SlideShare a Scribd company logo
1 of 33
#include "customer.h"
#include "heap.h"
#include <iostream>
using namespace std;
int comparisonWay = 0; // 0 for arrival time, 1 for processing
time
bool Customer::operator>(const Customer& c) {
return comparisonWay ? processing_time <
c.processing_time : arrival_time < c.arrival_time; // a customer
is "greater" if his time is shorter
};
void customerQueueTest(int n_cust) {
int current_time = 0;
int totalWaitingTime = 0;
int i;
int WT = 0; // waiting time for each customer
Heap<Customer> queue;
Customer* custList = new Customer[n_cust];
cout << endl << endl << "Setup" << endl;
cout << "List of customers and their arrival and processing
times" << endl;
for (i = 0; i<n_cust; i++)
{
custList[i].setAT(i);
custList[i].setPT((n_cust - i) % (n_cust / 2) + 1 + (i
% 2)*(n_cust / 2));
cout << "Customer " << i << " will arrive at time " <<
custList[i].AT() << " with PT=" << custList[i].PT() << endl;
}
cout << endl;
for (int round = 0; round<2; round++) {
// you may need a big modification within this for-
loop
cout << endl << endl;
cout << "Test Round " << round + 1 << endl;
cout << (round == 0 ? "First come first serve" :
"Customer with the least PT served first") << endl;
comparisonWay = round;
current_time = 0;
totalWaitingTime = 0;
queue.insert(custList[0]);
cout << "Customer arrives at time " <<
custList[0].AT() << " with PT=" << custList[0].PT() << endl;
while (!queue.empty()) {
// you should change all of the code here inside
Customer c = queue.extractMax();
cout << "Customer arrives when no one is
waiting" << endl;
cout << "Customer is served at time " <<
current_time << " with AT=" << c.AT() << " and PT=" <<
c.PT() << " after waiting for "
<< WT << " min." << endl;
}
cout << "Total Waiting Time: " << totalWaitingTime
<< endl;
cout << "Average Waiting Time: " <<
totalWaitingTime / (float)n_cust << endl;
}
delete[] custList;
}
#pragma once
#include <math.h>
#include <iostream>
using namespace std;
#ifndef HEAPHPP
#define HEAPHPP
template <class T>
void Heap<T>::_bubbleUp(int index) {
}
template <class T>
void Heap<T>::_bubbleDown(int index) {
}
template <class T>
void Heap<T>::insert(T item) {
}
template <class T>
T Heap<T>::extractMax() {
return T();
}
template <class T>
void Heap<T>::printHeapArray() {
for (int i = 0; i < _n; i++)
cout << _heap[i] << " ";
cout << endl;
}
template <class T>
int Heap<T>::_lookFor(T x){ // not a very good
implementation, but just use this for now.
int i;
for(i=0;i<_n;i++)
if (_heap[i] == x)
return i;
return -1;
}
template <class T>
void Heap<T>::decreaseKey(T from, T to)
{
}
template <class T>
void Heap<T>::increaseKey(T from, T to)
{
}
template <class T>
void Heap<T>::deleteItem(T x)
{
}
template <class T>
void Heap<T>::printTree() {
int parity = 0;
if (_n == 0)
return;
int space = pow(2,1 + (int) log2f(_n)),i;
int nLevel = (int) log2f(_n)+1;
int index = 0,endIndex;
int tempIndex;
for (int l = 0; l < nLevel; l++)
{
index = 1;
parity = 0;
for (i = 0; i < l; i++)
index *= 2;
endIndex = index * 2 - 1;
index--;
tempIndex = index;
while (index < _n && index < endIndex) {
for (i = 0; i < space-1; i++)
cout << " ";
if(index==0)
cout << "|";
else if (parity)
cout << "";
else
cout << "/";
parity = !parity;
for (i = 0; i < space; i++)
cout << " ";
index++;
}
cout << endl;
index=tempIndex;
while (index < _n && index < endIndex) {
for (i = 0; i < (space-1-((int)
log10(_heap[index]))); i++)
cout << " ";
cout << _heap[index];
for (i = 0; i < space; i++)
cout << " ";
index++;
}
cout << endl;
space /= 2;
}
}
#endif
#include "heap.h"
#include "customer.h"
void heapTest();
void hiddenHeapTest();
void customerQueueTest();
int main() {
heapTest();
//customerQueueTest(10);
}
void heapTest(){
Heap<int> ih;
cout << "Interger Heap Test" << endl;
for (int i=1; i < 16; i++)
{
ih.insert(i);
cout << "Insert " << i << " into the heap." << endl;
cout << "Heap Array:";
ih.printHeapArray();
cout << endl;
ih.printTree();
cout << endl << endl;
}
cout << "Increasing 13 to 99" << endl;
ih.increaseKey(13,99);
cout << "Heap Array:";
ih.printHeapArray();
cout << endl;
ih.printTree();
cout << endl << endl;
cout << "Deleting the item 2" << endl;
ih.deleteItem(2);
cout << "Heap Array:";
ih.printHeapArray();
cout << endl;
ih.printTree();
cout << endl << endl;
cout << "Deleting the item 10" << endl;
ih.deleteItem(10);
cout << "Heap Array:";
ih.printHeapArray();
cout << endl;
ih.printTree();
cout << endl << endl;
cout << "Decreasing the key 15 to 13)" << endl;
ih.decreaseKey(15,13);
cout << "Heap Array:";
ih.printHeapArray();
cout << endl;
ih.printTree();
cout << endl << endl;
for (int i = 1; i < 12; i++)
{
cout << "Extract Max: Max = ";
cout << ih.extractMax() << endl;
ih.printTree();
cout << endl << endl;
}
}
Heap and Queueing Simulation
Two BIG Parts
• Implementing Heap
– Basic requirement
• Perform a queueing simulation experiment
with Priority Queue
– Difficult
– Treat it as a mini project
Time to Level UP!
Something Different
• We will NOT give you the MSVC .sln or Xcode
project
– It’s time for you to create your own
– Any problem, please refer to Lab 1 slides
Something Different
• We will tell you need to do
– Namely, list of tasks
• However
– You have to decide the order
– There may be some additional unnamed tasks you
have to fill in
Something Different
• You have to learn how to NOT relying on the
coursemology output
– Instead relying on your own testing cases and
judgement
Given Files
• The Heap files:
– heap.h
– heap.hpp
• The driver program for your tests
– main.cpp
• Customer class, but you can ignore it for the
Heap task first
– customer.h
– customer.cpp
Part 1 Heap Implementation (Array)
Very First Task
• Create your own MSVC .sln or Xcode Project
Implementing Heap
• MaxHeap
– Parents > children
• You will implement the Heap with the array
representation
– It is NOT recommended to implement the heap by
pointer/tree/node representation
• The following functions are provided for you
– printHeapArray, printTree, _lookFor
Given Functions
• printHeapArray()
– print out the array that stores the heap
• printTree()
– print the heap in a graphical tree form… somehow
Given Functions
• The function
int Heap<T>::_lookFor(T x)
• It searches for the item x in the array and return
the index of x in the heap array
• In real practice, the index of x and x should be
stored in a symbol table/dictionary, thus, hash
table, for fast look-up of the index of x
– O(1) look-up time
• However, we just use a linear search here for our
assignment
– O(n) look-up time
Implementing Heap
• You have to implement and submit the following
functions:
– insert(x): Insert an item x into the heap
– extractMax(): extract the max. item from the heap
– decreaseKey(x,y): decrease the key of item x to y
– increaseKey (x,y): increase the key of item x to y
– deleteItem(x): remove the item x
– _bubbleUp(i): bubble up the item in index i
– _bubbleDown(i) : bubble down the item in index i
Implementing Heap
• You have to implement and submit the
following functions:
insert(x), extractMax(), decreaseKey(x,y), increaseKey
(x,y), deleteItem(x), _bubbleUp(i),_bubbleDown(i)
• What is the order of implementation?!
If You Implemented Correctly
If You Implemented Correctly
Second Part: Queueing Simulation
• Queueing theory is the mathematical study of
waiting lines, or queues. A queueing model is
constructed so that queue lengths and waiting
time can be predicted. Queueing theory is
generally considered a branch of operations
research because the results are often used
when making business decisions about the
resources needed to provide a service.
Queueing Theory
Model
• Customers
– Arrival time
– Processing time
• Time need to be served
• Queue
– Where customer wait, can be
prioritized
• Server
– Customers get served and
leave
Questions
• About waiting time
– Average WT
– Max WT
– Min WT
– or other WT
• For all customers
Single/Multiple Queue(s) with Multiple
Servers
What does the bank do?
Queue with “Priority”
Part 2: Queue Simulation
• First, the code customerTest() will generate 10
customers for you in customer.cpp
• And we assume that there is only ONE server
now
Customer Behavior
• All the customers will be stored in the array
custList[]
• To make it simple, the customer number is
equal to the time they arrived in minutes
– E.g. Customer 4 will arrive 4 min after the store
opens
• When the customer arrives, they will wait in
the waiting queue if the server is serving
another customer
Customer Behavior
• If the server is serving no one, next customer
in the queue will be served (dequeued)
• Each customer has a processing time (PT)
– The amount of time he will occupy the server
when he left the waiting queue
– The server will not server the next one in the
queue until he finish this current one
Waiting Time
• For each customer, his waiting time (WT) is
count as the difference between
– The time he arrives and the time he starts to be
served (dequeued)
– NOT the time he finished being served
Example (Normal Queue)
• Assume that the priority of the queue is FIFO
– Normal queue in real life
• Generate four customers (Done for you):
Time at the start of… Customer Server
0 C0 arrives Serves C0 at time 0
1 C1 arrives Serves C1 at time 1
2 C2 arrives Busy with C1
3 C3 arrives Busy with C1
4 Busy with C1
5 Serves C2 at time 5
6 Serves C3 at time 6
• Customer 2 waits for 5 – 2 = 3 min in the queue
• Customer 3 waits for 6 – 3 = 3 min in the queue
Output for FIFO
• Total WT = 6 min for all customers
• Average WT = 1.5 min for each customer
For 10 Customers (Setup)
Output for FIFO (10 Customers)
However
• If we change the queue priority
– It will not be First Come First Served
• Miraculously, there is a smart scanner that can
detect the processing time for the customer in
the queue
• The server will serve the customer with the
LEAST processing time among the people in
the queue FIRST
Output For Least PT (10 Customers)
Conclusion?
• What is the difference in the average waiting
time for two different policy of the priority of
the queue?
– FIFO vs Least PT
• Is it just coincident? Or is it always like that?
Difference
• FIFO
• Least PT first
Given Code
class Customer {
private:
int arrival_time;
// time of arrival after the shop opened in min
int processing_time;
// amount of time need to be processed with the customer
serivce in
min
public:
Customer () {arrival_time = 0; processing_time = 0;};
void setAT(int t) {arrival_time = t;};
void setPT(int t) {processing_time = t;};
int AT() {return arrival_time;};
int PT() {return processing_time;};
bool operator>(const Customer& c);
// a customer is "greater" if his time is shorter
};
Comparison For Heap/PQ
• If comparisonWay = 0
– the heap be ordered by arrival times (AT)
• If comparisonWay = 0
– the heap be ordered by processing times (PT)
int comparisonWay = 0; // 0 for arrival time, 1 for processing
time
bool Customer::operator>(const Customer& c) {
return comparisonWay ?
processing_time < c.processing_time :
arrival_time < c.arrival_time;
// a customer is "greater" if his time is shorter
};
Actually NOT a
good practice to
use a global
variable
First Part of CustomerQueueTest()
void customerQueueTest(int n_cust) {
int current_time = 0;
int totalWaitingTime = 0;
int i;
int WT = 0; // waiting time for each customer
Heap<Customer> queue;
Customer* custList = new Customer[n_cust];
cout << endl << endl << "Setup" << endl;
cout << "List of customers and their arrival and processing
times" << endl;
for (i = 0; i<n_cust; i++)
{
custList[i].setAT(i);
custList[i].setPT((n_cust - i) % (n_cust / 2) + 1 + (i %
2)*(n_cust /
2));
cout << "Customer " << i << " will arrive at time "
<< custList[i].AT() << " with PT=" << custList[i].PT() <<
endl;
}
cout << endl;
Setting up n
customers for the
test
Following on
for (int round = 0; round<2; round++) {
// you may need a big modification within this for-loop
cout << endl << endl;
cout << "Test Round " << round + 1 << endl;
cout << (round == 0 ? "First come first serve" : "Customer
with the least PT served first") << endl;
comparisonWay = round;
current_time = 0;
totalWaitingTime = 0;
queue.insert(custList[0]);
cout << "Customer arrives at time " << custList[0].AT() << "
with PT=" << custList[0].PT() << endl;
while (!queue.empty()) {
// you should change all of the code here inside
Customer c = queue.extractMax();
cout << "Customer arrives when no one is waiting" << endl;
cout << "Customer is served at time " << current_time << "
with AT=" << c.AT()
<< " and PT=" << c.PT() << " after waiting for “
<< WT << " min." << endl;
}
cout << "Total Waiting Time: " << totalWaitingTime << endl;
cout << "Average Waiting Time: " << totalWaitingTime /
(float)n_cust << endl;
You have to
change all the
code here!
The purpose for giving you the code here is
for all those “cout” such that it will match the
coursemology test case
Difference
• FIFO
• Least PT first
Real Job
• Treat the Queueing Simulation part of your
assignment as a real job
– A mini project
10 ways school is different than the
working world
• If you can't do the work, you're out.
• We grade on a curve.
• …
• We hate slackers.
• You have to fight for recognition.
• We really, really, really want you to be able to write
properly.
• We really, really, really want you to be able to do math.
• If you can't make money for us, we won't hire you.
https://www.cbsnews.com/news/10-ways-school-is-different-
than-the-world-of-work/
We really, really, really want you to be able to write
CODE properly
https://www.cbsnews.com/news/10-ways-school-is-different-
than-the-world-of-work/
https://www.cbsnews.com/news/10-ways-school-is-different-
than-the-world-of-work/
https://www.cbsnews.com/news/10-ways-school-is-different-
than-the-world-of-work/
https://www.cbsnews.com/news/10-ways-school-is-different-
than-the-world-of-work/
https://www.cbsnews.com/news/10-ways-school-is-different-
than-the-world-of-work/
https://www.cbsnews.com/news/10-ways-school-is-different-
than-the-world-of-work/
https://www.cbsnews.com/news/10-ways-school-is-different-
than-the-world-of-work/
https://www.cbsnews.com/news/10-ways-school-is-different-
than-the-world-of-work/
https://www.cbsnews.com/news/10-ways-school-is-different-
than-the-world-of-work/
https://www.cbsnews.com/news/10-ways-school-is-different-
than-the-world-of-work/
https://www.cbsnews.com/news/10-ways-school-is-different-
than-the-world-of-work/
https://www.cbsnews.com/news/10-ways-school-is-different-
than-the-world-of-work/
https://www.cbsnews.com/news/10-ways-school-is-different-
than-the-world-of-work/
https://www.cbsnews.com/news/10-ways-school-is-different-
than-the-world-of-work/
https://www.cbsnews.com/news/10-ways-school-is-different-
than-the-world-of-work/
https://www.cbsnews.com/news/10-ways-school-is-different-
than-the-world-of-work/
https://www.cbsnews.com/news/10-ways-school-is-different-
than-the-world-of-work/
https://www.cbsnews.com/news/10-ways-school-is-different-
than-the-world-of-work/
https://www.cbsnews.com/news/10-ways-school-is-different-
than-the-world-of-work/Heap and Queueing SimulationTwo BIG
PartsTime to Level UP!Something DifferentSomething
DifferentSomething DifferentGiven FilesPart 1 Heap
Implementation (Array)Very First TaskImplementing
HeapGiven FunctionsGiven FunctionsImplementing
HeapImplementing HeapIf You Implemented CorrectlyIf You
Implemented CorrectlySlide Number 17Second Part: Queueing
SimulationQueueing TheoryModelQuestionsSingle/Multiple
Queue(s) with Multiple ServersWhat does the bank do?Queue
with “Priority”Part 2: Queue SimulationCustomer
BehaviorCustomer BehaviorWaiting TimeExample (Normal
Queue)Slide Number 30Output for FIFOFor 10 Customers
(Setup)Output for FIFO (10 Customers)HoweverOutput For
Least PT (10 Customers)Conclusion?DifferenceGiven
CodeComparison For Heap/PQFirst Part of
CustomerQueueTest()Following onDifferenceReal Job10 ways
school is different than the working world
#include customer.h#include heap.h#include iostream.docx

More Related Content

Similar to #include customer.h#include heap.h#include iostream.docx

Router Queue Simulation in C++ in MMNN and MM1 conditions
Router Queue Simulation in C++ in MMNN and MM1 conditionsRouter Queue Simulation in C++ in MMNN and MM1 conditions
Router Queue Simulation in C++ in MMNN and MM1 conditionsMorteza Mahdilar
 
Project 5Programming and Algorithms IICSCI 211, Spring 2.docx
Project 5Programming and Algorithms IICSCI 211, Spring 2.docxProject 5Programming and Algorithms IICSCI 211, Spring 2.docx
Project 5Programming and Algorithms IICSCI 211, Spring 2.docxbriancrawford30935
 
#include iostream#includectimeusing namespace std;void.docx
#include iostream#includectimeusing namespace std;void.docx#include iostream#includectimeusing namespace std;void.docx
#include iostream#includectimeusing namespace std;void.docxmayank272369
 
C++ and OOPS Crash Course by ACM DBIT | Grejo Joby
C++ and OOPS Crash Course by ACM DBIT | Grejo JobyC++ and OOPS Crash Course by ACM DBIT | Grejo Joby
C++ and OOPS Crash Course by ACM DBIT | Grejo JobyGrejoJoby1
 
C++ Nested loops, matrix and fuctions.pdf
C++ Nested loops, matrix and fuctions.pdfC++ Nested loops, matrix and fuctions.pdf
C++ Nested loops, matrix and fuctions.pdfyamew16788
 
C++ Language -- Dynamic Memory -- There are 7 files in this project- a.pdf
C++ Language -- Dynamic Memory -- There are 7 files in this project- a.pdfC++ Language -- Dynamic Memory -- There are 7 files in this project- a.pdf
C++ Language -- Dynamic Memory -- There are 7 files in this project- a.pdfaassecuritysystem
 
2 BytesC++ course_2014_c3_ function basics&parameters and overloading
2 BytesC++ course_2014_c3_ function basics&parameters and overloading2 BytesC++ course_2014_c3_ function basics&parameters and overloading
2 BytesC++ course_2014_c3_ function basics&parameters and overloadingkinan keshkeh
 
Library functions in c++
Library functions in c++Library functions in c++
Library functions in c++Neeru Mittal
 
I need help to modify my code according to the instructions- Modify th.pdf
I need help to modify my code according to the instructions- Modify th.pdfI need help to modify my code according to the instructions- Modify th.pdf
I need help to modify my code according to the instructions- Modify th.pdfpnaran46
 
Object oriented programming system with C++
Object oriented programming system with C++Object oriented programming system with C++
Object oriented programming system with C++msharshitha03s
 
I have written the code but cannot complete the assignment please help.pdf
I have written the code but cannot complete the assignment please help.pdfI have written the code but cannot complete the assignment please help.pdf
I have written the code but cannot complete the assignment please help.pdfshreeaadithyaacellso
 
FP 201 - Unit 3 Part 2
FP 201 - Unit 3 Part 2FP 201 - Unit 3 Part 2
FP 201 - Unit 3 Part 2rohassanie
 

Similar to #include customer.h#include heap.h#include iostream.docx (20)

Router Queue Simulation in C++ in MMNN and MM1 conditions
Router Queue Simulation in C++ in MMNN and MM1 conditionsRouter Queue Simulation in C++ in MMNN and MM1 conditions
Router Queue Simulation in C++ in MMNN and MM1 conditions
 
CPP Homework Help
CPP Homework HelpCPP Homework Help
CPP Homework Help
 
C++ file
C++ fileC++ file
C++ file
 
C++ file
C++ fileC++ file
C++ file
 
Project 5Programming and Algorithms IICSCI 211, Spring 2.docx
Project 5Programming and Algorithms IICSCI 211, Spring 2.docxProject 5Programming and Algorithms IICSCI 211, Spring 2.docx
Project 5Programming and Algorithms IICSCI 211, Spring 2.docx
 
#include iostream#includectimeusing namespace std;void.docx
#include iostream#includectimeusing namespace std;void.docx#include iostream#includectimeusing namespace std;void.docx
#include iostream#includectimeusing namespace std;void.docx
 
C++ and OOPS Crash Course by ACM DBIT | Grejo Joby
C++ and OOPS Crash Course by ACM DBIT | Grejo JobyC++ and OOPS Crash Course by ACM DBIT | Grejo Joby
C++ and OOPS Crash Course by ACM DBIT | Grejo Joby
 
C++ Nested loops, matrix and fuctions.pdf
C++ Nested loops, matrix and fuctions.pdfC++ Nested loops, matrix and fuctions.pdf
C++ Nested loops, matrix and fuctions.pdf
 
C++ Language -- Dynamic Memory -- There are 7 files in this project- a.pdf
C++ Language -- Dynamic Memory -- There are 7 files in this project- a.pdfC++ Language -- Dynamic Memory -- There are 7 files in this project- a.pdf
C++ Language -- Dynamic Memory -- There are 7 files in this project- a.pdf
 
2 BytesC++ course_2014_c3_ function basics&parameters and overloading
2 BytesC++ course_2014_c3_ function basics&parameters and overloading2 BytesC++ course_2014_c3_ function basics&parameters and overloading
2 BytesC++ course_2014_c3_ function basics&parameters and overloading
 
Code optimization
Code optimization Code optimization
Code optimization
 
Code optimization
Code optimization Code optimization
Code optimization
 
CP 04.pptx
CP 04.pptxCP 04.pptx
CP 04.pptx
 
Library functions in c++
Library functions in c++Library functions in c++
Library functions in c++
 
Final DAA_prints.pdf
Final DAA_prints.pdfFinal DAA_prints.pdf
Final DAA_prints.pdf
 
7720
77207720
7720
 
I need help to modify my code according to the instructions- Modify th.pdf
I need help to modify my code according to the instructions- Modify th.pdfI need help to modify my code according to the instructions- Modify th.pdf
I need help to modify my code according to the instructions- Modify th.pdf
 
Object oriented programming system with C++
Object oriented programming system with C++Object oriented programming system with C++
Object oriented programming system with C++
 
I have written the code but cannot complete the assignment please help.pdf
I have written the code but cannot complete the assignment please help.pdfI have written the code but cannot complete the assignment please help.pdf
I have written the code but cannot complete the assignment please help.pdf
 
FP 201 - Unit 3 Part 2
FP 201 - Unit 3 Part 2FP 201 - Unit 3 Part 2
FP 201 - Unit 3 Part 2
 

More from AASTHA76

(APA 6th Edition Formatting and St.docx
(APA 6th Edition Formatting and St.docx(APA 6th Edition Formatting and St.docx
(APA 6th Edition Formatting and St.docxAASTHA76
 
(a) Thrasymachus’ (the sophist’s) definition of Justice or Right o.docx
(a) Thrasymachus’ (the sophist’s) definition of Justice or Right o.docx(a) Thrasymachus’ (the sophist’s) definition of Justice or Right o.docx
(a) Thrasymachus’ (the sophist’s) definition of Justice or Right o.docxAASTHA76
 
(Glossary of Telemedicine and eHealth)· Teleconsultation Cons.docx
(Glossary of Telemedicine and eHealth)· Teleconsultation Cons.docx(Glossary of Telemedicine and eHealth)· Teleconsultation Cons.docx
(Glossary of Telemedicine and eHealth)· Teleconsultation Cons.docxAASTHA76
 
(Assmt 1; Week 3 paper) Using ecree Doing the paper and s.docx
(Assmt 1; Week 3 paper)  Using ecree        Doing the paper and s.docx(Assmt 1; Week 3 paper)  Using ecree        Doing the paper and s.docx
(Assmt 1; Week 3 paper) Using ecree Doing the paper and s.docxAASTHA76
 
(Image retrieved at httpswww.google.comsearchhl=en&biw=122.docx
(Image retrieved at  httpswww.google.comsearchhl=en&biw=122.docx(Image retrieved at  httpswww.google.comsearchhl=en&biw=122.docx
(Image retrieved at httpswww.google.comsearchhl=en&biw=122.docxAASTHA76
 
(Dis) Placing Culture and Cultural Space Chapter 4.docx
(Dis) Placing Culture and Cultural Space Chapter 4.docx(Dis) Placing Culture and Cultural Space Chapter 4.docx
(Dis) Placing Culture and Cultural Space Chapter 4.docxAASTHA76
 
(1) Define the time value of money.  Do you believe that the ave.docx
(1) Define the time value of money.  Do you believe that the ave.docx(1) Define the time value of money.  Do you believe that the ave.docx
(1) Define the time value of money.  Do you believe that the ave.docxAASTHA76
 
(chapter taken from Learning Power)From Social Class and t.docx
(chapter taken from Learning Power)From Social Class and t.docx(chapter taken from Learning Power)From Social Class and t.docx
(chapter taken from Learning Power)From Social Class and t.docxAASTHA76
 
(Accessible at httpswww.hatchforgood.orgexplore102nonpro.docx
(Accessible at httpswww.hatchforgood.orgexplore102nonpro.docx(Accessible at httpswww.hatchforgood.orgexplore102nonpro.docx
(Accessible at httpswww.hatchforgood.orgexplore102nonpro.docxAASTHA76
 
(a) The current ratio of a company is 61 and its acid-test ratio .docx
(a) The current ratio of a company is 61 and its acid-test ratio .docx(a) The current ratio of a company is 61 and its acid-test ratio .docx
(a) The current ratio of a company is 61 and its acid-test ratio .docxAASTHA76
 
(1) How does quantum cryptography eliminate the problem of eaves.docx
(1) How does quantum cryptography eliminate the problem of eaves.docx(1) How does quantum cryptography eliminate the problem of eaves.docx
(1) How does quantum cryptography eliminate the problem of eaves.docxAASTHA76
 
#transformation10EventTrendsfor 201910 Event.docx
#transformation10EventTrendsfor 201910 Event.docx#transformation10EventTrendsfor 201910 Event.docx
#transformation10EventTrendsfor 201910 Event.docxAASTHA76
 
$10 now and $10 when complete Use resources from the required .docx
$10 now and $10 when complete Use resources from the required .docx$10 now and $10 when complete Use resources from the required .docx
$10 now and $10 when complete Use resources from the required .docxAASTHA76
 
#MicroXplorer Configuration settings - do not modifyFile.Versio.docx
#MicroXplorer Configuration settings - do not modifyFile.Versio.docx#MicroXplorer Configuration settings - do not modifyFile.Versio.docx
#MicroXplorer Configuration settings - do not modifyFile.Versio.docxAASTHA76
 
#include string.h#include stdlib.h#include systypes.h.docx
#include string.h#include stdlib.h#include systypes.h.docx#include string.h#include stdlib.h#include systypes.h.docx
#include string.h#include stdlib.h#include systypes.h.docxAASTHA76
 
$ stated in thousands)Net Assets, Controlling Interest.docx
$ stated in thousands)Net Assets, Controlling Interest.docx$ stated in thousands)Net Assets, Controlling Interest.docx
$ stated in thousands)Net Assets, Controlling Interest.docxAASTHA76
 
#include stdio.h#include stdlib.h#include pthread.h#in.docx
#include stdio.h#include stdlib.h#include pthread.h#in.docx#include stdio.h#include stdlib.h#include pthread.h#in.docx
#include stdio.h#include stdlib.h#include pthread.h#in.docxAASTHA76
 
#Assessment BriefDiploma of Business Eco.docx
#Assessment BriefDiploma of Business Eco.docx#Assessment BriefDiploma of Business Eco.docx
#Assessment BriefDiploma of Business Eco.docxAASTHA76
 
#include stdio.h#include stdint.h#include stdbool.h.docx
#include stdio.h#include stdint.h#include stdbool.h.docx#include stdio.h#include stdint.h#include stdbool.h.docx
#include stdio.h#include stdint.h#include stdbool.h.docxAASTHA76
 
#1) Identify 2020 National Health Goals related to home care d.docx
#1) Identify 2020 National Health Goals related to home care d.docx#1) Identify 2020 National Health Goals related to home care d.docx
#1) Identify 2020 National Health Goals related to home care d.docxAASTHA76
 

More from AASTHA76 (20)

(APA 6th Edition Formatting and St.docx
(APA 6th Edition Formatting and St.docx(APA 6th Edition Formatting and St.docx
(APA 6th Edition Formatting and St.docx
 
(a) Thrasymachus’ (the sophist’s) definition of Justice or Right o.docx
(a) Thrasymachus’ (the sophist’s) definition of Justice or Right o.docx(a) Thrasymachus’ (the sophist’s) definition of Justice or Right o.docx
(a) Thrasymachus’ (the sophist’s) definition of Justice or Right o.docx
 
(Glossary of Telemedicine and eHealth)· Teleconsultation Cons.docx
(Glossary of Telemedicine and eHealth)· Teleconsultation Cons.docx(Glossary of Telemedicine and eHealth)· Teleconsultation Cons.docx
(Glossary of Telemedicine and eHealth)· Teleconsultation Cons.docx
 
(Assmt 1; Week 3 paper) Using ecree Doing the paper and s.docx
(Assmt 1; Week 3 paper)  Using ecree        Doing the paper and s.docx(Assmt 1; Week 3 paper)  Using ecree        Doing the paper and s.docx
(Assmt 1; Week 3 paper) Using ecree Doing the paper and s.docx
 
(Image retrieved at httpswww.google.comsearchhl=en&biw=122.docx
(Image retrieved at  httpswww.google.comsearchhl=en&biw=122.docx(Image retrieved at  httpswww.google.comsearchhl=en&biw=122.docx
(Image retrieved at httpswww.google.comsearchhl=en&biw=122.docx
 
(Dis) Placing Culture and Cultural Space Chapter 4.docx
(Dis) Placing Culture and Cultural Space Chapter 4.docx(Dis) Placing Culture and Cultural Space Chapter 4.docx
(Dis) Placing Culture and Cultural Space Chapter 4.docx
 
(1) Define the time value of money.  Do you believe that the ave.docx
(1) Define the time value of money.  Do you believe that the ave.docx(1) Define the time value of money.  Do you believe that the ave.docx
(1) Define the time value of money.  Do you believe that the ave.docx
 
(chapter taken from Learning Power)From Social Class and t.docx
(chapter taken from Learning Power)From Social Class and t.docx(chapter taken from Learning Power)From Social Class and t.docx
(chapter taken from Learning Power)From Social Class and t.docx
 
(Accessible at httpswww.hatchforgood.orgexplore102nonpro.docx
(Accessible at httpswww.hatchforgood.orgexplore102nonpro.docx(Accessible at httpswww.hatchforgood.orgexplore102nonpro.docx
(Accessible at httpswww.hatchforgood.orgexplore102nonpro.docx
 
(a) The current ratio of a company is 61 and its acid-test ratio .docx
(a) The current ratio of a company is 61 and its acid-test ratio .docx(a) The current ratio of a company is 61 and its acid-test ratio .docx
(a) The current ratio of a company is 61 and its acid-test ratio .docx
 
(1) How does quantum cryptography eliminate the problem of eaves.docx
(1) How does quantum cryptography eliminate the problem of eaves.docx(1) How does quantum cryptography eliminate the problem of eaves.docx
(1) How does quantum cryptography eliminate the problem of eaves.docx
 
#transformation10EventTrendsfor 201910 Event.docx
#transformation10EventTrendsfor 201910 Event.docx#transformation10EventTrendsfor 201910 Event.docx
#transformation10EventTrendsfor 201910 Event.docx
 
$10 now and $10 when complete Use resources from the required .docx
$10 now and $10 when complete Use resources from the required .docx$10 now and $10 when complete Use resources from the required .docx
$10 now and $10 when complete Use resources from the required .docx
 
#MicroXplorer Configuration settings - do not modifyFile.Versio.docx
#MicroXplorer Configuration settings - do not modifyFile.Versio.docx#MicroXplorer Configuration settings - do not modifyFile.Versio.docx
#MicroXplorer Configuration settings - do not modifyFile.Versio.docx
 
#include string.h#include stdlib.h#include systypes.h.docx
#include string.h#include stdlib.h#include systypes.h.docx#include string.h#include stdlib.h#include systypes.h.docx
#include string.h#include stdlib.h#include systypes.h.docx
 
$ stated in thousands)Net Assets, Controlling Interest.docx
$ stated in thousands)Net Assets, Controlling Interest.docx$ stated in thousands)Net Assets, Controlling Interest.docx
$ stated in thousands)Net Assets, Controlling Interest.docx
 
#include stdio.h#include stdlib.h#include pthread.h#in.docx
#include stdio.h#include stdlib.h#include pthread.h#in.docx#include stdio.h#include stdlib.h#include pthread.h#in.docx
#include stdio.h#include stdlib.h#include pthread.h#in.docx
 
#Assessment BriefDiploma of Business Eco.docx
#Assessment BriefDiploma of Business Eco.docx#Assessment BriefDiploma of Business Eco.docx
#Assessment BriefDiploma of Business Eco.docx
 
#include stdio.h#include stdint.h#include stdbool.h.docx
#include stdio.h#include stdint.h#include stdbool.h.docx#include stdio.h#include stdint.h#include stdbool.h.docx
#include stdio.h#include stdint.h#include stdbool.h.docx
 
#1) Identify 2020 National Health Goals related to home care d.docx
#1) Identify 2020 National Health Goals related to home care d.docx#1) Identify 2020 National Health Goals related to home care d.docx
#1) Identify 2020 National Health Goals related to home care d.docx
 

Recently uploaded

Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991RKavithamani
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
PSYCHIATRIC History collection FORMAT.pptx
PSYCHIATRIC   History collection FORMAT.pptxPSYCHIATRIC   History collection FORMAT.pptx
PSYCHIATRIC History collection FORMAT.pptxPoojaSen20
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 

Recently uploaded (20)

Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
PSYCHIATRIC History collection FORMAT.pptx
PSYCHIATRIC   History collection FORMAT.pptxPSYCHIATRIC   History collection FORMAT.pptx
PSYCHIATRIC History collection FORMAT.pptx
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 

#include customer.h#include heap.h#include iostream.docx

  • 1. #include "customer.h" #include "heap.h" #include <iostream> using namespace std; int comparisonWay = 0; // 0 for arrival time, 1 for processing time bool Customer::operator>(const Customer& c) { return comparisonWay ? processing_time < c.processing_time : arrival_time < c.arrival_time; // a customer is "greater" if his time is shorter }; void customerQueueTest(int n_cust) { int current_time = 0; int totalWaitingTime = 0; int i;
  • 2. int WT = 0; // waiting time for each customer Heap<Customer> queue; Customer* custList = new Customer[n_cust]; cout << endl << endl << "Setup" << endl; cout << "List of customers and their arrival and processing times" << endl; for (i = 0; i<n_cust; i++) { custList[i].setAT(i); custList[i].setPT((n_cust - i) % (n_cust / 2) + 1 + (i % 2)*(n_cust / 2)); cout << "Customer " << i << " will arrive at time " << custList[i].AT() << " with PT=" << custList[i].PT() << endl; } cout << endl;
  • 3. for (int round = 0; round<2; round++) { // you may need a big modification within this for- loop cout << endl << endl; cout << "Test Round " << round + 1 << endl; cout << (round == 0 ? "First come first serve" : "Customer with the least PT served first") << endl; comparisonWay = round; current_time = 0; totalWaitingTime = 0; queue.insert(custList[0]); cout << "Customer arrives at time " << custList[0].AT() << " with PT=" << custList[0].PT() << endl; while (!queue.empty()) { // you should change all of the code here inside Customer c = queue.extractMax(); cout << "Customer arrives when no one is
  • 4. waiting" << endl; cout << "Customer is served at time " << current_time << " with AT=" << c.AT() << " and PT=" << c.PT() << " after waiting for " << WT << " min." << endl; } cout << "Total Waiting Time: " << totalWaitingTime << endl; cout << "Average Waiting Time: " << totalWaitingTime / (float)n_cust << endl; } delete[] custList; } #pragma once #include <math.h>
  • 5. #include <iostream> using namespace std; #ifndef HEAPHPP #define HEAPHPP template <class T> void Heap<T>::_bubbleUp(int index) { } template <class T> void Heap<T>::_bubbleDown(int index) { } template <class T> void Heap<T>::insert(T item) {
  • 6. } template <class T> T Heap<T>::extractMax() { return T(); } template <class T> void Heap<T>::printHeapArray() { for (int i = 0; i < _n; i++) cout << _heap[i] << " "; cout << endl; } template <class T> int Heap<T>::_lookFor(T x){ // not a very good implementation, but just use this for now.
  • 7. int i; for(i=0;i<_n;i++) if (_heap[i] == x) return i; return -1; } template <class T> void Heap<T>::decreaseKey(T from, T to) { } template <class T> void Heap<T>::increaseKey(T from, T to) {
  • 8. } template <class T> void Heap<T>::deleteItem(T x) { } template <class T> void Heap<T>::printTree() { int parity = 0; if (_n == 0) return; int space = pow(2,1 + (int) log2f(_n)),i; int nLevel = (int) log2f(_n)+1; int index = 0,endIndex; int tempIndex;
  • 9. for (int l = 0; l < nLevel; l++) { index = 1; parity = 0; for (i = 0; i < l; i++) index *= 2; endIndex = index * 2 - 1; index--; tempIndex = index; while (index < _n && index < endIndex) { for (i = 0; i < space-1; i++) cout << " "; if(index==0) cout << "|"; else if (parity) cout << ""; else
  • 10. cout << "/"; parity = !parity; for (i = 0; i < space; i++) cout << " "; index++; } cout << endl; index=tempIndex; while (index < _n && index < endIndex) { for (i = 0; i < (space-1-((int) log10(_heap[index]))); i++) cout << " "; cout << _heap[index]; for (i = 0; i < space; i++) cout << " "; index++; }
  • 11. cout << endl; space /= 2; } } #endif #include "heap.h" #include "customer.h" void heapTest();
  • 12. void hiddenHeapTest(); void customerQueueTest(); int main() { heapTest(); //customerQueueTest(10); } void heapTest(){ Heap<int> ih; cout << "Interger Heap Test" << endl; for (int i=1; i < 16; i++) { ih.insert(i); cout << "Insert " << i << " into the heap." << endl;
  • 13. cout << "Heap Array:"; ih.printHeapArray(); cout << endl; ih.printTree(); cout << endl << endl; } cout << "Increasing 13 to 99" << endl; ih.increaseKey(13,99); cout << "Heap Array:"; ih.printHeapArray(); cout << endl; ih.printTree(); cout << endl << endl; cout << "Deleting the item 2" << endl; ih.deleteItem(2);
  • 14. cout << "Heap Array:"; ih.printHeapArray(); cout << endl; ih.printTree(); cout << endl << endl; cout << "Deleting the item 10" << endl; ih.deleteItem(10); cout << "Heap Array:"; ih.printHeapArray(); cout << endl; ih.printTree(); cout << endl << endl; cout << "Decreasing the key 15 to 13)" << endl; ih.decreaseKey(15,13); cout << "Heap Array:"; ih.printHeapArray();
  • 15. cout << endl; ih.printTree(); cout << endl << endl; for (int i = 1; i < 12; i++) { cout << "Extract Max: Max = "; cout << ih.extractMax() << endl; ih.printTree(); cout << endl << endl; } } Heap and Queueing Simulation
  • 16. Two BIG Parts • Implementing Heap – Basic requirement • Perform a queueing simulation experiment with Priority Queue – Difficult – Treat it as a mini project Time to Level UP! Something Different • We will NOT give you the MSVC .sln or Xcode project – It’s time for you to create your own – Any problem, please refer to Lab 1 slides Something Different • We will tell you need to do – Namely, list of tasks
  • 17. • However – You have to decide the order – There may be some additional unnamed tasks you have to fill in Something Different • You have to learn how to NOT relying on the coursemology output – Instead relying on your own testing cases and judgement Given Files • The Heap files: – heap.h – heap.hpp • The driver program for your tests – main.cpp • Customer class, but you can ignore it for the Heap task first – customer.h – customer.cpp Part 1 Heap Implementation (Array)
  • 18. Very First Task • Create your own MSVC .sln or Xcode Project Implementing Heap • MaxHeap – Parents > children • You will implement the Heap with the array representation – It is NOT recommended to implement the heap by pointer/tree/node representation • The following functions are provided for you – printHeapArray, printTree, _lookFor Given Functions • printHeapArray() – print out the array that stores the heap • printTree() – print the heap in a graphical tree form… somehow
  • 19. Given Functions • The function int Heap<T>::_lookFor(T x) • It searches for the item x in the array and return the index of x in the heap array • In real practice, the index of x and x should be stored in a symbol table/dictionary, thus, hash table, for fast look-up of the index of x – O(1) look-up time • However, we just use a linear search here for our assignment – O(n) look-up time Implementing Heap • You have to implement and submit the following functions: – insert(x): Insert an item x into the heap – extractMax(): extract the max. item from the heap – decreaseKey(x,y): decrease the key of item x to y – increaseKey (x,y): increase the key of item x to y – deleteItem(x): remove the item x – _bubbleUp(i): bubble up the item in index i – _bubbleDown(i) : bubble down the item in index i Implementing Heap
  • 20. • You have to implement and submit the following functions: insert(x), extractMax(), decreaseKey(x,y), increaseKey (x,y), deleteItem(x), _bubbleUp(i),_bubbleDown(i) • What is the order of implementation?! If You Implemented Correctly If You Implemented Correctly Second Part: Queueing Simulation • Queueing theory is the mathematical study of waiting lines, or queues. A queueing model is constructed so that queue lengths and waiting time can be predicted. Queueing theory is generally considered a branch of operations research because the results are often used when making business decisions about the
  • 21. resources needed to provide a service. Queueing Theory Model • Customers – Arrival time – Processing time • Time need to be served • Queue – Where customer wait, can be prioritized • Server – Customers get served and leave Questions • About waiting time – Average WT – Max WT – Min WT
  • 22. – or other WT • For all customers Single/Multiple Queue(s) with Multiple Servers What does the bank do? Queue with “Priority” Part 2: Queue Simulation • First, the code customerTest() will generate 10 customers for you in customer.cpp • And we assume that there is only ONE server
  • 23. now Customer Behavior • All the customers will be stored in the array custList[] • To make it simple, the customer number is equal to the time they arrived in minutes – E.g. Customer 4 will arrive 4 min after the store opens • When the customer arrives, they will wait in the waiting queue if the server is serving another customer Customer Behavior • If the server is serving no one, next customer in the queue will be served (dequeued) • Each customer has a processing time (PT) – The amount of time he will occupy the server when he left the waiting queue – The server will not server the next one in the queue until he finish this current one
  • 24. Waiting Time • For each customer, his waiting time (WT) is count as the difference between – The time he arrives and the time he starts to be served (dequeued) – NOT the time he finished being served Example (Normal Queue) • Assume that the priority of the queue is FIFO – Normal queue in real life • Generate four customers (Done for you): Time at the start of… Customer Server 0 C0 arrives Serves C0 at time 0 1 C1 arrives Serves C1 at time 1 2 C2 arrives Busy with C1 3 C3 arrives Busy with C1 4 Busy with C1 5 Serves C2 at time 5
  • 25. 6 Serves C3 at time 6 • Customer 2 waits for 5 – 2 = 3 min in the queue • Customer 3 waits for 6 – 3 = 3 min in the queue Output for FIFO • Total WT = 6 min for all customers • Average WT = 1.5 min for each customer For 10 Customers (Setup) Output for FIFO (10 Customers) However • If we change the queue priority – It will not be First Come First Served • Miraculously, there is a smart scanner that can detect the processing time for the customer in the queue
  • 26. • The server will serve the customer with the LEAST processing time among the people in the queue FIRST Output For Least PT (10 Customers) Conclusion? • What is the difference in the average waiting time for two different policy of the priority of the queue? – FIFO vs Least PT • Is it just coincident? Or is it always like that? Difference • FIFO • Least PT first Given Code
  • 27. class Customer { private: int arrival_time; // time of arrival after the shop opened in min int processing_time; // amount of time need to be processed with the customer serivce in min public: Customer () {arrival_time = 0; processing_time = 0;}; void setAT(int t) {arrival_time = t;}; void setPT(int t) {processing_time = t;}; int AT() {return arrival_time;}; int PT() {return processing_time;}; bool operator>(const Customer& c); // a customer is "greater" if his time is shorter }; Comparison For Heap/PQ • If comparisonWay = 0 – the heap be ordered by arrival times (AT) • If comparisonWay = 0 – the heap be ordered by processing times (PT) int comparisonWay = 0; // 0 for arrival time, 1 for processing time bool Customer::operator>(const Customer& c) {
  • 28. return comparisonWay ? processing_time < c.processing_time : arrival_time < c.arrival_time; // a customer is "greater" if his time is shorter }; Actually NOT a good practice to use a global variable First Part of CustomerQueueTest() void customerQueueTest(int n_cust) { int current_time = 0; int totalWaitingTime = 0; int i; int WT = 0; // waiting time for each customer Heap<Customer> queue; Customer* custList = new Customer[n_cust]; cout << endl << endl << "Setup" << endl; cout << "List of customers and their arrival and processing times" << endl; for (i = 0; i<n_cust; i++) { custList[i].setAT(i); custList[i].setPT((n_cust - i) % (n_cust / 2) + 1 + (i % 2)*(n_cust / 2)); cout << "Customer " << i << " will arrive at time " << custList[i].AT() << " with PT=" << custList[i].PT() << endl; }
  • 29. cout << endl; Setting up n customers for the test Following on for (int round = 0; round<2; round++) { // you may need a big modification within this for-loop cout << endl << endl; cout << "Test Round " << round + 1 << endl; cout << (round == 0 ? "First come first serve" : "Customer with the least PT served first") << endl; comparisonWay = round; current_time = 0; totalWaitingTime = 0; queue.insert(custList[0]); cout << "Customer arrives at time " << custList[0].AT() << " with PT=" << custList[0].PT() << endl; while (!queue.empty()) { // you should change all of the code here inside Customer c = queue.extractMax(); cout << "Customer arrives when no one is waiting" << endl; cout << "Customer is served at time " << current_time << " with AT=" << c.AT() << " and PT=" << c.PT() << " after waiting for “ << WT << " min." << endl; } cout << "Total Waiting Time: " << totalWaitingTime << endl;
  • 30. cout << "Average Waiting Time: " << totalWaitingTime / (float)n_cust << endl; You have to change all the code here! The purpose for giving you the code here is for all those “cout” such that it will match the coursemology test case Difference • FIFO • Least PT first Real Job • Treat the Queueing Simulation part of your assignment as a real job – A mini project 10 ways school is different than the working world
  • 31. • If you can't do the work, you're out. • We grade on a curve. • … • We hate slackers. • You have to fight for recognition. • We really, really, really want you to be able to write properly. • We really, really, really want you to be able to do math. • If you can't make money for us, we won't hire you. https://www.cbsnews.com/news/10-ways-school-is-different- than-the-world-of-work/ We really, really, really want you to be able to write CODE properly https://www.cbsnews.com/news/10-ways-school-is-different- than-the-world-of-work/ https://www.cbsnews.com/news/10-ways-school-is-different- than-the-world-of-work/ https://www.cbsnews.com/news/10-ways-school-is-different- than-the-world-of-work/ https://www.cbsnews.com/news/10-ways-school-is-different- than-the-world-of-work/ https://www.cbsnews.com/news/10-ways-school-is-different- than-the-world-of-work/ https://www.cbsnews.com/news/10-ways-school-is-different- than-the-world-of-work/ https://www.cbsnews.com/news/10-ways-school-is-different- than-the-world-of-work/ https://www.cbsnews.com/news/10-ways-school-is-different- than-the-world-of-work/ https://www.cbsnews.com/news/10-ways-school-is-different- than-the-world-of-work/
  • 32. https://www.cbsnews.com/news/10-ways-school-is-different- than-the-world-of-work/ https://www.cbsnews.com/news/10-ways-school-is-different- than-the-world-of-work/ https://www.cbsnews.com/news/10-ways-school-is-different- than-the-world-of-work/ https://www.cbsnews.com/news/10-ways-school-is-different- than-the-world-of-work/ https://www.cbsnews.com/news/10-ways-school-is-different- than-the-world-of-work/ https://www.cbsnews.com/news/10-ways-school-is-different- than-the-world-of-work/ https://www.cbsnews.com/news/10-ways-school-is-different- than-the-world-of-work/ https://www.cbsnews.com/news/10-ways-school-is-different- than-the-world-of-work/ https://www.cbsnews.com/news/10-ways-school-is-different- than-the-world-of-work/ https://www.cbsnews.com/news/10-ways-school-is-different- than-the-world-of-work/Heap and Queueing SimulationTwo BIG PartsTime to Level UP!Something DifferentSomething DifferentSomething DifferentGiven FilesPart 1 Heap Implementation (Array)Very First TaskImplementing HeapGiven FunctionsGiven FunctionsImplementing HeapImplementing HeapIf You Implemented CorrectlyIf You Implemented CorrectlySlide Number 17Second Part: Queueing SimulationQueueing TheoryModelQuestionsSingle/Multiple Queue(s) with Multiple ServersWhat does the bank do?Queue with “Priority”Part 2: Queue SimulationCustomer BehaviorCustomer BehaviorWaiting TimeExample (Normal Queue)Slide Number 30Output for FIFOFor 10 Customers (Setup)Output for FIFO (10 Customers)HoweverOutput For Least PT (10 Customers)Conclusion?DifferenceGiven CodeComparison For Heap/PQFirst Part of CustomerQueueTest()Following onDifferenceReal Job10 ways school is different than the working world