Processes Step by Step

Model Implementation (1)

The doInitialSchedules() Method

   
 

The third and last of the inherited methods from desmoj.core.simulator.Model is called doInitalSchedules(). Its purpose is to place all events and process activations, respectively, on the event list of the scheduler which are needed to keep the simulation alive. As soon as there are no more events on the event list, the simulation run will stop.

We will need to activate the van carrier(s) for simulation time 0.0, because they are permanent entities and are active from the very first second of our simulation run.

Furthermore we need to activate the truck generator, because it has to create the first (and all the following) trucks and let them arrive in our system.

   /**
    * Activates dynamic model components (simulation processes).
    *
    * This method is used to place all events or processes on the
    * internal event list of the simulator which are necessary to start
    * the simulation.
    *
    * In this case, the truck generator and the van carrier(s) have to be
    * created and activated.
    */
public void doInitialSchedules() {

   // create and activate the van carrier(s)
   for (int i=0; i < NUM_VC; i++)
   {
      VanCarrier vanCarrier = new VanCarrier(this, "Van Carrier", true);
      vanCarrier.activate();
         // Use TimeSpan to activate a process after a span of time relative to actual simulation time,
         // or use TimeInstant to activate the process at an absolute point in time.
   }

   // create and activate the truck generator process
   TruckGenerator generator = new TruckGenerator(this,"TruckArrival",false);
   generator.activate();
}

Note that you have to supply each model component in DESMO-J with a name. In the above method we do this by naming the truck generator process "TruckArrival" and the van carrier process(es) "Van Carrier". You might worry about how we will be able to differentiate between several van carriers all named "Van Carrier" if there is more than one. The answer to this is, that DESMO-J automatically creates a unique name for each object by combining the given name (e.g. "Van Carrier") with a unique number generated by the framework. Thus DESMO-J will name the objects instantiated from the VC class "Van Carrier#1", "Van Carrier#2", "Van Carrier#3" and so on.



   
  http://desmoj.sourceforge.net/tutorial/processes/impl3.html