Upload files to 'Exercise 7 - Assignment 2 Preparation (Week 8)'

This commit is contained in:
Manish 2021-04-28 08:29:27 +02:00
parent a818bfc540
commit e96124bc8a
2 changed files with 65 additions and 0 deletions

Binary file not shown.

View File

@ -0,0 +1,65 @@
Q1. Main program function (loop explained in detail in Q3).
- Input file name
- try opening file, print error and exit if fails
- read two integers i.e. no. of business class and tourist class servers (these serve as artificial limits on respective idle server queues)
- read (float, integer, float) and initialise min-heap with this event
- start simulation loop in which event at the top min-heap is processed (explained in part Q3.)
- seek to the top of the file for second scenario simulation
- read (float, integer, float) and initialize min-heap with this event
- start simulation loop in which event at the top min-heap is processed (explained in part Q3.). This time, business servers can serve tourist customers if free and business customer queue is empty (explained in Part Q3.)
Q2. Event can be either arrival of new customer or completion of serving a customer
Q3. Each event (element in min-heap) has event ID. If id == 0 than event type is new customer arrival, else event is completion of serving a customer by a server. Server type is identified by server id no. Business class servers are in range 1-20 and tourist class servers in range 21-40. [Alternatively, business class server are in the range 1 to no. of business customers and tourist servers are above business customer servers.]
- simulation while loop
- if heap[0].id == 0 i.e. event type is customer arrival than:
- save heap[0] in current_customer variable
- read next customer arrival in heap[0]
- if next read is (0, 0, 0) i.e. no more customers than:
- swap heap[0] with heap[-1]
- reduce heap size by 1
- else:
- replace heap[0] with next arrival record
- shiftdown(heap[0])
- (current_customer variable) if any of it's class server free i.e its idle server queue is not empty than:
- assign customer to that server
- add it to the back of heap
- Set its event time current time + service time (when the server will be finished with current customer)
- extend heap size by 1
- shiftup(Heap[-1])
- else if no server free
- add customer to respective queue
- else if heap[0].id != 0 i.e. event type is a server finished with serving a customer
- if respective queue isEmpty() == true:
- replace heap[0] with queue.pop() (first customer in queue)
- shiftdown(heap[0])
- else if respective isEmpty() == false:
- free server and add it to respective idle servers queue
- swap heap[0] with heap[-1] and reduce heap size by 1
- shift down heap[0]
- if heap_size == 0:
- break loop
For second of simulation, all will be same except when business customer server finishes serving and business customer queue is empty:
- if tourist customer queue is not empty
- server that tourist customer
And:
- if arrival is tourist customer:
- if no idle tourist server and tourist queue is empty:
- if any idle business server:
- assign customer to business server