Last active
December 16, 2015 12:49
-
-
Save shade34321/5437603 to your computer and use it in GitHub Desktop.
Restaurant Simulator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// compareParty.cpp | |
// ResSim | |
// | |
// Created by Shade Alabsa on 4/20/13. | |
// Copyright (c) 2013 Shade Alabsa. All rights reserved. | |
// | |
#include "compareParty.h" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// main.cpp | |
// ResSim | |
// | |
// Created by Shade Alabsa on 4/10/13. | |
// Copyright (c) 2013 Shade Alabsa. All rights reserved. | |
// | |
#include <iostream> | |
#include "menu.h" | |
#include "restaurant.h" | |
int main(int argc, const char * argv[]) | |
{ | |
menu m; | |
return 0; | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "cook.h" | |
/** | |
To figure out the cook time. It takes a random time based off of how busy they are. If they aren't very busy, 1, then they should be able to output orders in the alloted time. | |
As they get busier the cooks take longer to cook the food. | |
**/ | |
int cook::cookTime(int level, int avg){ | |
int t; | |
class random r; | |
switch(level){ | |
case 1: | |
t = r(avg); | |
break; | |
case 2: | |
t = r(10) + avg; | |
break; | |
case 3: | |
t = r(20) + avg; | |
default: | |
t = r(35) + avg; | |
} | |
return t; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef cook_h | |
#define cook_h | |
#include <iostream> | |
#include "random.h" | |
class cook{ | |
public: | |
int cookTime(int, int); | |
}; | |
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Ld /Users/shade/Library/Developer/Xcode/DerivedData/ResSim-fvkhqxhiupiizxgffxqgoxgolsmv/Build/Products/Debug/ResSim normal x86_64 | |
cd /Users/shade/Dropbox/School/Gwinnett_Tech/CIST_2362/final/ResSim | |
setenv MACOSX_DEPLOYMENT_TARGET 10.8 | |
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -arch x86_64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk -L/Users/shade/Library/Developer/Xcode/DerivedData/ResSim-fvkhqxhiupiizxgffxqgoxgolsmv/Build/Products/Debug -F/Users/shade/Library/Developer/Xcode/DerivedData/ResSim-fvkhqxhiupiizxgffxqgoxgolsmv/Build/Products/Debug -filelist /Users/shade/Library/Developer/Xcode/DerivedData/ResSim-fvkhqxhiupiizxgffxqgoxgolsmv/Build/Intermediates/ResSim.build/Debug/ResSim.build/Objects-normal/x86_64/ResSim.LinkFileList -mmacosx-version-min=10.8 -stdlib=libstdc++ -o /Users/shade/Library/Developer/Xcode/DerivedData/ResSim-fvkhqxhiupiizxgffxqgoxgolsmv/Build/Products/Debug/ResSim | |
Undefined symbols for architecture x86_64: | |
"party::getArrival()", referenced from: | |
restaurant::startSim() in restaurant.o | |
ld: symbol(s) not found for architecture x86_64 | |
clang: error: linker command failed with exit code 1 (use -v to see invocation) | |
"party::getArrival()", referenced from: | |
Restaurant::startSim() in restaurant.o | |
Symbol(s) not found for architecture x86_64 | |
Linker command failed with exit code 1 (use -v to see invocation) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "file.h" | |
file::file(std::string fn){ | |
file::filename = fn; | |
} | |
void file::open(){ | |
output.open(file::filename.c_str(), std::ios::app); | |
} | |
void file::close(){ | |
output.close(); | |
} | |
/** | |
To output data to a file | |
**/ | |
void file::writeToFile(std::string message){ | |
file::open(); | |
output << message; | |
file::close(); | |
} | |
/** | |
To output lines to a log file | |
**/ | |
void file::writeLog(std::string message){ | |
file::open(); | |
std::string time = currentTime(); | |
output << time << " " << message << "\n"; | |
file::close(); | |
} | |
/** | |
Gets current date and time so we can have a time stamp for our logs | |
Outputs in the following format | |
YYYY-MM-DD.HH:MM:SS:MS | |
**/ | |
const std::string file::currentTime(){ | |
time_t now = time(0); | |
struct tm tstruct; | |
char buf[80]; | |
tstruct = *localtime(&now); | |
strftime(buf,sizeof(buf), "%Y-%m-%d.%X", &tstruct); | |
return buf; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
So I have a standardized way of opening and closing files. Don't have to worry about if a file is open or closed. Or messing with to many fstream objects | |
**/ | |
#ifndef file_h | |
#define file_h | |
#include <fstream> | |
#include <iostream> | |
#include <string> | |
#include <time.h> | |
class file{ | |
private: | |
std::string filename; | |
std::fstream output; | |
void close(); | |
void open(); | |
const std::string currentTime(); | |
public: | |
file(std::string); | |
void writeToFile(std::string); | |
void writeLog(std::string); | |
}; | |
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
IHOP | |
3 | |
40 | |
4 | |
1 | |
12 | |
5 | |
1 | |
2 | |
3 | |
4 | |
5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// main.cpp | |
// ResSim | |
// | |
// Created by Shade Alabsa on 4/10/13. | |
// Copyright (c) 2013 Shade Alabsa. All rights reserved. | |
// | |
#include <iostream> | |
#include "menu.h" | |
#include "restaurant.h" | |
int main(int argc, const char * argv[]) | |
{ | |
menu m; | |
return 0; | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "party.h" | |
party::party(){} | |
party::party(int numPeople, int a){ | |
people = numPeople; | |
arrival = a; | |
} | |
int party::getPeople(){ | |
return people; | |
} | |
void party::setPeople(int p){ | |
people = p; | |
} | |
bool party::isWaiting(){ | |
return waiting; | |
} | |
void party::setWaiting(bool w){ | |
waiting = w; | |
} | |
void party::setWaitTime(int t){ | |
waitTime = t; | |
} | |
int party::getwaitTime(){ | |
return waitTime; | |
} | |
void party::setArrival(int a){ | |
arrival =a; | |
} | |
int party::getTotalTime(int current){ | |
return (current-arrival); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef party_h | |
#define party_h | |
#include <iostream> | |
class party{ | |
private: | |
int people; | |
int waitTime; | |
bool waiting; | |
int arrival; | |
public: | |
party(); | |
party(int, int); | |
int getPeople(); | |
void setPeople(int); | |
bool isWaiting(); | |
void setWaiting(bool); | |
void setWaitTime(int); | |
int getwaitTime(); | |
void setArrival(int); | |
int getArrival(); | |
int getTotalTime(int); | |
void decrement(); | |
}; | |
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "random.h" | |
random::random(){ | |
srand((unsigned)time(0)); | |
} | |
unsigned int random::operator()(int m){ | |
unsigned int randNumber = rand(); | |
return randNumber % m; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef random_h | |
#define random_h | |
#include <iostream> | |
#include <stdlib.h> | |
#include <time.h> | |
class random{ | |
public: | |
random(); | |
unsigned int operator()(int); | |
}; | |
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "restaurant.h" | |
restaurant::restaurant(std::string n, int l, int numTables, int s, int hours, int t, int act, int NumServers, std::vector<int> skillLevel){ | |
name = n; | |
level = l; | |
seats = s; | |
totalTime = hours*60; //total minutes we have | |
type = t; | |
avgCookTime = act; | |
for(int i = 0;i<numTables;i++){ //sets up the dining room with tables | |
table t (seats); | |
diningRoom.push_back(t); | |
} | |
int d; | |
if(numTables % NumServers == 0){ //if the tables are equally divisible by the number of servers | |
d = numTables / NumServers; //all servers get the same amount of tables | |
for(int i = 0;i<NumServers;i++){ | |
server s (skillLevel.at(i), d); | |
waitStaff.push_back(s); | |
} | |
} | |
else{ | |
d = numTables / NumServers; | |
int j = numTables % NumServers; //how many left over tables do we have that can't be evenly divided up | |
int i =0; | |
while(j>0){ | |
server s(skillLevel.at(i), (d+1)); //otherwise the first set get an extra table | |
waitStaff.push_back(s); | |
i++; | |
j--; | |
} | |
for(i;i<NumServers;i++){ | |
server s(skillLevel.at(i),d); | |
waitStaff.push_back(s); | |
} | |
} | |
} | |
const std::string restaurant::currentTime(){ | |
time_t now = time(0); | |
struct tm tstruct; | |
char buf[80]; | |
tstruct = *localtime(&now); | |
strftime(buf,sizeof(buf), "%Y-%m-%d", &tstruct); | |
return buf; | |
} | |
void restaurant::startSim(){ | |
file log((name + "_" + currentTime() + ".log").c_str()); | |
file sim((name + "_" + currentTime() + ".sim").c_str()); | |
log.writeLog("Starting simulation"); | |
sim.writeToFile("Starting simulation"); | |
std::cout << "Starting Simulation:" << std::endl; | |
sim.writeToFile("Input parameters"); | |
std::cout << "Input parameters" << std::endl; | |
sim.writeToFile("Name: " + std::string(name)); | |
oss << "Level of Business: " << level; | |
sim.writeToFile(oss.str()); | |
oss << "Number of tables: " << diningRoom.size(); | |
sim.writeToFile(oss.str()); | |
oss << "Seats per table: " << seats; | |
sim.writeToFile(oss.str()); | |
oss << "Length of the Simulation: " << (totalTime/60); | |
sim.writeToFile(oss.str()); | |
switch(type){ | |
case 1: | |
sim.writeToFile("Type of Restaurant: Casual"); | |
break; | |
case 2: | |
sim.writeToFile("Type of Restaurant: Bistro"); | |
break; | |
case 3: | |
sim.writeToFile("Type of Restaurant: Gourmet"); | |
break; | |
default: | |
sim.writeToFile("Type of Restaurant: Fine Dining"); | |
break; | |
} | |
oss << "Recomended average cook time: " << avgCookTime; | |
sim.writeToFile(oss.str()); | |
sim.writeToFile("Wait Staff:"); | |
for(int i =0;i<waitStaff.size();i++){ | |
oss << "Server " << (i+1) << " with skill level of " << waitStaff.at(i).getSkill(); | |
sim.writeToFile(oss.str()); | |
} | |
std::cout << "Name: " << name << std::endl; | |
std::cout << "Level of Business: " << level << std::endl; | |
std::cout << "Number of tables: " << diningRoom.size() << std::endl; | |
std::cout << "Seats per table: " << seats << std::endl; | |
std::cout << "Length of the Simulation: " << (totalTime/60) << std::endl; | |
switch(type){ | |
case 1: | |
std::cout << "Type of Restaurant: Casual" << std::endl; | |
break; | |
case 2: | |
std::cout << "Type of Restaurant: Bistro" << std::endl; | |
break; | |
case 3: | |
std::cout << "Type of Restaurant: Gourmet" << std::endl; | |
break; | |
default: | |
std::cout << "Type of Restaurant: Fine Dining" << std::endl; | |
break; | |
} | |
std::cout << "Recomended average cook time: " << avgCookTime << std::endl; | |
std::cout << "Wait Staff:" << std::endl; | |
for(int i =0;i<waitStaff.size();i++){ | |
std:: cout << "Server " << (i+1) << " with skill level of " << waitStaff.at(i).getSkill() << std::endl; | |
} | |
int currentTime; | |
class random randGen; | |
for(currentTime =0;currentTime<totalTime;currentTime++){ | |
if(randGen(4) <= level){ | |
int numGuests = randGen(seats); | |
guests+=numGuests; | |
parties++; | |
party p(numGuests,currentTime); | |
waitingList.push(p); | |
} | |
if(!waitingOnFood.empty()){ | |
} | |
if(!takingOrder.empty()){ | |
} | |
if(!waitingForServer.empty()){ | |
for(int i =0;i<waitStaff.size();i++){ | |
if(!(waitStaff.at(i).isBusy())){ | |
if(waitStaff.at(i).canHandleAnother()){ | |
waitingForServer.front().setServer(waitStaff.at(i)); | |
waitingForServer.front().getParty().setWaitTime((waitStaff.at(i).orderTime(waitingForServer.front().getParty().getPeople())) + currentTime); | |
takingOrder.push(waitingForServer.front()); | |
waitingForServer.pop(); | |
} | |
} | |
} | |
} | |
if(!waitingList.empty()){ | |
for(int i = 0;i<diningRoom.size();i++){ | |
if((diningRoom.at(i)).isEmpty()){ | |
diningRoom.at(i).setParty(waitingList.front()); | |
waitingForServer.push(diningRoom.at(i)); | |
totalWait += (currentTime - waitingList.front().getArrival()); | |
waitingList.pop(); | |
} | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef restaurant_h | |
#define restaurant_h | |
#include <iostream> | |
#include <vector> | |
#include <list> | |
#include <queue> | |
#include <string> | |
#include <sstream> | |
#include "server.h" | |
#include "table.h" | |
#include "party.h" | |
#include "cook.h" | |
#include "random.h" | |
#include "file.h" | |
#include "compareParty.h" | |
class restaurant{ | |
private: | |
std::queue<party> waitingList; | |
std::queue<table> waitingForServer; | |
std::priority_queue<table, std::vector<table>, compareParty> takingOrder; | |
std::priority_queue<table, std::vector<table>, compareParty> waitingOnFood; | |
std::priority_queue<table, std::vector<table>, compareParty> eating; | |
int guests; //how many guest total we had | |
int parties; //how many parties we had | |
int totalWait; //total wait a party waited on a table for | |
int cookTime; //total wait a party waited on food for | |
int turnAround; //how long it took to take a customer in and get them out | |
std::string name; | |
int level, totalTime, type, avgCookTime, seats; | |
std::vector<table> diningRoom; | |
std::vector<server> waitStaff; | |
std::ostringstream oss; | |
protected: | |
public: | |
restaurant(std::string, int, int, int, int, int, int, int, std::vector<int>); | |
void startSim(); | |
const std::string currentTime(); | |
}; | |
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "server.h" | |
server::server(){ | |
} | |
server::server(int s, int n){ | |
skill = s; | |
numTables = n; | |
current = 0; | |
} | |
int server::orderTime(int p){ | |
int t; | |
switch (skill){ //we account for taking the physical orders and entering them into the computer here. The time it takes to take an order and the time it takes to enter it is roughly the same for servers | |
case 1: | |
t = 4*p; | |
break; | |
case 2: | |
t = 6*p; | |
break; | |
case 3: | |
t = 8*p; | |
break; | |
case 4: | |
t = 10*p; | |
break; | |
default: | |
t = 12*p; | |
break; | |
} | |
return t; | |
} | |
bool server::canHandleAnother(){ | |
return (current<numTables); | |
} | |
bool server::isBusy(){ | |
return busy; | |
} | |
int server::getSkill(){ | |
return skill; | |
} | |
void server::decrement(){ | |
current--; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef server_h | |
#define server_h | |
#include <iostream> | |
#include <vector> | |
class server{ | |
private: | |
int skill; | |
int numTables; | |
int current; | |
bool busy; | |
public: | |
server(); | |
server(int, int); | |
int orderTime(int); | |
bool canHandleAnother(); | |
bool isBusy(); | |
int getSkill(); | |
void decrement(); | |
}; | |
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "table.h" | |
table::table(){} | |
table::table(int seats){ | |
seats = seats; | |
empty = true; | |
} | |
bool table::isEmpty(){ | |
return empty; | |
} | |
void table::setEmpty(){ | |
empty = true; | |
} | |
void table::setServer(server serv){ | |
s = serv; | |
} | |
server table::getServer(){ | |
return s; | |
} | |
int table::getSeats(){ | |
return seats; | |
} | |
void table::setParty(party guests){ | |
p = guests; | |
empty = false; | |
} | |
party table::getParty(){ | |
return p; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef table_h | |
#define table_h | |
#include <iostream> | |
#include "party.h" | |
#include "server.h" | |
class table{ | |
private: | |
int seats; | |
party p; | |
server s; | |
bool empty; | |
protected: | |
public: | |
table(); | |
table(int); | |
bool isEmpty(); | |
void setServer(server); | |
server getServer(); | |
void setParty(party); | |
party getParty(); | |
int getSeats(); | |
void setEmpty(); | |
}; | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment