Advanced Modelling FeaturesInterrupts
The Model Class |
||
In the description of the implementation, we will focus on how to use the interrupt feature in DESMO-J. Thus we will only regard the necessary additions to the source code of the ProcessesExample model. As the interrupt() method is already part of the desmoj.core.simulator.SimProcess class, we don't have to import any additional packages. What we do need in the model class, however, is a queue for the busy van carriers so that urgent trucks may get a reference to one of them for interruption. We also add a boolean distribution to determine if a new truck is urgent and the interrupt code to pass as a parameter to an interrupted van carrier. The following code snippet shows only the relevant parts of the model class. import desmoj.core.simulator.*; import desmoj.core.dist.*; /** * This is the model class. It is the main class of a process-oriented * model of the loading zone of a container terminal where urgent trucks * are always serviced first. */ public class InterruptsExample extends Model { /** Random number stream used to determine if a truck is urgent. */ private BoolDistBernoulli urgentStream; /** Queue for busy VCs. This is needed in order for an urgent truck to be * able to interrupt a VC if there is no idle VC available. */ protected ProcessQueue<VanCarrier> busyVCQueue; /** An interrupt code to tell the interrupted VC that an urgent truck * is awaiting service. */ protected InterruptCode urgentTruckArrived; // additional model attributes: other distributions and queues ... // constructor ... /** * initialises static model components like distributions and queues. */ public void init() { // initialise distributions urgentStream = new BoolDistBernoulli(this, "UrgentTruckStream", 0.1, true, false); // 10% of all trucks are considered urgent ... // initialise queues busyVCQueue = new ProcessQueue<VanCarrier>(this, "busy VC Queue", true, true); ... // initialise interrupt code urgentTruckArrived = new InterruptCode("Urgent Truck Arrived"); } /** Returns a sample of the random stream used to determine * if a truck is urgent. * @return boolean true if the truck is urgent; false otherwise */ public boolean getTruckIsUrgent() { return urgentStream.sample(); } // additional required methods ... } Nothing special here, as you can see. The real changes have to be made to the life cycles of the process classes. Let us start with the truck. |
||
http://desmoj.sourceforge.net/tutorial/advanced/interrupt2.html |