//This function responds to the user commands void Scheduler::Invoke(String binaryInput) { Tokenize(binaryInput); if(elevatorID==3) //special code for toggling userType (shortage of input pins) return; if(userType == "Operator") {Operator();return;} else {Passenger();return;} }
int main(int argc, const char * argv[]) { vector < Passenger > passengersA; vector < Passenger > passengersB; passengersB.push_back(Passenger("Saffron",200,50 ,Coordinate(20,15,12,"Delphi System"),"I travel very light")); passengersB.push_back(Passenger("Mrs. Reynolds",150,120 ,Coordinate(2,2,2,"Europa Colony"),"Just trying to get back my husband!")); passengersB.push_back(Passenger("Yolanda",500,100 ,Coordinate(20,15,12,"Delphi System"),"I am a courier of sensitive items")); passengersB.push_back(Passenger("Tracey Smith ",200,50 ,Coordinate(20,15,12,"Delphi System"),"Just a guy")); passengersA.push_back(Passenger("Magistrate Higgins ",600,120 ,Coordinate(2,2,2,"Europa Colony"),"I am very important person")); passengersA.push_back(Passenger("Stitch Hessian",100,100 ,Coordinate(100,72,32,"3rd moon of Persephone"),"Just get me there")); Coordinate earth(0,0,0,"Earth"); Coordinate europa(2,2,2,"Europa Colony"); vector< CargoBin > cargo; cargo.push_back(*new CargoBin(ACR.WARP,10)); cargo.push_back(*new CargoBin(ACR.ISOLC,10)); vector< SpaceThing > stations; stations.push_back( *new SpaceThing("Far Point Station",100,100,cargo,europa,passengersB) ); stations.push_back( *new SpaceThing("Mars Research Station",100,100,cargo,europa,passengersB) ); stations.push_back( *new SpaceThing("Earth Space Command Station",100,100,cargo,europa,passengersB) ); //=====================================everything above line is dummy data, replace with an object factory //SpaceFactory factory = SpaceFactory("/Users/Neil/Dropbox/webster/COSC4260/IAWSCA/SpaceFactory/"); //vector< SpaceThing > stations(randomStations(5)); //Dosn't work. Don't know why. Memory error in buy. Can't hunt it down. Brain is fried, out of time. Ship ship(interface,"HMS Out Of Time",1000,2000,cargo,earth,passengersA); bool close; string choices[] = {//TODO: map menu options to function pointers?? "TRADE CARGO", //1 "LOAD PASSENGERS", //2 "SET COURSE", //3 "DOCK", //4 "MANAGE CARGO", //5 "VIEW PASSENGERS", //6 }; interface.message("Welcome to your space ship",true); vector < string > mainMenu(begin_address(choices),end_address(choices)); while (!close) { ship.displayHUD(); int choice = interface.showMenu("\n\nMAIN MENU", mainMenu,"Please choose an action"); switch (choice){ case 1: ship.buy(); break; case 2: ship.loadPassengers(); break; case 3: ship.setNewCourse(); break; case 4: ship.dock(stations); //stations = randomStations(5); break; case 5: ship.manageInventory(); break; case 6: ship.viewPassengers(); break; case 7: close = interface.prompt("Are you sure you want to quit","Yes","No"); break; } } quit(); return 0; }
bool ElevatorSim::readPassengerCsv() { bool status = true; try { std::ifstream file(mPassengerFilePath); std::string line; while (std::getline(file, line)) { bool lineStatus = true; int startTime = 0; FloorNumber startFloor = 0; FloorNumber endFloor = 0; // get the tokens std::stringstream lineStream(line); std::string cell; try { if (std::getline(lineStream, cell, ',')) { startTime = std::stoi(cell, nullptr); } else { lineStatus = false; } if (std::getline(lineStream, cell, ',')) { startFloor = std::stoi(cell, nullptr); } else { lineStatus = false; } if (std::getline(lineStream, cell, ',')) { endFloor = std::stoi(cell, nullptr); } else { lineStatus = false; } } catch (const std::invalid_argument& e) { lineStatus = false; } if (lineStatus) { // error handling invalid input out of scope assert(startTime >= 0); Direction dir = (endFloor - startFloor) > 0 ? Direction::UP : Direction::DOWN; PassengerStart newPassenger = std::make_pair(Passenger(dir, endFloor), startFloor); mPassengerList.emplace(startTime, newPassenger); } } mPassengersStart = mPassengerList.size(); } catch (...) { std::cerr << "Failed to read csv file: " << mPassengerFilePath << std::endl; status = false; } return status; }
void runlogic() { NSDL2_RUNLOGIC(NULL, NULL, "Executing init_script()"); init_script(); NSDL2_RUNLOGIC(NULL, NULL, "Executing sequence block - Parent"); { NSDL2_RUNLOGIC(NULL, NULL, "Executing dowhile block - DoWhileBlock. NS Variable = var_dowhile"); { NSDL2_RUNLOGIC(NULL, NULL, "NS Variable value for block - DoWhileBlock = %d", ns_get_int_val("var_dowhile")); do { NSDL2_RUNLOGIC(NULL, NULL, "Executing sequence block - Seq1"); { NSDL2_RUNLOGIC(NULL, NULL, "Executing weight block - Weight"); { //int Weightweight = ns_get_random_number_int(1, 100); int Weightweight = ns_get_random_number_int(1, weight); NSDL2_RUNLOGIC(NULL, NULL, "Percentage random number for block - Weight = %d", Weightweight); //if(Weightweight <= 100) if(Weightweight <= weight) { NSDL2_RUNLOGIC(NULL, NULL, "Executing percent block - Percentage (wt value = 100)"); { //int Percentagepercent = ns_get_random_number_int(1, 100); int Percentagepercent = ns_get_random_number_int(1, per1+per2); NSDL2_RUNLOGIC(NULL, NULL, "Percentage random number for block - Percentage = %d", Percentagepercent); //if(Percentagepercent <= 50) if(Percentagepercent <= per1) { NSDL2_RUNLOGIC(NULL, NULL, "Executing flow - LoginLogout (pct value = 50%)"); LoginLogout(); } //else if(Percentagepercent <= 100) else if(Percentagepercent <= per1+per2) { NSDL2_RUNLOGIC(NULL, NULL, "Executing count block - Count. Min = 1, Max = 1 (pct value = 50%)"); { //int CountCount = ns_get_random_number_int(1, 1); int CountCount = ns_get_random_number_int(min, max); int CountLoop; for(CountLoop = 1; CountLoop <= CountCount; CountLoop++) { NSDL2_RUNLOGIC(NULL, NULL, "Executing while block - while. NS Variable = var_while (pct value = 50%), SelectedCount = %d, Iteration = %d",CountCount, CountLoop); { NSDL2_RUNLOGIC(NULL, NULL, "NS Variable value for block - while = %d", ns_get_int_val("var_while")); while(ns_get_int_val("var_while")) { NSDL2_RUNLOGIC(NULL, NULL, "Executing sequence block - SeqW (pct value = 50%), SelectedCount = %d, Iteration = %d",CountCount, CountLoop); { NSDL2_RUNLOGIC(NULL, NULL, "Executing switch block - Switch. NS Variable = var_switch (pct value = 50%), SelectedCount = %d, Iteration = %d",CountCount, CountLoop); { NSDL2_RUNLOGIC(NULL, NULL, "NS Variable value for block - Switch = %d", ns_get_int_val("var_switch")); switch(ns_get_int_val("var_switch")) { case 0: NSDL2_RUNLOGIC(NULL, NULL, "Executing sequence block - Seq2 (case value = 0), SelectedCount = %d, Iteration = %d",CountCount, CountLoop); { NSDL2_RUNLOGIC(NULL, NULL, "Executing flow - Passenger"); Passenger(); NSDL2_RUNLOGIC(NULL, NULL, "Executing flow - FlowSwitch"); FlowSwitch(); } break; case 1: NSDL2_RUNLOGIC(NULL, NULL, "Executing sequence block - Seq3 (case value = 1)"); { NSDL2_RUNLOGIC(NULL, NULL, "Executing flow - Reservation"); Reservation(); NSDL2_RUNLOGIC(NULL, NULL, "Executing flow - FlowSwitch"); FlowSwitch(); } break; case 2: NSDL2_RUNLOGIC(NULL, NULL, "Executing sequence block - Seq4 (case value = 2)"); { NSDL2_RUNLOGIC(NULL, NULL, "Executing flow - LoginLogout"); LoginLogout(); NSDL2_RUNLOGIC(NULL, NULL, "Executing flow - FlowSwitch"); FlowSwitch(); } break; default: NSDL2_RUNLOGIC(NULL, NULL, "Executing sequence block - Seq5 (case value = -1)"); { NSDL2_RUNLOGIC(NULL, NULL, "Executing flow - Tours"); Tours(); NSDL2_RUNLOGIC(NULL, NULL, "Executing flow - FlowSwitch"); FlowSwitch(); } break; } } NSDL2_RUNLOGIC(NULL, NULL, "Executing flow - FlowWhile"); FlowWhile(); } } } } } } } } } NSDL2_RUNLOGIC(NULL, NULL, "Executing flow - FlowDoWhile"); FlowDoWhile(); } } while(ns_get_int_val("var_dowhile")); } } NSDL2_RUNLOGIC(NULL, NULL, "Executing ns_exit_session()"); ns_exit_session(); }