haifa.shopsim.kernel
Class ShopRun

java.lang.Object
  |
  +--javaSimulation.Linkage
        |
        +--javaSimulation.Link
              |
              +--javaSimulation.Process
                    |
                    +--haifa.shopsim.kernel.ShopRun
All Implemented Interfaces:
java.lang.Runnable

public class ShopRun
extends javaSimulation.Process
implements java.lang.Runnable

This class is the Process in the simulation that starts it all (the main process). It has references to the shopAlgorithm, the ShopData, the log, the shopResults, it also refences all of the entities of the simulation, the machines, the jobs, the route starts and ends.

This class is a singleton because the javaSimualtion package uses static variables for time and such, so no two shop runs can be run in the same process.


Field Summary
private static int count
          Use to ensure that at most one instance of this class exists at any time.
private  Job[] jobs
          An array of all of the jobs in the shop.
private  java.io.PrintWriter log
          For misc output information.
private  boolean lowPriority
           
private  Machine[] machines
          An array of all of the machines in the shop.
(package private)  long MAX_SIM_TIME
          A simualation may not run past this time.
private  PostRunAction postRunAction
           
(package private)  java.util.HashMap restingMachines
           
private  RouteEnd[] routeEnds
          An array of all of the route ends.
private  RouteStart[] routeStarts
          An array of all of the route starts.
private  java.lang.Thread run
          The Thread that this class runs on.
private  ShopAlgorithm shopAlgorithm
          A refrence to the algorithm that is asked what to do at each time epoch.
(package private)  java.util.ArrayList shopChangeListeners
           
private  ShopData shopData
          A reference to the shopData.
private  ShopState shopState
          A reference to the ShopState object.
(package private)  int unfinishedJobs
           
 
Fields inherited from class javaSimulation.Process
after, after_code, at, at_code, before, before_code, delay, delay_code, direct_code, EVTIME, MAIN, myCoroutine, PRED, prior, SQS, SUC, TERMINATED
 
Constructor Summary
ShopRun(ShopAlgorithm shopAlgorithm_, ShopData shopData_, ShopState shopState_, PostRunAction postRunAction_, java.io.PrintWriter log_, boolean lowPriority_)
          Sets up the shop.
 
Method Summary
 void actions()
          This method is the main corotine of the simulation (it exists for as long as the simulation exists).
 void addShopChangeListener(ShopChangeListener scl)
           
(package private)  void awakenRestingMachines()
           
(package private)  java.util.Map getQMap()
           
private  void logPrint(java.lang.String msg)
          Writes message to log, including time
private  java.util.Vector machinesWithSameTime(int mN)
          Returns a vector of Integers of all of the machines that have the same time as the machine numbered mN.
(package private)  void notifyListeners(ShopChangeEvent sce)
           
(package private)  boolean quitCalled()
          Returns true if quit has been called on the algorithm.
 void reset()
           
 void run()
          The running thread of the simulation activates the main class.
 void start()
           
(package private)  ShopCommand whatNow(int machineNumber)
          Used by the Machine objects in the simulation.
 
Methods inherited from class javaSimulation.Process
, activat, activate, activate, activate, activate, activate, activate, activate, cancel, cancel, current, error, evTime, hold, idle, main, nextEv, passivate, reactivate, reactivate, reactivate, reactivate, reactivate, reactivate, reactivate, scheduleAfter, terminated, time, wait
 
Methods inherited from class javaSimulation.Link
follow, into, out, precede
 
Methods inherited from class javaSimulation.Linkage
pred, prev, suc
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

count

private static int count
Use to ensure that at most one instance of this class exists at any time.

run

private java.lang.Thread run
The Thread that this class runs on. It may be given low or high priority in the consturctor.

MAX_SIM_TIME

final long MAX_SIM_TIME
A simualation may not run past this time.

shopAlgorithm

private ShopAlgorithm shopAlgorithm
A refrence to the algorithm that is asked what to do at each time epoch.

shopData

private ShopData shopData
A reference to the shopData. It is used to inquire about the job shop problem at hand.

log

private java.io.PrintWriter log
For misc output information.

shopState

private ShopState shopState
A reference to the ShopState object. It is updated before asking the algorithm for new commands.

postRunAction

private PostRunAction postRunAction

lowPriority

private boolean lowPriority

machines

private Machine[] machines
An array of all of the machines in the shop.

jobs

private Job[] jobs
An array of all of the jobs in the shop. These travel around as the simulation evolves in time.

routeStarts

private RouteStart[] routeStarts
An array of all of the route starts.

routeEnds

private RouteEnd[] routeEnds
An array of all of the route ends.

shopChangeListeners

java.util.ArrayList shopChangeListeners

unfinishedJobs

int unfinishedJobs

restingMachines

java.util.HashMap restingMachines
Constructor Detail

ShopRun

public ShopRun(ShopAlgorithm shopAlgorithm_,
               ShopData shopData_,
               ShopState shopState_,
               PostRunAction postRunAction_,
               java.io.PrintWriter log_,
               boolean lowPriority_)
Sets up the shop. Bind all of the machines in the shop to their predecessors and successors.
Method Detail

awakenRestingMachines

void awakenRestingMachines()

addShopChangeListener

public void addShopChangeListener(ShopChangeListener scl)

notifyListeners

void notifyListeners(ShopChangeEvent sce)

getQMap

java.util.Map getQMap()

whatNow

ShopCommand whatNow(int machineNumber)
Used by the Machine objects in the simulation. This method is responsible for updating the state of the ShopState object and for inquring the algorithm what now.

machinesWithSameTime

private java.util.Vector machinesWithSameTime(int mN)
Returns a vector of Integers of all of the machines that have the same time as the machine numbered mN. This vector will always have atleast one element: mN

quitCalled

boolean quitCalled()
Returns true if quit has been called on the algorithm.

reset

public void reset()

start

public void start()

run

public void run()
The running thread of the simulation activates the main class.
Specified by:
run in interface java.lang.Runnable

logPrint

private void logPrint(java.lang.String msg)
Writes message to log, including time

actions

public void actions()
This method is the main corotine of the simulation (it exists for as long as the simulation exists). It starts off by activating all of the machines (which are the main "working" entities in the system). It Then holds for the MAX_SIM_TIME which is an upper bound on the simulation run. In normal circumstances it should be rare for the method to regain controll at MAX_SIM_TIME when the other machines are still working.

When the method finally regains controll, it cleans up and returns, thus the simulation is over.

Overrides:
actions in class javaSimulation.Process