DESMO-J Distilled

Model Implementation (2)

   
 

Part 2: Classes for Dynamic Model Components

For each type of dynamic model component you will have to subclass one or more of DESMO-J’s abstract component classes. Depending on the modelling style you choose this means either defining subclasses of desmoj.core.simulator.SimProcess or of desmoj.core.simulator.Entity and desmoj.core.simulator.Event.

Process-interaction Approach (or Process-oriented Modelling Style)

Write a subclass of desmoj.core.simulator.SimProcess for each type of dynamic model component. This comprises implementing

  • the lifeCycle() method. This describes the component’s behaviour consisting of instantaneous state changes like setting internal attribute values, (de-)queueing entities or scheduling other processes for (re-)activation, and time-consuming activities. For these, the SimProcess class defines the methods hold() to model an activity of known duration and passivate() to model waiting for an indefinite duration.
  • a constructor. Here, you should always call the constructor of SimProcess via super() first before you initialise any attributes, if needed.

You may download the following process class template to aid you in building your own simulation process.

package <my.package.name>;

// import the DESMO-J stuff
import desmoj.core.simulator.*;

public class <MyComponentType> extends SimProcess {

   // define attributes here (optional)

   /** constructs a process... */
   public MyComponentType(MyModel model) {
      super (model, "<MyComponentTypeName>", true);
   }

   /** describes this process's life cycle */
   public void lifeCycle() {
   }

   // define additional methods here (optional)

} /* end of process class */

Event-scheduling Approach (or Event-oriented Modelling Style)

Write a subclass of desmoj.core.simulator.Entity for each type of dynamic model component. This comprises defining entity-specific attributes as class fields, implementing a constructor with a call to the constructor of Entity via super() as the first statement, and implementing additional methods if necessary.

The behaviour of these dynamic model components is specified in events. Write a subclass of one of the following classes (all derived from desmoj.core.simulator.AbstractEvent)

  • Event (an event that refers to one entity - e.g. a customer leaving the model)
  • EventOf2Entities (an event that refers to two entities - e.g. a server entity completing the request of a customer entity)
  • EventOf3Entities (an event that refers to three entities - e.g. a machine entity assembles two parts represented by two other entities)
  • ExternalEvent (an event that doesn't refer to a entity, but e.g. to the model as whole - e.g. arrival of new custome who is not yet represented by an entity)
for each type of event in your model. This comprises implementing

  • the eventRoutine(...) method, where the parameters include up to three Entities (depending on the relevant subclass of AbstraceEntity, see above). This method describes the given entities' behaviour consisting of instantaneous state changes like setting internal attribute values, (de-)queueing entities or scheduling new events. Note that the eventRoutine() method of ExternalEvents is parameterless as it does not take an entity as parameter.
  • a constructor. Here, you should always call the constructor of the relevant superclass via super() first before you initialise any attributes, if needed.

You may download the following entity class template and event class template (here, a subclass of Event, thus accepting one entity as parameter, serves as example) to aid you in building your own entities and events.

package <my.package.name>;

// import the DESMO-J stuff
import desmoj.core.simulator.*;

public class <MyEntityType> extends Entity {

   // define attributes here (optional)

   /** constructs an entity... */
   public MyEntityType(MyModel model) {
      super (model, "<MyEntityTypeName>", true );
   }

   // define additional methods here (optional)

} /* end of entity class */
package <my.package.name>;

public class <MyEventType> extends Event<MyEntity> {

   // define attributes here (optional)

   /** constructs an event... */
   public MyEventType(MyModel model) {
      super (model, "<MyEventTypeName>", true );
   }

   /** describes what happens during this event */
   public void eventRoutine(MyEntity who) {
   }

   // define additional methods here (optional)

} /* end of event class */


   
  http://desmoj.sourceforge.net/tutorial/distilled/3.html