Assignment 3

  • Worth: 10%

  • DUE: April 14th, 2022 at 11:55pm; submitted on MOODLE.

Warning

For this assignment, you may not work with anyone else.

You need to work independently.

How to submit your work

You need to submit your C++ (.h/.cpp) files directly on moodle. The first two lines of the C++ file should be as follows:

// Student name:
// Student number:

Instructions

  • In this assignment you will compare the efficiency of priority queues.

  • We will consider a coffee shop scenario with customers arriving and ordering different types of coffee.

  • You can put the drinks in two categories:

    • Regular coffees

    • Special coffees

  • Regular coffees cost less, but are faster to serve.

  • While special coffees cost more, but are longer to serve.

  • The purpose is to verify how the coffee shop can earn more just by implementing three types of queues:

    • Regular queues, so no priority: first arrived first served.

    • Priority to regular coffees.

    • Priority to special coffees.

  • To evaluate the most efficient queue:

    • You will simulate 1000 services for each queue.

    • A service last 60 minutes.

    • The coffee shop have a maximum size of 20 customers.

    • When it is full, no new customers can be added to queue.

  • The probability that a new customer arrives every 30 seconds (time step) is 55%.

  • The type of clients/drinks generated follow the probabilities:

  • Regular coffee: 70%

  • Special coffee: 30%

  • The service for each type of coffee follows a uniform distribution in the following range:

  • Regular coffee: 60s - 120s (so between [2 - 4] time steps)

  • Special coffee: 120s - 300s (so between [4 - 10] time steps)

  • The price of the drinks are as follows:

    • Regular coffee: $2

    • Special coffee: $5

Architecture of the program

  • You will need a class Simulator that will simulate the 1000 services and calculate the earning of the coffee shop for each type of queue.

  • You will need a class Queue that will be the regular queue.

  • A class PriorityMin that will implement a min priority queue (minheap) to prioritize the regular coffee customers.

  • A class PriorityMax that will implement a max priority queue (maxheap) to prioritize the special coffee customers.

  • A class Customer that will represent a customer.

  • A file main.cpp.

Customer

  • This class is simple and contains the following variables:

    • type: 1 or 2, 1 for regular coffee and 2 for special coffee.

    • serviceTime that represents the service time of this customer.

    • price the price related to the type of customer.

Simulator

  • This class is the most complicated one.

  • it will have a method to generate a customer based on the previous probabilities.

  • It will have a method to simulate one service:

    • You will have a time step (one iteration) of 30s.

    • Each time step, you will check if a new customer is generated:

      • You will generate the type of customer.

      • You will generate the service time of the customer.

    • When you service a customer you remove it from the queue.

    • But you need to finish servicing the customer to start servicing the next one.

    • When you are servicing the customer you can remove 30s from the service time after each iteration.

    • You add the price of the coffee to the total of the service.

    • At the end of the service (60 min) you add the earning of the service to the total of all services for this type of queue.

  • It will also have a method to simulate the 1000 services.

  • You will implement a method that simulate all the services for each type of queues and print the average earnings per service.

PriorityMin

  • It is a regular binary heap, but the lowest is type the higher is the priority.

PriorityMax

  • It is a regular binary heap, but the higher is type the higher is the priority.

Queue

  • It is a regular queue: FIFO.

Some marking details

Warning

Having the correct outputs doesn’t mean that you will obtain a perfect mark.

The marking will depend on:

  • Correctness.

  • Comments

  • Variable names

  • Style

  • etc.

General FAQ:

  • Does my text file have enough details?
    • Probably. The shorter the better.

  • Do I have enough comments?
    • I don’t know, maybe? If you’re looking at code and have to ask if you should comment it… just comment it. That said, don’t write me a book.

  • Can I work with my friend?
    • No.

  • If our code/functions are identical, you won’t really call this cheating, would you?
    • Yes.

  • Moodle was totally broken, it’s not my fault it’s late.
    • Nice try.

  • I accidentally submitted the wrong code. Here is the right code, but it’s late. But you can see that I submitted the wrong code on time! You’ll still accept it, right?
    • No.