Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Introduction to Simulation Discrete Simulation Analytical Modeling Modeling Paradigms Input Modeling Random Number Generation Output Analysis Continuous and Hybrid Simulation Simulation Software
Discrete Simulation 1
Contents
Organization of Discrete-Event Simulation (DES) Simulation of a Single-Server Queue Hand Simulation of the Queue Simulation with AnyLogic Simulation with AutoMod Simulation with OPNET Simulation with OMNeT++ Simulation with Syntony Simulation in Java List Processing in Simulation
Discrete Simulation 2
Organization of Discrete-Event Simulation Recall: in discrete-event simulation, events occur instantaneously at separate points in time and change the state variables Two mechanisms to advance the simulated time:
next-event time advance the simulation clock is always advanced to the time of the next event, the state variables are updated and future event times are determined, until termination is used by all major simulation software and by most people coding their model in a general-purpose language will be used throughout the lectures fixed-increment time advance the simulation clock is always advanced in increments of t time units useful for systems in which the time advances in fixed increments (e.g., economic systems with annual change, slotted communication systems)
Discrete Simulation 3
although this model seems simple compared with those usually of real interest, how it is simulated is actually quite representative we will use it for illustrations throughout this and later lectures
Discrete Simulation 4
Organization of Discrete-Event Simulation (cont.) Events and times in the single-server queue
ti = time of arrival of the i'th customer (i=1,2,3,) Ai = ti ti-1 = inter-arrival time between the (i-1)st and the i'th arrivals of customers (t0 = 0) Si = time the server spends serving the i'th customer (without the customers waiting time) Wi = waiting time of the i'th customer Di = Wi + Si = time in system of the i'th customer (also often called total delay or response time of the system) ci = ti + Wi + Si = ti + Di = time i'th customer completes service and departs ei = time of occurrence of i'th event of any type
Discrete Simulation 5
Discrete Simulation 6
e0
0 A1
e1
t1 A2 S1
e2
t2
e3
c1 A3
e4
t3
e5
c2 Time
S2
Discrete Simulation 7
e 1 t
2t
e2 e3
3t e4
4t
Time
Discrete Simulation 8
Organization of Discrete-Event Simulation (cont.) Typical components in DES (with next-event time approach):
system state: collection of state variables necessary to describe the system at a particular time simulation clock: variable giving the current value of simulated time event list: list containing the next time when each type of event will occur statistical counters: variables used for storing statistical information about system performance initialization routine: subprogram to initialize the simulation model at time 0 timing routine: subprogram that determines the next event from the event list and then advances the simulation clock to the time when that event is to occur
Discrete Simulation 9
1. Update system state 2. Update statistical counters 3. Generate future events and add to event list, eventually remove others from the event list
No
Stop
Discrete Simulation 11
Discrete Simulation 12
Discrete Simulation 13
Simulation of a Single-Server Queue (cont.) Define 3 measures of system performance for SSQ
d(n) = expected mean time in system (delay) of the first n customers q(n) = expected mean queue length until n customers have been served u(n) = expected utilization until n customers have been served = expected average proportion of time that the server is busy until n customers have been served
Discrete Simulation 14
Simulation of a Single-Server Queue (cont.) Estimation of the system time / delay / response time:
from a single run of the simulation resulting in customer delays D1, D2, D3, ..., an obvious estimator of d(n) is 1 n d(n) = Di n i=1 which is just the arithmetic mean of the n Dis that were observed in the simulation as a common convention, ^ (circumflex) above a symbol denotes an estimator since the average (arithmetic mean) is taken over a finite number of values (a subcase of a countable set), this measure is an example of a discrete-time statistics the expected mean waiting time is similarly estimated from W1, W2,
Discrete Simulation 15
Q(t ) dt
for computing it easily, let Ti be the total time during the simulation that the queue is of length i, then 1 (n) = q iTi T(n) i=0 the area can be accumulated as rectangles as the simulation progresses over time
Simulation and Modeling I Discrete Simulation 16
0
e1=0.4
1
e2=1.6
4
e8=4.0 e7=3.8 e6=3.3
6
e11=5.8 e10=5.6
9 t
Arrivals
e3=2.1
e12=7.2
Departures
e4=2.4 e5=3.1
e9=4.9
e13=8.6=T (5)
Discrete Simulation 17
i=0
numerator:
our estimate of the average number in queue gets: q (5 ) = 9.9 / 8.6 = 1.15
Discrete Simulation 18
B( t ) dt
Discrete Simulation 19
1
e2=1.6
2
e3=2.1
4
e8=4.0 e7=3.8 e6=3.3
6
e11=5.8 e10=5.6
9t
e4=2.4 e5=3.1
e9=4.9
and
(5 ) = u
( 3 .3 0 .4 ) + ( 8 .6 3 .8 ) 7 .7 = = 0.90 8 .6 8 .6
Discrete Simulation 20
Discrete Simulation 21
idle
poisoning
server
Server Number Times Time status in of last of queue arrival event of queued customers
Statistical counters 0 0 0 0
Number Total Area Area served waiting under under time Q(t) B(t)
System
Simulation and Modeling I
Computer representation
Discrete Simulation 23
Server Number Times Time status in of last of queue arrival event of queued customers
Statistical counters 0 0 0 0
Number Total Area Area served waiting under under time Q(t) B(t)
System
Simulation and Modeling I
Computer representation
Discrete Simulation 24
Server Number Times Time status in of last of queue arrival event of queued customers
Number Total Area Area served waiting under under time Q(t) B(t)
System
Simulation and Modeling I
Computer representation
Discrete Simulation 25
Server Number Times Time status in of last of queue arrival event of queued customers
Number Total Area Area served waiting under under time Q(t) B(t)
System
Simulation and Modeling I
Computer representation
Discrete Simulation 26
1.6 2.1
Server Number Times Time status in of last of queue arrival event of queued customers
Number Total Area Area served waiting under under time Q(t) B(t)
System
Simulation and Modeling I
Computer representation
Discrete Simulation 27
2.1
Server Number Times Time status in of last of queue arrival event of queued customers
Number Total Area Area served waiting under under time Q(t) B(t)
System
Simulation and Modeling I
Computer representation
Discrete Simulation 28
idle
Server Number Times Time status in of last of queue arrival event of queued customers
Number Total Area Area served waiting under under time Q(t) B(t)
System
Simulation and Modeling I
Computer representation
Discrete Simulation 29
3.8
Server Number Times Time status in of last of queue arrival event of queued customers
Number Total Area Area served waiting under under time Q(t) B(t)
System
Simulation and Modeling I
Computer representation
Discrete Simulation 30
3.8 4.0
Server Number Times Time status in of last of queue arrival event of queued customers
Number Total Area Area served waiting under under time Q(t) B(t)
System
Simulation and Modeling I
Computer representation
Discrete Simulation 31
4.0
Server Number Times Time status in of last of queue arrival event of queued customers
Number Total Area Area served waiting under under time Q(t) B(t)
System
Simulation and Modeling I
Computer representation
Discrete Simulation 32
4.0 5.6
Server Number Times Time status in of last of queue arrival event of queued customers
Number Total Area Area served waiting under under time Q(t) B(t)
System
Simulation and Modeling I
Computer representation
Discrete Simulation 33
Server Number Times Time status in of last of queue arrival event of queued customers
Number Total Area Area served waiting under under time Q(t) B(t)
System
Simulation and Modeling I
Computer representation
Discrete Simulation 34
Server Number Times Time status in of last of queue arrival event of queued customers
Number Total Area Area served waiting under under time Q(t) B(t)
System
Simulation and Modeling I
Computer representation
Discrete Simulation 35
Server Number Times Time status in of last of queue arrival event of queued customers
Number Total Area Area served waiting under under time Q(t) B(t)
System
Simulation and Modeling I
Computer representation
Discrete Simulation 36
Discrete Simulation 38
Discrete Simulation 39
Java-based
textual model parts in Java executable model + simulation engine mapped on Java other Java code can be linked
Simulation and Modeling I Discrete Simulation 40
connector
port (with queue; deprecated) port reference port (without queue) statechart event dynamic event
Discrete Simulation 41
[All items checked && some items not in stock] Item Received [some items not in stock]
transition
Waiting
self-transition State
Delivered
Discrete Simulation 42
Discrete Simulation 43
exp(1/10)/port.send()
2 active objects: client and server connected via ports, with a queue at server port 2 timed events: exponentially distributed inter-arrival and service times with means equal to 10 and 9
Simulation and Modeling I Discrete Simulation 45
Discrete Simulation 46
Simulation with AnyLogic (cont.) Runtime view windows to inspect model execution
Discrete Simulation 47
Implementation in AnyLogic:
Discrete Simulation 48
Discrete Simulation 49
select buttons for continuous-time statistics, like queue length or discrete-time statistics, like waiting time
Discrete Simulation 51
Condition Trigger CustomerQueue.size() > 0 Action WaitingTime.add( time() CustomerQueue.removeFirst().doubleValue()); QueueLength.update(); BusyFunction.add(1, time());; Rate Trigger 0.11111 Action Throughput = (++CustomersServed)/time(); BusyFunction.add(0, time());
Simulation and Modeling I Discrete Simulation 52
Simulation with AnyLogic (cont.) Graphical output (initial plots) and statistics (at t=10.000 sec)
flexible visualization of data via various types of charts (time plots, histograms, bar, stack and pie charts, etc.) usual procedure: collect data in Data Set objects connect data set to desired visualization object data is displayed during simulation run drawback: each graphic below requires two data sets (actual value and mean) in addition to Statistics objects (WaitingTime, QueueLength, BusyFunction)
Discrete Simulation 53
More information
Discrete Simulation 55
loads: dynamic entities which are moved around queues: buffers where loads can reside (i.e., wait or are being processed) resources: needed for processing loads processes: logical control of movement and resource usage of loads, executed by loads, causes events to happen
Discrete Simulation 56
Result display
standard statistics about all modeling entities (queues, resources, ...): current value, mean, min, max, ... customized graphs (e.g., business graphics)
Discrete Simulation 58
current value
averaged value
Discrete Simulation 59
Discrete Simulation 60
Discrete Simulation 61
Simulation with AutoMod (cont.) Mean waiting time in Q_waitingroom (in sec)
79 min
Discrete Simulation 62
Discrete Simulation 63
Discrete Simulation 64
Discrete Simulation 65
state-transition diagrams at the core, here called Finite-State Machines (FSMs) communication via packets ( messages) hierarchical structure (network, module and process level with dedicated editors: Project, Node and Process editor) packet streams are similar to connected ports, but the FSM itself must react to a reception (in AnyLogic port actions after a reception) initial states are needed in each FSM events have to be scheduled explicitly coding in C/C++ and Proto-C (OPNET-specific kernel procedures) even simple models require various kernel procedures
Discrete Simulation 66
2 modules (here processes) with an extended FSM each connected via a packet stream with a queue the guards ARRIVAL and SCV_COMPLETION control which transition may be taken causing specific actions (C code) ARRIVAL: get packet from stream; start service if end of idle period SVC_COMPLETION: start new service unless end of busy period
Simulation and Modeling I Discrete Simulation 67
Node/Module level
Attribute process model : SSQ_generator InterarrivalMean : promoted
Discrete Simulation 68
Discrete Simulation 69
kernel procedures to generate packet (op_pk_create()) and send it to a packet stream (op_pk_send()) generated packets implicitly get a time stamp!
kernel procedures to generate exponentially distributed interrarrival times (op_dist_exponential()) and to schedule an interrupt for the next arrival time (op_intrpt_schedule_self())
Discrete Simulation 70
transition executives
Discrete Simulation 71
Discrete Simulation 72
Finite-State Machines (FSMs) as C++ code, no graphical representation communication via messages hierarchical structure (network, complex and simple modules) textual representation of model structure: ned files graphical model structure editor: GNED initial states are needed in each FSM events have to be scheduled explicitly coding in C/C++ using the OMNeT++ API INET framework for internet protocols, mobility, wireless channels (loss, fading) used in a joint simulation study of our group and Siemens Industry for sensor networks in automation
Discrete Simulation 73
handleMessage() busy
handleMessage()
Discrete Simulation 74
Discrete Simulation 75
Discrete Simulation 76
kernel procedures to generate packet (new cMessage()) and send it to a port (send()) generated packets implicitly get a time stamp!
kernel procedures to generate exponentially distributed interrarrival times (exponential()) and to schedule an event for the next arrival time (scheduleAt())
Discrete Simulation 77
Discrete Simulation 78
Discrete Simulation 79
Discrete Simulation 80
Discrete Simulation 81
Discrete Simulation 82
Discrete Simulation 83
Modeling paradigm
idle
busy
Discrete Simulation 86
Definition of variables (and their values) that can be accessed in the model
Discrete Simulation 87
Casual statement specifying the action to be taken on transition execution: Create a new client signal (client.create()) and send it to the port called departures (sendTo(departures))
Discrete Simulation 88
Discrete Simulation 89
Discrete Simulation 90
event log
network view
Discrete Simulation 91
set the options for the plot (name, labels, colors, ...)
Discrete Simulation 92
time series plot of the queue length at the server of a single-server queue
set the options for the plot (name, labels, colors, ...)
Discrete Simulation 93
Discrete Simulation 94
Discrete Simulation 96
2 random number streams 2 lists: queue + service unit 2 counters: mean queuing delay, mean queue length customers with their arrival and service times
Discrete Simulation 97
... public static void main (String[] args) { new QueueEv(); } public QueueEv() { Sim.init(); new EndOfSim().schedule (timeHorizon); new Arrival().schedule (Rand1.expon (genArr, meanArr)); Sim.start(); } ...
Discrete Simulation 98
Discrete Simulation 99
schedule next arrival create new customer, set arrival time, generate service time join queue, update counter enter service, schedule Departure, update counter
remove customer move customer from queue to service unit, schedule Departure, update counters
... class EndOfSim extends Event { public void actions () { queuingD.report(); queueL.report(); Sim.stop(); } } }
write statistical report for the two counters stop event processing
Values differ from AutoMod results, 1000 minutes correspond to 16 hours only!
start event list processing get first event set sim. clock, execute event, get next event
time of event occurrence event type identification construct + schedule event determine event time, insert in event list
schedule event
Higher level modeling paradigm and tool environment makes modeling less tedious
Simulation and Modeling I Discrete Simulation 110
can be implemented by using pointers (links) in C, Java (or arrays in languages without dynamic data structures such as FORTRAN) each object has a link to its successor and predecessor special links to the first and the last object of the list typical operations: insert an object in the list such that the list is sorted (increasing/decreasing) according to a certain variable get an object at the i'th position of the list (get the first, get the last element) remove a certain object according to its variable or position
node with predecessor, successor first and last pointers pointer to stack of free nodes insertion at first position