Docsity

CS 2604 Data Structures and File Management - Event Simulation Algorithm for Assignment #2, Assignments of Computer Science

Toggle sidebar
bg1
CS 2604 Data Structures and File Management Summer II 2003
Event Simulation Handout for Programming Assignment #2
The following algorithm is what I suggest you implement for the DMV Simulation
assignment. You are free to improve on it. Most importantly, make sure you understand
how it works, before implementing.
// screen queue: queue at the screening window
// tran queue: priority queue for the transaction windows
// event queue: time-ordered queue used by your program to
// carry out the simulation
t = 0
while event queue not empty OR input file not empty
t, e = time and event details from file or queue (earliest)
if e is a window close command
set window status to closed
else if e is a window open command
set window status to available
generate trytoserve event at t
else if e is an incoming transaction
display transaction details
enqueue transaction to screen queue
generate trytodispatch event at t
else if e is a trytodispatch event
if screen queue is not empty and scrwindow is not busy
dequeue transaction x from screen queue
set scrwindow status to busy
generate dispatch event for x at time t+1
endif
else if e is a dispatch event
display dispatch details
set scrwindow status to available
generate trytodispatch event at t
enqueue transaction to tran queue
generate trytoserve event at t
else if e is a trytoserve event
if tran queue not empty and there is an available window
get first available window
dequeue transaction x from tran queue
set window status to busy
display transaction details
generate completion event at t + x
(where x is the expected length of transaction)
generate trytoserve event at t // this may not be necessary
endif
else if e is a completion event
display completion details
set window status to available
generate trytoserve event at t
endif
endwhile

Partial preview of the text

Download CS 2604 Data Structures and File Management - Event Simulation Algorithm for Assignment #2 and more Assignments Computer Science in PDF only on Docsity!

CS 2604 Data Structures and File Management Summer II 2003

Event Simulation Handout for Programming Assignment

The following algorithm is what I suggest you implement for the DMV Simulation

assignment. You are free to improve on it. Most importantly, make sure you understand

how it works, before implementing.

// screen queue: queue at the screening window // tran queue: priority queue for the transaction windows // event queue: time-ordered queue used by your program to // carry out the simulation

t = 0

while event queue not empty OR input file not empty

t, e = time and event details from file or queue (earliest)

if e is a window close command set window status to closed else if e is a window open command set window status to available generate trytoserve event at t else if e is an incoming transaction display transaction details enqueue transaction to screen queue generate trytodispatch event at t else if e is a trytodispatch event if screen queue is not empty and scrwindow is not busy dequeue transaction x from screen queue set scrwindow status to busy generate dispatch event for x at time t+ endif else if e is a dispatch event display dispatch details set scrwindow status to available generate trytodispatch event at t enqueue transaction to tran queue generate trytoserve event at t else if e is a trytoserve event if tran queue not empty and there is an available window get first available window dequeue transaction x from tran queue set window status to busy display transaction details generate completion event at t + x (where x is the expected length of transaction) generate trytoserve event at t // this may not be necessary endif else if e is a completion event display completion details set window status to available generate trytoserve event at t endif

endwhile