lecture3

Document Sample

```					 2WB05 Simulation
Lecture 3: Discrete Event
Simulation II
Marko Boon
http://www.win.tue.nl/courses/2WB05

November 26, 2012
Discrete-event simulation                    2/21

Entity             Attribute

Job                Arrival time

Machine            Status (idle or busy)

Job is a temporary entity
Machine is a permanent entity

Department of Mathematics and Computer Science
Discrete-event simulation                       3/21

Elementary events

Job:                       Machine:

arrival                    remove from queue

departure                  become busy

begin service              become idle

end service

join queue

Department of Mathematics and Computer Science
Discrete-event simulation                                    4/21

Compound events

Arrival

begin service
become busy

arrival

join queue

Department of Mathematics and Computer Science
Discrete-event simulation                                                5/21
Departure

remove from
queue
begin service

end service                             departure

become idle

Department of Mathematics and Computer Science
Discrete-event simulation                                          6/21

State of the system at time t:

• status of the machine (i = 0, 1)
• number of jobs in the queue (n = 0, 1, 2, . . .)
• remaining interarrival time (a ≥ 0)
• remaining service time (b ≥ 0)

Then the remaining time until the next event is given by

min(a, b)

Department of Mathematics and Computer Science
Discrete-event simulation                                     7/21

Prototypical event-scheduling approach:

program

schedule
initial events

timing
routine

end
simulation

show
statistics

end

Department of Mathematics and Computer Science
Discrete-event simulation                              8/21

timing
routine

event from              to next event      event
FES                  time

yes        time <
run length?

no

end
simulation

Department of Mathematics and Computer Science
Discrete-event simulation                                                                                                                                              9/21

UML Class Diagram
Queue

#   customers: Vector<Customer>                      EventQueue
#   n: int                                    #   events: Vector<Event>
#   sumS: double
#   sumS2: double                             +   addEvent(Event) : void
#   sumW: double                              +   EventQueue()
#   sumW2: double                             +   nextEvent() : Event
#   surface: double
#   t: double

+   getCustomerAt(int) : Customer
+   getMeanNumberOfCustomers() : double
+   getMeanSojournTime() : double
Event
+   getMeanWaitingTime() : double
+   getSize() : int                           +   ARRIVAL: int = 1 {readOnly}
+   getVarianceSojournTime() : double                                                                 Customer
#   customer: Customer
+   getVarianceWaitingTime() : double         +   DEPARTURE: int = 2 {readOnly}             #   arrivalTime: double
+   Queue()                                   #   time: double                    #customer
#   serviceTime: double
+   removeCustomer(double) : Customer         #   type: int
+   Customer(double, double)
+   Event(int, double)                        +   getArrivalTime() : double
+   Event(int, double, Customer)              +   getServiceTime() : double
+   getCustomer() : Customer
+   getTime() : double
MultiServerQueue                   +   getType() : int
#   c: int

+   getNumberOfServers() : int
+   MultiServerQueue(int)
+   removeCustomer(Customer, double) : Customer

Department of Mathematics and Computer Science
Discrete-event simulation                                                             10/21

The Customer class

Customer

#   arrivalTime: double
#   serviceTime: double

+   Customer(double, double)
+   getArrivalTime() : double
+   getServiceTime() : double

The Customer (or Job) contains information about his Arrival Time and Service Time.
Possible extensions: different customer types (priority queues).

Department of Mathematics and Computer Science
Discrete-event simulation                                                                                    11/21

The Event class

Event

+   ARRIVAL: int = 1 {readOnly}
#   customer: Customer
+   DEPARTURE: int = 2 {readOnly}
#   time: double
#   type: int

+   Event(int, double)
+   Event(int, double, Customer)
+   getCustomer() : Customer
+   getTime() : double
+   getType() : int

The Event contains information about the time at which it occurs, its type (ARRIVAL or DEPARTURE), and to which
Customer it corresponds.

Department of Mathematics and Computer Science
Discrete-event simulation                                                                                  12/21

The EventQueue class

EventQueue

#   events: Vector<Event>

+   EventQueue()
+   nextEvent() : Event

The EventQueue is the implementation of the Future Event Set (FES). It contains a sorted list of Events.

Department of Mathematics and Computer Science
Discrete-event simulation                                                                         13/21

The Queue class

Queue

#   customers: Vector<Customer>
#   n: int
#   sumS: double
#   sumS2: double
#   sumW: double
#   sumW2: double
#   surface: double
#   t: double

+   getCustomerAt(int) : Customer
+   getMeanNumberOfCustomers() : double
+   getMeanSojournTime() : double
+   getMeanWaitingTime() : double
The Queue is the implementation of the machine
+   getSize() : int                         (server) and its current list of Customers.
+   getVarianceSojournTime() : double
+   getVarianceWaitingTime() : double
It computes all kind of performance measures on-the-
+   Queue()                                 ﬂy, like the total sum of sojourn times, waiting times,
+   removeCustomer(double) : Customer
number of customers up to time t etc..

Department of Mathematics and Computer Science
Discrete-event simulation                                                                             14/21

The MultiServerQueue class
Queue

#   customers: Vector<Customer>
#   n: int
#   sumS: double
#   sumS2: double
#   sumW: double
#   sumW2: double
#   surface: double
#   t: double

+   getCustomerAt(int) : Customer
+
+
getMeanNumberOfCustomers() : double
getMeanSojournTime() : double
An implementation of a multi server queue. It inherits
+
+
getMeanWaitingTime() : double
getSize() : int                           from the Queue class. It is not used in this example.
+   getVarianceSojournTime() : double
+   getVarianceWaitingTime() : double
+   Queue()
+   removeCustomer(double) : Customer

MultiServerQueue

#   c: int

+   getNumberOfServers() : int
+   MultiServerQueue(int)
+   removeCustomer(Customer, double) : Customer

Department of Mathematics and Computer Science
Discrete-event simulation                                                    15/21

Arrival event:

arrival                  create                 determine     schedule
Job                    time next     next
arrival       arrival

yes
arrange                      succes?          attempt
service                                       service

no

join queue

select next
event

Department of Mathematics and Computer Science
Discrete-event simulation                                                            16/21
Departure event:

departure                            queue    no   get first     arrange
empty?        job from      service
queue

yes
machine    select next
becomes       event
idle

Department of Mathematics and Computer Science
Discrete-event simulation                                                                    17/21

Initialization

Queue q = new Queue();
EventQueue eventq = new EventQueue();
Random rand = new Random();
Distribution interarrivalTimeDist =
new ExponentialDistribution(lambda, rand);
Distribution serviceTimeDist =
new ExponentialDistribution(mu, rand);
double t = 0;
// generate first arrival
interarrivalTimeDist.nextRandom()));
The Distribution and ExponentialDistribution class are part of a package that can be downloaded
from the website.

Department of Mathematics and Computer Science
Discrete-event simulation                    18/21

Main program

while (t < simLength) {
Event e = eventq.nextEvent();
t = e.getTime();
switch (e.getType()) {
case Event.ARRIVAL : {
// handle arrival
}
case Event.DEPARTURE : {
// handle departure
}
}
}

Department of Mathematics and Computer Science
Discrete-event simulation                          19/21

case Event.ARRIVAL : {
// schedule next arrival
t + interarrivalTimeDist.nextRandom()));

double serviceTime =
serviceTimeDist.nextRandom();
if (q.getSize() == 1) {
t + serviceTime));
}
break;
}

Department of Mathematics and Computer Science
Discrete-event simulation                        20/21

case Event.DEPARTURE : {
q.removeCustomer(t);
if (q.getSize() > 0) {
double serviceTime =
q.getCustomerAt(0).getServiceTime();
t + serviceTime));
}
break;
}

Department of Mathematics and Computer Science
Discrete-event simulation                         21/21

Print Results:

System.out.println("Mean waiting time: " +
q.getMeanWaitingTime());
System.out.println("Var. waiting time: " +
q.getVarianceWaitingTime());
System.out.println("Mean sojourn time: " +
q.getMeanSojournTime());
System.out.println("Var. sojourn time: " +
q.getVarianceSojournTime());
System.out.println("Mean nr. of. customers: " +
q.getMeanNumberOfCustomers());

Department of Mathematics and Computer Science

```
DOCUMENT INFO
Categories:
Tags:
Stats:
 views: 0 posted: 3/3/2013 language: Latin pages: 21