Advanced Modelling FeaturesCondQueue
The Model Class |
||
In the description of the implementation, we will focus on the CondQueue construct and its use. As usual, we derive our own model class from desmoj.core.simulator.Model, define the necessary attributes (in this case: distributions, a CondQueue object, a Condition object to use with the condition queue and references to the terminal office, the currently docked ship and the list of incoming ships), and implement a constructor and the required methods description(), init() and doInitialSchedules() as well as a main() method. To be able to use the CondQueue construct we will have to import the desmoj.core.advancedModellingFeatures package. The following code snippet shows only the parts of the model class relevant to the CondQueue object: import desmoj.core.simulator.*; import desmoj.core.dist.*; import desmoj.core.advancedModellingFeatures.*; /** * This is the model class. It is the main class of a simple process-oriented * model of a container terminal using a condition queue to synchronise incoming * ships and trucks. */ public class CondQueueExample extends Model { /** A CondQueue for trucks waiting on a particular ship */ protected CondQueue<Truck> waitingTrucks; /** The condition for the trucks to check if their ship has arrived */ protected ShipArrivedCondition shipArrived; /** A reference to the ship that's currently in the harbour */ protected Ship currentShipInPort = null; /** A list to keep track of the awaited ships (so that trucks can be assigned to them) */ protected Vector<Ship> incomingShips = new Vector<Ship>(); /** A reference to the terminal office */ protected TerminalOffice terminalOffice; // additional model attributes: distributions ... // constructor ... /** * initialises static model components like distributions and queues. */ public void init() { // initialise distributions ... // initialise condition queue waitingTrucks = new CondQueue<Truck>(this, "Waiting Trucks", true, true); // have queue check all entities when notified, not just the first one waitingTrucks.setCheckAll(true); // initialise condition the trucks are waiting on shipArrived = new ShipArrivedCondition(this, "Your Ship Arrived!", true); } // additional required methods ... } The first statement shown in the init() method initialises the CondQueue. The subsequent call to the setCheckAll() method is necessary to ensure that the queue will check all processes waiting for arrival of ships, not just the first one. The condition itself is instantiated by the last statement. As conditions are specific to models, a model designer has to implement their own condition classes. In this case, we derive a subclass named ShipArrivedCondition from DESMO-J's abstract Condition class. But first we will take a look at the two dynamic model components that use the condition queue. Let us start with the ship. |
||
http://desmoj.sourceforge.net/tutorial/advanced/condqueue2.html |