Advanced Modelling FeaturesWaitQueue
The Ship Process |
||
Ships are also modelled as simulation processes. Let's have a look at the lifeCycle() of the Ship process: /** * Describes this ship's life cycle: * * On arrival, the ship requests two trainloads of coal (one after the other). * After loading is completed, it directly leaves the system again. */ public void lifeCycle() throws SuspendExecution { // get a reference to the model WaitQueueExample model = (WaitQueueExample )getModel(); // create and schedule successor new Ship(model).activate(new TimeSpan(model.shipArrivals.sample(), TimeUnit.MINUTES)); // arrive at the harbour // request two train loads of coal --> may cause delay for (int i = 0; i < 2; i++) { model.transferPoint.cooperate(model.coalTransfer); } // update statistics model.departures.update(); // leave system } On arrival at the harbour the truck requests one of the two train loads of coal it can carry. For this, it signals the model's WaitQueue named transferPoint that it wants to act as a master in the process cooperation of transferring coal from train to ship via calling its cooperate(ProcessCoop coop) method. If there are no trains waiting to be unloaded, this results in automatically enqueueing and passivating the ship process until a new train arrives. When there is a train available, the WaitQueue object automatically removes master and slave process from their respective queues and starts their cooperation by calling the cooperate() method of the ProcessCoop object the ship as the master has passed as a parameter. Let's now have a look at how the process cooperation is expressed in DESMO-J. |
||
http://desmoj.sourceforge.net/tutorial/advanced/waitqueue4.html |