CHAPTER 5
MODEL BEANS
In JSIM Web-based, component-based, and agent-based simulation environment, every model must be encapsulated as JavaBeans. Therefore, the model bean can be assembled with model agent, database bean, scenario agent, or other model beans to form an application. For every model bean, it not only is an abstraction of a real life situation but also has all the features a JavaBean possesses.
5.1 Design Issue of Model Bean
To cope with the two aspects related to every model bean, a special object oriented design is necessary. Every model bean in JSIM is derived from a super class called ModelBean. The ModelBean class takes care of the bean aspects of each model bean, and the derived child class is responsible for all the features, related to real life situation the model tries to represent (for example, ERoom model represents an Emergency room simulation). By this design, the following advantages are obvious:
All the new bean features can be added only into ModelBean, every model bean will automatically have these features. This is a very good example to show the great strength of object oriented programming style. As far as code generation’s concern, currently the jmodel package can provide a visual design tool to generate code of a model. The model created this way is just an applet. But as shown in the appendices B and C, there is no big difference between code generated by jmodel package and child class of ModelBean. It is possible to modify the jmodel package so that it can generate model bean code as well. If this step succeeds, the building of simulation application becomes an entirely visual process. The simulationist, who may not know low level programming in Java, can create an application without writing a line of Java code.
5.2 Model Bean’s Features
All the JavaBean features are resolved in ModelBean. The ModelBean can fire the following events:
An alternative of a general JSIM event may be developed to replace all these events.
A simulationist must be given the chance to modify the major simulation parameters, like inter-arrival distribution, service distribution, number of customer, number of service center, data monitoring spot, etc. It is the AdvertiserEvent that exposes these properties to, for example, a ScenarioAgent.
The model bean will fire a BatchEvent if the amount of data required by the model agent has been collected. The data is a collection of batch mean values. Each value is the mean of a particular batch. A model agent specifies the batch size and number of batches to be collected.
The EntityEvent is used to produce the interaction among the model beans. In simulation, one event in one model may have some kind effect on another model. When an entity is caught by a Sink, there is a possibility that the model bean might fire an EntityEvent to broadcast this event. The registered model beans, which are interested in this event, will act according to the semantics of the simulation.
When simulation is over, the Model class collects all the statistical results from all the data collectable locations of the model bean. The StatReportEvent can send out these results to any registered beans which want them.
ModelBean
can listen to following events:The ModelActionEvent is triggered by model agent. It contains the data from model agent to guide the model bean to collect simulation output data, including the number of batches to be collected and the batch size. In case of the replication model agent, the number of batch is always one, and the size of the batch is equal to replication size. The other data, used mainly for control of simulation process, indicates the type of model agent involved, and flow-control of the simulation. ModelBean also has methods for registration of listeners of the events it can trigger.
The ModelBean class is an abstract class. It contains three abstract methods which must be implemented by the child class. Here are these methods:
/**
* The method to initialize a simulation model
*/
public abstract void initModel (boolean batched );
/**
* The method to set the model's properties
*/
public abstract void setModelProperties(Hashtable data);
/**
* The method to collect the model's properties
*/
public abstract void getModelProperties( );
The initModel method initializes the model with different types of DynamicNodes and Transports linking the nodes. The content of this method is almost the same as the code generated by jmodel package. To advertise a model’s properties, a dedicated method, getModelProperties, is used to gather properties of a model and an Advertiser instance is initialized to store these properties. SetModelProperties method is called when SceanrioAgent fires the ScenarioEvent. This method sets model properties modified by the user. These three methods totally depend on the real life situation the model represents. Therefore, every child of ModelBean must implement them.