DESMO-J Distilled

Model Implementation (1)

   
 

Part 1: The Model Class

Every simulation model in DESMO-J will have to derive a subclass from desmoj.core.simulator.Model which sets up the model and connects it to an experiment (an instance of desmoj.core.simulator.Experiment) which in turn controls the simulation run. Thus you'll have to write a subclass of desmoj.core.simulator.Model. Since this abstract class is defining several abstract methods you have to provide an implementation to each of these:

  • in the init() method create and initialise your static model components like queues, distributions, and data collectors
  • in the doInitialSchedules() method create and activate the dynamic model components, i.e. provide them with a first entry on the event list; alternately, you may create the dynamic model components in the init() method together with the static components and only activate them in doInitialSchedules()
  • in the description() method give a short model description

You also have to implement a constructor. Here, you always call the constructor of desmoj.core.simulator.Model via super() first and then do any model-specific things, if necessary.

Always define model components as attributes (fields) of your model class. To provide you dynamic model components with access to commonly used static components like distributions or queues you may either implement additional methods or you may declare these attributes with the appropriate Java access control modifiers (e.g. don't use private on such attributes).

Last but not least implement a main() method to be able to run the model. Inside main(), create an instance of your model and an instance of desmoj.core.simulator.Experiment, and connect both. Then set experiment parameters like the stop time of the simulation or whether or not to display a progress bar during execution. Finally, you start the experiment and tell it to generate a report at the end.

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

package <my.package.name>;

import desmoj.core.dist.*;
import desmoj.core.simulator.*;
import desmoj.core.statistic.*;
import java.util.concurrent.TimeUnit;

public class <MyModel> extends Model {

   // define model components here

   /** constructs a model	 */
   public MyModel() {
      super(null, "<MyModelName>", true, true);
   }

   /** initialise static components */
   public void init() {
   }

   /** activate dynamic components */
   public void doInitialSchedules() {
   }

   /** returns a description of this model to be used in the report */
   public String description() {
      return "<Description of my model>";
   }

   // define any additional methods if necessary,
   // e.g. access methods to model components

   /** runs the model */
   public static void main(String[] args) {

      // create model and experiment
      MyModel model = new MyModel();
      Experiment exp = new Experiment("");
      // and connect them
      model.connectToExperiment(exp);

      // set experiment parameters
      exp.setShowProgressBar(true);
      TimeInstant stopTime = new TimeInstant(1440, TimeUnit.MINUTES);
      exp.tracePeriod(new TimeInstant(0), stopTime);
      exp.stop(stopTime);

      // start experiment
      exp.start();

      // generate report and shut everything off
      exp.report();
      exp.finish();
   }

} /* end of model class */


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