int main() { try { const string stageFilename = getFilename( stage_ ); const string riderFilename = getFilename( rider_ ); // // Setup the race data analyzer // RaceAnalyzer raceData( stageFilename, riderFilename ); bool done = false; // // Loop until the userwants to quite // while( ! done ) { // // Get a process the user's menu choice // switch( getChoice() ) { case menuDisplaySummary_ : displaySummary( raceData ); break; case menuDisplayRiders_ : displayRiderData( raceData ); break; case menuDisplayTeams_ : displayTeamData( raceData ); break; case menuQuit_ : done = true; break; default : assert(true); } } } catch(...) { system("pause"); return EXIT_FAILURE; } return EXIT_SUCCESS; }
int main(int argc, const char *argv[]) { Json::Value options; char usage[] = "Usage: main [jobNum] config1 [config2 ...]"; if (argc <= 1) { std::cerr << "Too few arguments" << std::endl; std::cerr << usage << std::endl; return 1; } else if ((std::string(argv[1]) == "-h") || (std::string(argv[1]) == "--help")) { std::cout << usage << std::endl; return 0; } unsigned int configStart = 1; int jobNum = -1; // try to interpret the first arg as a job number bool isJobNum = true; for (int i = 0; argv[1][i] != '\0'; i++) { if (!isdigit(argv[1][i])) { isJobNum = false; break; } } if (isJobNum) { jobNum = atoi(argv[1]); configStart++; } for (int i = configStart; i < argc; i++) { if (! readJson(argv[i],options)) { return 1; } } int numTrials = options.get("trials",1).asUInt(); int startTrial = 0; int origNumTrials = numTrials; unsigned int numTrialsPerJob = options.get("trialsPerJob",1).asUInt(); unsigned int maxNumStepsPerEpisode = options.get("maxNumStepsPerEpisode",10000).asUInt(); if (jobNum < 0) { jobNum = 0; } else { startTrial = jobNum * numTrialsPerJob; numTrials = min((int)numTrialsPerJob,numTrials-startTrial); } if (numTrials <= 0) { std::cerr << "ERROR: insufficient number of trials: " << numTrials << std::endl; std::cerr << "Calculated from: jobNum: " << jobNum << " numTrialsPerJob: " << numTrialsPerJob << " numTrials: " << origNumTrials << std::endl; std::cerr << "Start trial should be: " << startTrial << std::endl; return 1; } replaceOptsDir(options); if (jobNum == 0) saveConfig(options); replaceOptsJob(options,boost::lexical_cast<std::string>(jobNum)); unsigned int numEpisodes = options.get("numEpisodesPerTrial",1).asUInt(); bool displayDescriptionQ = options["verbosity"].get("description",true).asBool(); bool displaySummaryQ = options["verbosity"].get("summary",true).asBool(); bool displayObsQ = options["verbosity"].get("observation",true).asBool(); bool displayStepsPerEpisodeQ = options["verbosity"].get("stepsPerEpisode",true).asBool(); bool displayStepsPerTrialQ = options["verbosity"].get("stepsPerTrial",true).asBool(); std::string saveFilename = options["save"].get("results","").asString(); bool saveResultsQ = (saveFilename != ""); bool randomizeSeedQ = options.get("randomizeSeed",false).asBool(); // running for fixed lengths unsigned int numStepsPerEpisode = options.get("numStepsPerEpisode",0).asUInt(); bool runForFixedLength = (numStepsPerEpisode != 0); // get the output DT information unsigned int outputDTSteps = options["verbosity"].get("dtsteps",0).asUInt(); std::string outputDTFilename = options["verbosity"].get("dtfile","").asString(); bool outputDTCSVQ = (outputDTFilename != ""); boost::shared_ptr<OutputDT> outputDT; boost::shared_ptr<std::vector<Action::Type> > actions; Observation obs; double startTime = getTime(); std::vector<std::vector<unsigned int> > numSteps(numTrials,std::vector<unsigned int>(numEpisodes,0)); std::vector<std::vector<unsigned int> > numCaptures(numTrials,std::vector<unsigned int>(numEpisodes,0)); std::vector<std::vector<unsigned int> > *results = &numSteps; if (runForFixedLength) results = &numCaptures; std::cout << "Running for " << numTrials << " trials" << std::endl; unsigned int trialNum; unsigned int randomSeed; for (int trial = 0; trial < numTrials; trial++) { trialNum = trial + startTrial; if (randomizeSeedQ) randomSeed = getTime() * 1000000 + 1000 * getpid() + trialNum; // hopefully random enough else randomSeed = trialNum; //std::cout << "RANDOM SEED: " << randomSeed << std::endl; Json::Value trialOptions(options); replaceOptsTrial(trialOptions,trialNum); boost::shared_ptr<World> world = createWorldAgents(randomSeed,trialNum,trialOptions); boost::shared_ptr<const WorldModel> model = world->getModel(); std::cout << "Ad hoc agent ind: " << model->getAdhocInd() << std::endl; // INITIALIZATION if (trial == 0) { if (displayDescriptionQ) std::cout << world->generateDescription() << std::endl; if (outputDTCSVQ) { // set up the actions actions = boost::shared_ptr<std::vector<Action::Type> >(new std::vector<Action::Type>(model->getNumAgents())); // create models for the DT csv output if required std::vector<std::string> modelNames; //modelNames.push_back("GR"); //modelNames.push_back("TA"); //modelNames.push_back("GP"); //modelNames.push_back("PD"); outputDT = boost::shared_ptr<OutputDT>(new OutputDT(outputDTFilename,model->getDims(),model->getNumAgents()-1,modelNames,true,false,outputDTSteps)); } } if (outputDTCSVQ) { if (outputDT->hasCollectedSufficientData()) { std::cout << "WARNING: collected sufficient data, stopping with " << trial << " trials" << std::endl; numSteps.resize(trial); break; } } if (displayStepsPerTrialQ) std::cout << "trial " << std::setw(2) << trialNum << ": " << std::flush; for (unsigned int episode = 0; episode < numEpisodes; episode++) { world->randomizePositions(); world->restartAgents(); if (outputDTCSVQ) { // for the first step, add the observation, since it keeps a history of 1 world->generateObservation(obs); outputDT->saveStep(trial,numSteps[trial][episode],obs,*actions); } while (!model->isPreyCaptured()) { numSteps[trial][episode]++; // check end conditions if (runForFixedLength) { if (numSteps[trial][episode] > numStepsPerEpisode) break; } else { if (numSteps[trial][episode] > maxNumStepsPerEpisode) { std::cerr << "TRIAL " << trial << " EPISODE " << episode << " TOO LONG" << std::endl; break; } } if (displayObsQ) { world->generateObservation(obs); std::cout << obs << std::endl; } world->step(actions); if (outputDTCSVQ){ world->generateObservation(obs); // should follow world->step so that we can extract the observed actions of the previous step outputDT->saveStep(trial,numSteps[trial][episode],obs,*actions); } // if we want to run for a fixed length and the prey is captured, find a new position for the prey if (runForFixedLength && model->isPreyCaptured()) { //std::cout << "Prey is captured, generating new position" << std::endl; world->randomizePreyPosition(); numCaptures[trial][episode]++; } } // while the episode lasts if (displayObsQ) { world->generateObservation(obs); std::cout << obs << std::endl; } if (displayStepsPerEpisodeQ) std::cout << std::setw(3) << (*results)[trial][episode] << " " << std::flush; } if (displayStepsPerTrialQ) displayStepsPerTrial(displayStepsPerEpisodeQ,(*results)[trial]); } // end for trial double endTime = getTime(); // optionally display the summary if (displaySummaryQ) displaySummary(endTime-startTime,*results); // optionally save the results if (saveResultsQ) saveResults(saveFilename,startTrial,*results); // optionally finialize the saving of data for the DT if (outputDTCSVQ) outputDT->finalizeSave(randomSeed); return 0; }
int main(int argc, char* argv[]) { GJCType gjc; int initFlag, dataFlag, exitFlag=FALSE; char c[MAX_OPTION_INPUT+EXTRA_SPACES]; /* Initialise the Gloria Jean's Coffee system to a safe empty state. */ initFlag = systemInit(&gjc); /* Populate the Gloria Jean's Coffee system with data from the data files. */ /* Uncomment this line when you are ready to use command line arguments:*/ if(argv[1]==NULL||argv[2]==NULL){ printf("No argument found\n"); exit(EXIT_SUCCESS); } dataFlag = loadData(&gjc, argv[1], argv[2]); /* Testing to see if both systemInit(.) and loadData(.) are ok */ if (initFlag == FAILURE || dataFlag == FAILURE){ exit(EXIT_FAILURE); } /* Interactive menu providing user with access to the 9 menu options */ while(exitFlag==FALSE){ printf("Main Menu:\n"); printf("(1) Hot Drinks Summary\n"); printf("(2) Cold Drinks Summary\n"); printf("(3) Detailed Menu Report\n"); printf("(4) Add Menu Category\n"); printf("(5) Delete Menu Category\n"); printf("(6) Add Menu Item\n"); printf("(7) Delete Menu Item\n"); printf("(8) Save & Exit\n"); printf("(9) Abort\n"); printf("Select your option (1-9):"); fgets(c,MAX_OPTION_INPUT+EXTRA_SPACES,stdin); if(c[0]=='\n'){ printf("Invalid input\n"); }else if(stringIsInRange(c,MAX_OPTION_INPUT)==FALSE){ readRestOfLine(); printf("Invalid input\n"); }else{ stripNewLine(c); if(strcmp(c,"1")==0){ displaySummary(&gjc,HOT); }else if(strcmp(c,"2")==0){ displaySummary(&gjc,COLD); }else if(strcmp(c,"3")==0){ }else if(strcmp(c,"4")==0){ }else if(strcmp(c,"5")==0){ }else if(strcmp(c,"6")==0){ }else if(strcmp(c,"7")==0){ }else if(strcmp(c,"8")==0){ }else if(strcmp(c,"9")==0){ exitFlag=TRUE; } } } /* Deallocate all dynamically allocated memory. */ systemFree(&gjc); exit(EXIT_SUCCESS); }