Presentation is loading. Please wait.

Presentation is loading. Please wait.

COMPUTER 2430 Object Oriented Programming and Data Structures I

Similar presentations


Presentation on theme: "COMPUTER 2430 Object Oriented Programming and Data Structures I"— Presentation transcript:

1 COMPUTER 2430 Object Oriented Programming and Data Structures I

2 Prog 4: Simulation From Webster
a: the imitative representation of the functioning of one system or process by means of the functioning of another  a computer simulation of an industrial process

3 Queuing Systems Single Line Single Server
Jobs Waiting to be served One server services jobs Jobs wait in line (queue) if the server is busy (example: Mongolian Grill)

4 Performance of Queuing Systems
Some properties of interest Max line length Average line length Server utilization Jobs served immediately Average time in line (with or without “no-waits”) Max waiting time (with or without “still waiting”) . . .

5 Performance of Queuing Systems
How to get the statistics? Actual observation/recording Simulation Prog4 Not real But close to real

6 Simulation Server Job_Processed: null curTime Jobs

7 Time Unit Discrete time unit Integer starting with 0
Pick the right unit so that at most one arrival per time unit Job is just a time stamp

8 Simulation Server Job_Processed: null When does the first job come?
Initialization Job1: 4 . . . When does the first job come? Pre-Scheduled curTime Jobs

9 Simulation Server Job_Processed: null Jobs: Pre-Scheduled!
Initialization Job1: 4 . . . curTime Jobs: Pre-Scheduled!

10 Simulation Server Job_Processed: null Jobs: Pre-Scheduled!
Initialization Job1: 4 4 9 Job1: 4 Job2: 5 curTime Jobs: Pre-Scheduled!

11 Simulation Server Job_Processed: Job1 Next event? Completing at 8.
When completed? Pre-Scheduled: 4 Next event? Completing at 8. Initialization 4 8 9 Job1: 4 Job2: 5 curTime Jobs: Pre-Scheduled!

12 Simulation Server Job_Processed: Job1 Jobs: Pre-Scheduled!
Initialization 4 8 9 Job1: 4 Job2: 5 curTime Jobs: Pre-Scheduled!

13 Simulation Server Job_Processed: null Next event? Arrival at 9.
Initialization 4 8 9 Job1: 4 Job2: 5 curTime Jobs: Pre-Scheduled!

14 Simulation Server Job_Processed: null Jobs: Pre-Scheduled!
Initialization 4 8 9 13 Job1: 4 Job2: 5 Job3: 4 curTime Jobs: Pre-Scheduled!

15 Simulation Server Job_Processed: Job2 Next event? Arrival at 13.
Pre-Scheduled: 6 Next event? Arrival at 13. Initialization 4 8 9 13 15 Job1: 4 Job2: 5 Job3: 4 curTime Jobs: Pre-Scheduled!

16 Simulation Server Job_Processed: Job2 Jobs: Pre-Scheduled!
Initialization 4 8 9 13 15 20 Job1: 4 Job2: 5 Job3: 4 Job4: 7 curTime Jobs: Pre-Scheduled!

17 Simulation Server Job_Processed: Job2 Next event? Completing at 15.
Pre-Scheduled: 6 Job3 Next event? Completing at 15. Initialization 4 8 9 13 15 20 Job1: 4 Job2: 5 Job3: 4 Job4: 7 curTime Jobs: Pre-Scheduled!

18 Simulation Server Job_Processed: Job2 Jobs: Pre-Scheduled! Job3
Initialization 4 8 9 13 15 20 Job1: 4 Job2: 5 Job3: 4 Job4: 7 curTime Jobs: Pre-Scheduled!

19 Simulation Server Job_Processed: Job3 Jobs: Pre-Scheduled!
Completing at 20 Initialization 4 8 9 13 15 20 Job1: 4 Job2: 5 Job3: 4 Job4: 7 curTime Jobs: Pre-Scheduled!

20 Simulation Server Job_Processed: Job3 Next event?
Pre-Scheduled: 5 Completing at 20 Next event? Arrival & Completing:20 Initialization 20 4 8 9 13 15 Job1: 4 Job2: 5 Job3: 4 Job4: 7 curTime Jobs: Pre-Scheduled!

21 Pseudo Code Initialize simulation While not done update curTime to nextEventTime If curTime == Service Completion Time then Do Service Completion If curTime == Arrival Time then Do Arrival If curTime == Stop Time then Set done to true Dump statistics Multiple events can happen at the same time! Not If - Else The order to handle the events!

22 Class java.util.Random import java.util.*; Random randInt = new Random(2345); // seed 2345 int rand = randInt.nextInt(x); // returns an integer between 0 and (x – 1) // randInt.nextInt(6): 0 to 5 // To generate a random number in [5, 10] // 5 + randInt.nextInt(6) // To generate a random number in [a, b] // a + randInt.nextInt(b – a + 1)

23 Pre-Scheduling Jobs Random randArrival = new Random(2345); // seed 2345 // Arrival: [arr_min, arr_max] nextArrivalTime = arr_min + randArrival.nextInt(arr_max – arr_min + 1); nextArrivalTime = curTime + nextArrivalTime;

24 Pre-Scheduling Job-Completion
Random randCompl = new Random(5432); // Different seed! . . .

25 Constructor Set values for arr_min, arr_max, sc_min, sc_max, stop_time
Class Simulation Constructor Set values for arr_min, arr_max, sc_min, sc_max, stop_time

26 Initialize Simulation
Job reset server  idle Initialize stats to be collected if stop time is 0 then done  true else done  false Create a queue Schedule the first Arrival Time

27 Next Event Time When the server is idle When the server is busy
the minimum of the arrival time and Stop time When the server is busy the minimum of the arrival time, Service Completion time, and Stop time

28 Arrival Event (without statistics gathering)
Create a Job Schedule the next Arrival Time If server is busy then Enter the queue Else Schedule Service Completion Time Set server to busy

29 Server Completion (without statistics gathering)
If the queue is empty then Set server to idle Else Remove a job from the queue Schedule Service Completion Time

30 Pseudo Code Initialize simulation While not done update curTime to nextEventTime If curTime == Service Completion Time then Do Service Completion If curTime == Arrival Time then Do Arrival If curTime == Stop Time then Set done to true Dump statistics

31 Simulation Output Current Job: J:19/T:190 Num Arrived: 20 Num Waiting: 1 Num Served Immed: 3 Max Waiting Time: 15

32 Multiple Line Single Server
Jobs

33 Multiple Line Multiple Server
Jobs Server2

34 Single Line Multiple Server
Jobs Server2

35 Schedule Prog4 Groups Signup 5 PM, Wednesday, 11-8 Quiz 4
Friday, 11-10 Prog4 Work Plan 5 PM, Friday, 11-10 Lab8 and Lab9: Job and Queue 11 PM, Wednesday, 11-15 Test 2: Friday, 11-17 Prog4: Tuesday, 11-21


Download ppt "COMPUTER 2430 Object Oriented Programming and Data Structures I"

Similar presentations


Ads by Google