Processes Step by Step

Model Implementation (1)

Deriving the Model Class

   
 

To implement our conceptual model with DESMO-J we need a model class and simulation process classes for each entity type. The model class has to be derived from the abstract desmoj.core.simulator.Model class.

Open your editor or IDE and create a class called ProcessesExample which is derived from desmoj.core.simulator.Model. Don't forget to import the relevant DESMO-J packages:

  • desmoj.core.simulator for all basic modelling classes like Model, SimProcess and ProcessQueue.
  • desmoj.core.dist for stochastic distributions (random number streams).

Then define a constructor that simply hands its parameter values over to its superclass.

import desmoj.core.simulator.*;
import desmoj.core.dist.*;

/**
 * This is the model class. It is the main class of a simple process-oriented
 * model of the loading zone of a container terminal. Trucks arrive at the
 * terminal to load containers. They wait in line until a van carrier (VC) is
 * available to fetch a certain container and load it onto the truck. After
 * loading is completed, the truck leaves the terminal while the van carrier
 * serves the next truck.
 */
public class ProcessesExample extends Model {

   ...

   /**
    * ProcessesExample constructor.
    *
    * Creates a new ProcessesExample model via calling
    * the constructor of the superclass.
    *
    * @param owner the model this model is part of (set to null when there is 
    *              no such model)
    * @param modelName this model's name
    * @param showInReport flag to indicate if this model shall produce output 
    *                     to the report file
    * @param showInTrace flag to indicate if this model shall produce output 
    *                    to the trace file
    */
   public ProcessesExample(Model owner, String modelName, boolean showInReport, 
                                           boolean showInTrace) {
      super(owner, modelName, showInReport, showInTrace);
   }

   ...

} /* end of model class */

As you look at the DESMO-J API (Application Programmers Interface) for the desmoj.core.simulator.Model class, you will find that this class has three methods which carry the qualifier abstract. Therefore you are forced to implement these three methods:

  1. description()
  2. doInitialSchedules()
  3. init()

Read the code comments below to see what these methods are intended for. If you are using an IDE, it probably already has added these three methods to your code. If you don't use an IDE, please add the code below to your model class. We will start with implementing the description() method because it is the easiest one to do. This method returns a string describing what this model is all about. It will be included in the automatically generated report file.

   /**
    * Returns a description of the model to be used in the report.
    * @return model description as a string
    */
   public String description() {
      return "This model describes a queueing system located at a "+
                  "container terminal. Trucks will arrive and "+
                  "require the loading of a container. A van carrier (VC) is "+
                  "on duty and will head off to find the required container "+
                  "in the storage. It will then load the container onto the "+
                  "truck. Afterwards, the truck leaves the terminal. "+
                  "In case the VC is busy, the truck waits "+
                  "for its turn on the parking-lot. "+
                  "If the VC is idle, it waits on its own parking spot for the "+
                  "truck to come.";
   }
   /**
    * 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() { ... }
   /**
    * Initialises static model components like distributions and queues.
    */
   public void init() { ... }

  Before we continue with implementing the other two methods take some time to think about the static model components we will need for our model. Static model components comprise distributions, queues and statistical data collectors. We will skip the data collectors in this simple model, but we will definitely use distributions and queues. Can you work out what kind of each we need?



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