Advanced Modelling Features

Bin

The Train Process

   
 

The train process in our example is associated to one of the four Bin objects we created in the model class. Each train has a certain length, i.e. can carry a certain number of containers. On arrival at the the railway station of the container terminal the train requests the number of containers from the storage area (bin) of its destination. This may result in the train having to wait until enough containers are available. When the train is loaded, it leaves the system and is replaced by the next train half an hour later.

Let's have a look at the lifeCycle() method again:

/**
 * Describes this train's life cycle:
 *
 * On arrival at the the railway station of the container terminal
 * the train requests the number of containers from the storage area (Bin) of
 * its destination. This may result in the train having to wait until enough
 * containers are available.
 * When the train is loaded, it leaves the system, freeing the track
 * for the next train.
 */
public void lifeCycle() throws SuspendExecution {

   // send some information to the tracefile for documentation reasons
   sendTraceNote("Train length:  " + length + " containers");

   // load containers from storage
   // --> the process may be passivated and placed on an internal queue
   // by the bin if there are not enough containers available
   storage.retrieve(this.length);

   // train is loaded and can leave the system

   // create successor train
   Train nextTrain = new Train(myModel, "Train to "+storage.getName(), true, storage);
   // and schedule it for arrival in half an minute
   nextTrain.activate(new TimeSpan(0.5, TimeUnit.MINUTES));

}

We start with sending some information to the trace output when the ship arrives. Thus we'll see in the trace report how many containers the train will need to load. Using the retrieve() method the train then tries to obtain a number of containers corresponding to its length. This may result in the train process to be automatically passivated by the Bin object, if there are not enough containers available. The train process may be inserted into the internal waiting queue of the Bin object then. Otherwise it receives its containers immediately and proceeds. Before leaving the system, a train process creates and activates its successor.

Let us now take a look at the trace output of this example to see how the simulation processes interact via the Bin constructs.



   
  http://desmoj.sourceforge.net/tutorial/advanced/bin4.html