Object Oriented Discrete-Event Simulation CS4730 Fall 2010 Jose M. Garrido Department of Computer Science and Information Systems Kennesaw State University
Technical Attractions of Simulation * Ability to compress time, expand time Ability to control sources of variation Avoids errors in measurement Ability to stop and review Ability to restore system state Facilitates replication Modeler can control level of detail *Discrete-Event Simulation: Modeling, Programming, and Analysis by G. Fishman, 2001, pp (C) J. M. Garrido, 2009
Introduction What is discrete-event simulation? Modeling, simulating, and analyzing systems Computational and mathematical techniques Model: construct a conceptual framework that describes a system Simulate: perform experiments using computer implementation of the model Analyze: draw conclusions from output that assist in decision making process We will first focus on the model 3(C) J. M. Garrido, 2009
Characterizing a Model Deterministic or Stochastic Does the model contain stochastic components? Randomness is easy to add to a DES Static or Dynamic Is time a significant variable? Continuous or Discrete Does the system state evolve continuously or only at discrete points in time? Continuous: classical mechanics Discrete: queuing, inventory, machine shop models 4(C) J. M. Garrido, 2009
Definitions Discrete-Event Simulation Model Stochastic: some state variables are random Dynamic: time evolution is important Discrete-Event: significant changes occur at discrete time instances Monte Carlo Simulation Model Stochastic Static: time evolution is not important 5(C) J. M. Garrido, 2009
Programming Languages General-purpose programming languages Flexible and familiar Well suited for learning DES principles and techniques E.g.: C, C++, Java, Eiffel, Fortran, Ada Special-purpose simulation languages Most commercial simulation products are IDEs and not programming languages Good for building models quickly Provide built-in features (e.g., queue structures) Most provide graphics and animation E.g.: Arena, Flexim, Promodel, others 6(C) J. M. Garrido, 2009
Terminology Model vs. Simulation (noun) Model can be used WRT conceptual, specification, or computational levels Simulation is rarely used to describe the conceptual or specification model Simulation is frequently used to refer to the computational model (program) Model vs. Simulate (verb) To model can refer to development at any of the levels To simulate refers to computational activity Meaning should be obvious from the context 7(C) J. M. Garrido, 2009
Observations Make each model as simple as possible Never simpler Do not ignore relevant characteristics Do not include extraneous characteristics Model development is not sequential Steps are often iterated In a team setting, some steps will be in parallel Do not merge verification and validation Develop models at three levels Do not jump immediately to computational level Think a little, program a lot (and poorly); Think a lot, program a little (and well) 8(C) J. M. Garrido, 2009
Final Goal Discrete Event Simulation can provide valuable insight about the system 9(C) J. M. Garrido, 2009
Using Simulation Begin by studying trace-driven single server queue Follow that with a trace-driven machine shop model 10(C) J. M. Garrido, 2009
Approaches to Discrete-Event Simulation l Event approach l Activity approach l Process interaction approach Object oriented Psim3, and PsimJ2 use the full power of process interaction simulation. Other simulation packages and languages have limited OO support 11(C) J. M. Garrido, 2009
The Process Interaction Approach A simulation model using this approach consists of: A definition of the active and passive entities in the model. A description of how different active entities are going to interact among themselves, as time passes. A simulation run consists of creating and starting the passive and active objects. 12(C) J. M. Garrido, 2009
Advantages of the Process Style of Simulation Compatible with the Object-Oriented approach to modeling and programming, every process is an active object. Suitable for modeling large and complex systems. Threads are used to implement the active objects in the simulation models. 13(C) J. M. Garrido, 2009
Process Interaction Approach to Simulation with PsimJ2 A portable library package of Java classes Object-oriented Supports the process interaction approach A good tool for courses, such as: Object-oriented Simulation Object-oriented design and programming Operating systems Introduction to real-time systems 14(C) J. M. Garrido, 2009
Applying the Process Interaction Approach to Simulation The major components in a model are entities, these are modeled as active objects The active entities have a life of their own, and are called processes The passive entities are resources and queues The UML Collaboration diagram shows the process interactions 15(C) J. M. Garrido, 2009
Developing Simulation Models of Real-Time Systems The simulation models are more complex because they need to satisfy the requirements of real-time systems. A set of tasks are identified in developing such systems. Identifying these tasks will simplify the analysis and design phases of building a simulation model of real-time systems. 16(C) J. M. Garrido, 2009
Developing Models of RTS Concurrency – Multiple simultaneous activities. Synchronous Communication – Two or more communicate, where the sender will wait until the receiver gets the message. Timing Constraints – Describe the time windows during which activities must occur or respond. Communications Deadlines – Timers are used to place deadlines on how long a process can wait to communicate with another process. 17(C) J. M. Garrido, 2009
Train-Gate System Example Train-Gate System consists of a one- directional railway track crossing a road. The gate at the crossing must be lowered or raised by a Controller system. Sensors are used to detect entering trains and leaving trains. The signals from the sensors are sent to a Monitor, which keeps track of the number of trains in the area. 18(C) J. M. Garrido, 2009
Case Study: Train-Gate System Train Entry Sensor Train Exit Sensor Monitor ControllerGate Open Close Open/Close Signals Gate Opened / Closed Discrete Interarrival Times of Trains This simulation model is available at: 19(C) J. M. Garrido, 2009
Train-Gate System The real-time behavior of the Train-Gate System is modeled using Communicating Real-Time State Machines (CRSM). The timing constraints in CRSM are specified in the transitions between states, as shown in the diagram. The system design includes the common set of tasks identified in previous slides. Simulation of the Train-Gate system has been implemented using PsimJ2, a Java based discrete-event simulation package. The implementation of the system defines the processes: Controller, Gate, Train, Monitor, and Sensors. 20(C) J. M. Garrido, 2009
(C) J Garrido21 Processes Processes are implemented as threads in Java. The main body of a process is composed of a sequence of phases, after a phase is executed the control is returned to the simulation executive. The process executing a phase is the currently running process. From the system point of view, all processes are active and interacting at the same time.
(C) J Garrido22 Process View Static Process Description Dynamic Process Management Initiate Process Delay (Time) Process Suspend Process Activate Process Terminate Process
(C) J Garrido23 Resource View Standard/Tailored Resource Handler Resource Management Create resource Request resource Acquire resource Release resource Status of resource Destroy resource
(C) J Garrido24 Simulation Executive for the Process Interaction Approach Schedule processes at particular instants, i.e., place processes in the event list Remove processes from the event list ( to make them idle or to terminate them) Re-schedule processes, i.e., change position of processes in the event list. Execute the phase for the “running” process.
(C) J Garrido25 The Simulation Executive
(C) J Garrido26 Java Threads A thread consists of a set of phases, each of which is executed when the simulation executive advances the clock to the required time. Every thread re-starts execution at its own reactivation point (in the active phase), and its corresponding event time.
(C) J Garrido27 Thread With Its Reactivation Points
(C) J Garrido28 Using PsimJ2 Every simulation model defines a set of classes that will be instantiated appropriately The classes that represent processes need to inherit class Process, which is a thread class. The other classes defined are used to create passive objects.
(C) J Garrido29 Active and Passive Objects
(C) J. M. Garrido, Questions?