int main() { int odds[8]; int player1[5], player2[5]; int position[8]={0,0,0,0,0,0,0,0}; int count; int winner; char more_race='Y'; //Player array, slot0=money total, slot1=horse bet on, slot2=bet amount, slot3=odds of bet //slot4=original cash level. srand(time(0)); title_screen(); get_cash(player1,1); get_cash(player2,2); do { for(count=0;count<8;count++) position[count]=0; winner=6000; generate_odds(odds,8); disp_odds(odds); bet(player1,1,odds); disp_odds(odds); bet(player2,2,odds); do { for(count=0;count<8;count++) { position[count]+=move_horse(odds, count); if(position[count]>=50) winner=count; } disp_race(position); } while(winner==6000); cout<<"\nThe winning horse is horse "<<winner+1<<endl; player1[0]+=payoff(winner, player1,1); player2[0]+=payoff(winner, player2,2); if((player1[0]<=0)||(player2[0]<=0)) more_race='n'; else { cout<<"\nWould you like another race? (Y/N)\n"; cin>>more_race; } } while((more_race=='Y')||(more_race=='y')); final_results(player1,player2); return 0; }
//////////////////////////////////////////////////////////////////////////////// // Simulation::run // // // // starts all simulations, iterates over all parameter combinations // //////////////////////////////////////////////////////////////////////////////// void Simulation::run() { int n_it = 0; do { n_it++; if(sim_par.get_partResults()) { cout << "\n\nIteration " << n_it << "\n " << sim_par << "\n" << endl; out << "\n\nIteration " << n_it << "\n " << sim_par << "\n" << endl; } if (log(log_type::setup)) log << "\n\nIteration " << n_it << "\n\t" << sim_par << "\n" << endl; /* #ifdef _SAVE_RATE_ADAPT rate_adapt_file_ch << "\n\nIteration " << n_it << "\n\t" << sim_par << "\n" << "Time ,term 1,term 2,path loss ," << "fading(R) ,fading(I)\n"; rate_adapt_file_ch.setf(ios::left); rate_adapt_file_rt << "\n\nIteration " << n_it << "\n\t" << sim_par << "\n" << "Time ,sender,target,data rate\n"; rate_adapt_file_rt.setf(ios::left); #endif */ main_sch.init(); randgent.seed(sim_par.get_Seed()); Standard::set_standard(sim_par.get_standard(),sim_par.get_bandwidth(),sim_par.get_shortGI()); if(sim_par.get_TxMode() > Standard::get_maxMCS()) throw (my_exception("MCS not supported by standard.")); channel_struct ch_par(sim_par.get_LossExponent(), sim_par.get_RefLoss(), sim_par.get_DopplerSpread(), sim_par.get_NumberSinus()); ch = new Channel(&main_sch, &randgent, ch_par, &log); init_terminals(); start_sim(); wrap_up(); delete ch; for (vector<Terminal*>::iterator it = term_vector.begin(); it != term_vector.end(); ++it) delete *it; term_vector.clear(); } while (sim_par.new_iteration()); final_results(); }
//This code assumes that "ranks" is a vector(to be passed in) where each element(i) is a ranked list of documents relevant to queryi //Order: Most relevant to least relevant void evaluator(std::vector < std::map<double,unsigned int> > ranks){ std::vector< std::set<int> > rel; //rel will be a vector of sets of ints that stores the relavence data given to us from users as feedback //rel[i][j] will be a document number relevant to query i std::string inFileName = "MED.REL"; std::ifstream inFile; inFile.open(inFileName.c_str()); //Open the file with the c-strig version of its fileneame if (inFile.fail()) //Make sure that the file opens { std::cerr << "Error - can't open " << inFileName << std::endl; exit(EXIT_FAILURE); } rel = relSet(inFile); //Setting up rel based on data from an external file std::vector< std::vector<double> > results(rel.size()); //results will hold precision scores for certain recall values //results[i][j] will be a precision score for query i when recall was (j+1)/10 std::vector<double> final_results(10); //final_results will hold the data that can be plotted in Excel to give a performance graph double judgement_at, recall_num, precision_num, precision_den, precision_score, recall_score; int document_num = 0, counter; for (unsigned int query = 0; query < rel.size(); query++){ //We end at query = 30 because there are 30 queries in our query set judgement_at = 0.1; //The first judgement will be taken at recall = 0.1 recall_num = 0; precision_den = 0; precision_num = 0; std::map<double,unsigned int>::iterator mapsIt; for (mapsIt = ranks[query].end(); mapsIt != ranks[query].begin(); mapsIt--){ //This for loop checks each document returned by the BM25 algorithm and sees if it is relevant document_num = mapsIt->second; if (rel[query].count(document_num) == 1){ //If the document is relevant, precision and recall increase recall_num++; precision_num++; precision_den++; } else{ //If not, precision decreases and recall stays the same precision_den++; } precision_score = precision_num/precision_den; recall_score = (recall_num)/(rel[query].size()); if (recall_score > judgement_at){ //We record our precision scores whenever recall passes some multiple of 0.1 results[query].push_back(precision_score); judgement_at += 0.1; } else if (judgement_at == 1) { break; //Once we have reached 100% precision we no longer need to keep going } else{} } } for(unsigned int j = 0; j < 10; j++){ counter = 0; for(unsigned int k = 0; k < results.size(); k++){ if (j < results[k].size()) { final_results[j] += results[k][j]; //For all of our queries we add up the precision scores for a certain recall score(if such ascore exists) counter++; } } final_results[j] /= counter; //We then divide by the number of times we updated final_results[j] to give us an average } //When we have done this for recall scores from 0.1 -> 1 we are done and we can output final_results to csv std::ofstream outFileAve; outFileAve.open("IRresultsAve.csv"); //This is the file to which we will write the average precision-recall results across all queries for(unsigned int i = 10; i < 100; i += 10){ //This for loop writes the recall values outFileAve << i << ','; } outFileAve << 100 << '\n'; for(unsigned int j = 0; j < final_results.size(); j++){ //This loop writes the precision values if (j == (final_results.size()-1)){ outFileAve << final_results[j]; } else{ outFileAve << final_results[j] << ','; } } outFileAve.close(); std::ofstream outFileGen; outFileGen.open("IRresultsGen.csv"); //This is the file to which we will write the precision-recall scores for each individual query for (unsigned int k = 0; k < results.size(); k++){ //This loop runs over all queries for(unsigned int i = 10; i < 100; i += 10){ //All other code is the same as above outFileGen << i << ','; } outFileGen << 100 << '\n'; for(unsigned int j = 0; j < results[k].size(); j++){ if (j == (results[k].size()-1)){ outFileGen << results[k][j] << std::endl; } else{ outFileGen << results[k][j] << ','; } } } outFileGen.close(); }