Advanced Modelling FeaturesCondQueue
The Truck Process |
||
Trucks are also modelled as simulation processes. The Truck class stores the ship it is assigned to as an attribute called myShip. Let's have a look at the lifeCycle() of this process: /** * Describes this truck's life cycle: * * On arrival, the truck enters the queue for waiting trucks to wait * until its assigned ship arrives at the terminal. * Then it directly leaves the system again since (un)loading is not * modelled. */ public void lifeCycle() throws SuspendExecution { // get a reference to the model CondQueueExample model = (CondQueueExample)getModel(); // arrive at the harbour // send additional information to trace sendTraceNote(" is assigned to " + myShip.getName()); // enter CondQ for waiting model.waitingTrucks.waitUntil(model.shipArrived); // now the ship has arrived --> leave system sendTraceNote("Truck for "+ myShip.getName() +" was serviced and leaves"); } On arrival at the terminal the truck sends a trace note to record which ship it is assigned to. It then enters the model's CondQueue named waitingTrucks via calling its waitUntil() method. Since each truck waits on the same condition -- that a particular ship has arrived at the port -- they all pass the same Condition object as a parameter to the condition queue. This Condition object is therefore stored as an attribute named shipArrived of the model class. Calling the waitUntil() method results in automatically passivating the truck process unless its condition already evaluates to true. The execution of the truck's life cycle is suspended and control passes back to the scheduler which can activate the next process on the event list. Only when the condition this truck is waiting on is finally met, its lifeCycle() method resumes execution with the statement following the call to waitUntil(). In our case, the process just sends another trace note and terminates. Let's now have a look at how the condition is expressed in DESMO-J. |
||
http://desmoj.sourceforge.net/tutorial/advanced/condqueue4.html |