// write out the output file void BidSet::writeOutput(Param &p, Distribution *d, int index) { char filename[strlen(p.filename) + 10]; const char* file_ext = strstr(p.filename, ".txt") ? "" : ".txt"; if(p.verbatim) sprintf(filename, "%s%s", p.filename, file_ext); else sprintf(filename,"%s%04d%s",p.filename,index, file_ext); ofstream outfile(filename); // comments long time_buf = time(NULL); char* time_str = ctime(&time_buf); outfile << "%% File generated by CATS v." << Param::CATS_VERSION_STRING << time_str << endl; outfile << "%% The CATS webpage is http://robotics.stanford.edu/CATS\n\n"; outfile << "%% PARAMETER SETTINGS:\n"; outfile << p.outputSettings(true) << endl; outfile << d->outputSettings(true) << endl << endl; // header outfile << "goods " << p.num_goods << "\nbids " << num_bids << "\ndummy " << num_dummy_items << "\n\n"; // bids for (int t=0; t<numBids(); t++) { // bid number outfile << t << "\t"; // prices if (p.integer_prices) outfile << (int)getBid(t)->amount << "\t"; else outfile << getBid(t)->amount << "\t"; // all the goods for (int tt=0;tt<getBid(t)->num_goods;tt++) outfile << getBid(t)->getGood(tt) << "\t"; outfile << "#\n"; } outfile.close(); if (p.output_parameter_settings) printf ("\nWrote CATS output file \"%s\".\n", filename); }