CHAPTER 4

OVERVIEW OF JSIM

4.1 The variate Package

The variate package provides a wide variety of random variates. The Variate class is extended by all other variates. The Variate class uses JSIM's own Linear Congruential Generator called LCGRandom, but this can be changed very easily to use Java's Random class by modifying the code of the Variate class. It is also a simple matter to install yet another random generator. The LCGRandom number generator has a very long period and has been statistically proven to provide good inter-sample independence. The gen method returns the next random number. For the derived classes, the random number returned depends on the type of distribution used.

JSIM has implementations of fourteen continuous random variate generators and eight discrete random variate generators. The discrete random variates available in JSIM's variate package are Bernoulli, Binomial, DiscreteProb, Geometric, HyperGeometric, NegativeBinomial, Poisson, and Randi. The continuous random variates available are Beta, Cauchy, ChiSquare, Erlang, Exponential, F_Distribution, Gamma, HyperExponential, LogNormal, Normal, StudentT, Triangular, Uniform, and Weibull. The algorithms for these random variate generators may be found in [Law and Kelton, 1982, Pritsker, 1986]. The variate

package also contains two classes used to test the random number generators, namely LCG_ Test and KS_Test.

4.2 The queue Package

The queue package is rooted by the Queue class which is defined as an abstract base class, from which FIFO_Queue (First-In, First-Out), LIFO_Queue (Last-In, First-Out), PriorityQueue and TemporalQueue are derived. Splay trees are used to implement priority and temporal queues, and simple lists are used to implement the FIFO and LIFO queues. Each of these queues has, by default, infinite capacity. However, users have the freedom to set the capacity when constructing a queue object.

Priority and temporal queues may be used for lines ordered by priority as well as to implement Future Event Lists and time advance mechanisms. The incoming process (or event for event scheduling) is inserted into the Future Event List (FEL) based on the process activation time (ties are broken by priority), and then the process at the front of the FEL is invoked. The clock is updated to the time of the next process. The FEL is implemented as a temporal queue.

4.3 The statistics Package

The statistic package contains classes to collect statistical information. The Statistic class is an abstract base class and contains methods to analyze statistical data and aid in outputting simulation results. Format is used for formatted output and has methods similar to the printf function in the C language. It was developed by Cay Horstmann for the Core Java (Book/CD-ROM) published by SunSoft Press/Prentice Hall.

The SampleStat and TimeStat classes extend the base Statistic class. SampleStat is used for collecting sample statistical data (via its tally method), while the TimeStat class is used to gather time-persistent statistics (via its accumulate method). The Statistic class has the ability to calculate minimums, maximums, means, variances, standard deviations, root mean squares and confidence interval half widths. The package also contains a BatchStat class that is derived from SampleStat. BatchStat is used to collect batch statistics. The batch size is a parameter to the constructor of BatchStat. Finally, histograms can be produced using the Histogram class.

4.4 The process Package

The process package provides classes that are used to create simulation models following the process-interaction paradigm. A simulation model may be encapsulated as a Java bean. Such bean objects contain several DynamicNodes. Currently, Server, Facility, Signal, Source and Sink are provided as types of DynamicNodes. These nodes are connected with edges which Transport entities SimObjects between the nodes. A Model object is used to control the simulation by starting all of the Sources as well as stopping the simulation. If animation is to be performed, the model creates a ModelCanvas object on which it displays the animation.

4.4.1 SimObject Class

A simulation model based on the process-interaction paradigm needs to define the entities and their life cycle within the simulation model. An instance of the SimObject class represents a single simulation entity or process. The simulation model builder should extend SimObject to create a useful simulation entity. Precisely, the simulation model builder needs to specify the functioning or life cycle of the simulation entity as is required by the model. SimObject extends the Thread class provided by Java. Hence, every entity in a JSIM process-interaction model is a separate thread. A SimObject's logic (behavior during its lifetime) is defined by the model builder and by coding its run method.

4.4.2 DynamicNode Class

DynamicNode is an abstract class that encapsulates the features common to the classes that appear as nodes in a JSIM model, currently, Server, Facility, Signal, Source and Sink. Every such node collects two different types of statistics, namely duration/time data and occupancy/usage data. Suitable labels are created using the node's name for display purposes.

4.4.3 Server Class

