Events Step by Step

Model Implementation (2)

The Entities

   
 

After finishing the model class we have to implement the dynamic model components of our model. Using the event-oriented modelling style, dynamic model components are represented as events that manipulate entities. We will start with implementing the entities as they are very simple.

We have identified two types of entities: the trucks and the van carriers. For each type of entity we will derive a class from desmoj.core.simulator.Entity (API). The truck entity doesn't have any attibutes (which is actually quite uncommon but due to the simplicity of our model), so the implementation is straightforward. We only have to define a constructor and pass all parameters over to the constructor of the superclass. Don't forget to import the desmoj.core.simulator package.

import desmoj.core.simulator.*;
/**
 * The Truck entity encapsulates all information associated with a truck.
 * Due to the fact that the only thing a truck wants in our model is a single
 * container, our truck has no special attributes.
 * All necessary statistical information are collected by the queue object.
 */
public class Truck extends Entity {
   /**
    * Constructor of the truck entity.
    *
    * @param owner the model this entity belongs to
    * @param name this truck's name
    * @param showInTrace flag to indicate if this entity shall produce output
    *                    for the trace
    */
   public Truck(Model owner, String name, boolean showInTrace) {
      super(owner, name, showInTrace);
   }
}

The van carrier entity is similarly straightforward to implement: Same as the truck, no attributes are required for the purpose of our simple model.

import desmoj.core.simulator.*;
/**
 * The VanCarrier entity encapsulates all data relevant for a van carrier.
 * In our model, it only stores a reference to the truck it is currently
 * (un)loading.
 */
public class VanCarrier extends Entity {

   /**
    * Constructor of the van carrier entity.
    *
    * @param owner the model this entity belongs to
    * @param name this VC's name
    * @param showInTrace flag to indicate if this entity shall produce output
    *                    for the trace
    */
   public VanCarrier(Model owner, String name, boolean showInTrace) {
      super(owner, name, showInTrace);
   }
}


   
  http://desmoj.sourceforge.net/tutorial/events/impl20.html