Processes Step by StepModel Implementation (1)
Defining Static Model Components |
||
Obviously we will at least need the following four items:
Note: Two quick notes have to be made here. Firstly, we don't bother about reality levels within this tutorial. That means, we will not assume that our models approximate reality in any way more than to fit our imagination. So we will not bother about validating our models, although we don't forget that this is necessary when you model real systems. Our main goal is to teach the use of DESMO-J, not to teach simulation knowledge. Secondly, we are free in choosing a time unit for our simulation model. DESMO-J makes no assumption about the time scale to use within its internal event list. It is up to the programmer to keep all simulation times in a proper scale. This becomes extremely important when you start to implement component models, because they possibly use different time scales. For our van carrier model we will use minutes as the time unit. Let us now start to turn these results into DESMO-J code. Firstly, we define fields in our model class for the four objects. Note that the streams carry the qualifier private in order to encapsulate them as much as possible from their environment, while the queues carry the qualifier protected, because we must access them extensively during our simulation. We do not yet instantiate objects for these fields. We will do this later in the init() method and an explanation for this approach will follow there. Secondly, we will define the number of van carriers operating the loading zone as a model parameter. Thus it is easy to change its value for different experiments. public class ProcessesExample extends Model { /** * Model parameter: the number of van carriers */ protected static int NUM_VC = 1; /** * Random number stream used to draw an arrival time for the next truck. * See init() method for stream parameters. */ private desmoj.core.dist.ContDistExponential truckArrivalTime; /** * Random number stream used to draw a service time for a truck. * Describes the time needed by the VC to fetch and load the container * onto the truck. * See init() method for stream parameters. */ private desmoj.core.dist.ContDistUniform serviceTime; /** * A waiting queue object is used to represent the parking area for * the trucks. * Every time a truck arrives it is inserted into this queue (it parks) * and will be removed by the VC for service. * * This way all necessary basic statistics are monitored by the queue. */ protected desmoj.core.simulator.ProcessQueue<Truck> truckQueue; /** * A waiting queue object is used to represent the parking spot for * the VC. * If there is no truck waiting for service the VC will return here * and wait for the next truck to come. * * This way all idle time statistics of the VC are monitored by the queue. */ protected desmoj.core.simulator.ProcessQueue<VanCarrier> idleVCQueue; ... } Due to the fact that the streams we just have created are private members of the model class, it is necessary to make them accessible through getter-methods. We will therefore implement two getter-methods within the model class to access the random distributions serviceTime and truckArrivalTime. This is safer than giving them the "protected" status and it is feasible because we will only need to access one method (sample()) of these objects, not several. The sample() method is implemented in every distribution of desmoj.core.dist. It returns a sample out of a random stream defined and distributed by the object this method is called on. (see API documentation) /** * Returns a sample of the random stream used to determine the * time needed to fetch the container for a truck from the * storage area and the time the VC needs to load it onto the truck. * * @return double a serviceTime sample */ public double getServiceTime() { return serviceTime.sample(); } /** * Returns a sample of the random stream used to determine * the next truck arrival time. * * @return double a truckArrivalTime sample */ public double getTruckArrivalTime() { return truckArrivalTime.sample(); } |
||
http://desmoj.sourceforge.net/tutorial/processes/impl1.html |