A Server acts as a service provider. It initially creates a certain number of service units as defined by the model builder, thus providing servers to SimObjects requesting service. A SimObject obtains service by requesting a server and then using the server. If all the service units are busy, the client entity will be lost. Service may be preempted by invoking the preempt method. Each server also maintains statistics regarding the usage of its service units and its clients' service times.

4.4.4 Facility Class

A Facility is derived from Server since it is most similar to this class. It encapsulates a Queue as a private data member. Simulation entities (SimObjects) obtain service by requesting a facility using the request method. If the facility is not busy, the simulation entity acquires a server and uses it. However, if the facility is busy, the simulation entity is enqueued in the facility's Queue. When the simulation entity finishes its work, it releases the server. The queueLength method returns the length of the queue within the facility.

4.4.5 Signal Class

A Signal affects the behavior of servers, by alternatively, increasing or decreasing the number of service units. For example, a Signal may be used as a traffic light in a simulation of an intersection of streets. When the signal turns on/green, servers/facilities (representing traffic lanes) in its control list will have a service unit added (using the Server expand method) so that traffic can flow. Conversely, when the signal turns off/red, a service unit will be removed (using the Server contract method) to stop the traffic flow.

4.4.6 Source Class

A Source is a generator or creator of SimObjects. It creates SimObjects depending on defined parameters such as inter-arrival time or the number of entities to create. In the JSIM library, Source has been designed as an abstract class. This is because different simulation models will require different types of entities to be created. Hence, the model builder is required to extend Source to create a specialized entity generator. This is a very simple process and involves only the implementation of the abstract makeEntity method. This is because the decision as to which entities need to be created has to be made by the simulation model builder. The simulation model builder must extend Source and implement the abstract method makeEntity to return whatever entity is required. The run method implements the lifetime of the Source class. It has been implemented to create an entity periodically according to the inter-arrival time distribution.

4.4.7 Sink Class

A Sink is, conceptually, the opposite of a Source in that a sink phases out or destroys SimObjects created by a source. SimObjects go to a sink when they complete their lifetimes. SimObjects are eliminated at sinks using the capture method.

4.4.8 Transport Class

Objects from the Transport class form the edges of the simulation model graph, with each connecting two nodes. Simulation entities or SimObjects travel along transports while moving from one node to another. A transport has a default constant speed that may be changed using the adjustSpeed method. After joining a transport, an entity moves along the transport using the move method. The move method returns false when the end of the transport is reached. Transports have been implemented as quad curves, so that the model builder can flexibly specify the edge connecting two nodes. Quad curves are part of the Java 2D API and specify a curve as a quadratic function of x and y coordinates.

4.4.9 Model Class

The Model class is derived from (extends) Frame, allowing multiple models to be run simultaneously, each in a separate window frame. It also implements the Runnable interface and its run method starts off all Source objects. Then until the simulation is over, it periodically wakes up to repaint the animation canvas. When the simulation is over, it displays statistical summary results.

 

 

4.5 The jmodel Package

JSIM provides a visual model designer implemented using the Java swing package. It is a GUI-based model builder that supplies simulationists with more direct intuitive means to build a model. It allows users to position a simulation object on a model-builder canvas by selecting a button from the tool-bar and then clicking on a location on the canvas to place the object (e.g., Server node). Although JSIM is designed to allow models to be rapidly hand coded utilizing JSIM's extensive class library, the easiest way to create a model is to use JSIM's visual designer, JMODEL. JMODEL provides several buttons to control the construction of a model on a canvas. The control buttons currently provided are shown in table 1.

Server

Provides service to entities arriving at the node

Facility

Inherits from Server and adds a queue to hold waiting entities

Signal

Alters the number of service units in a server(s)

Source

Produces entities and records statistics about them

Sink

Consumes entities and records statistics about them

Transport

Connects two nodes (from, to) together

Move

Relocates nodes to new positions in the canvas (edges follow)

Delete

Deletes nodes or edges by clicking on them

Update

Views/changes the properties of selected nodes

Generate

Emits Java code implementing the designed model

Table 1: Jmodel’s Control Button

Models are built visually by clicking on a button to set the designer mode. Then, when the mouse is clicked, an action will be performed at its location in the drawing canvas. For example, if in "Facility" mode, a new facility will be drawn at the location. To connect two nodes with a transport, enter "Transport" mode and then click on the two nodes. This will cause a straight line to be drawn. To produce a curve, click on a point outside the nodes to serve as a control point.