int main() { run_one(); run_two(); return 0; }
void scaling_by_n( std::string prefix, size_t dim, bool is_periodic, Search_Factory::Search_Type search_type, bool do_spoke = true, bool do_favored = false, bool do_two = false, const double cutoff_t = 2., const size_t min_iter = 1, const size_t cutoff_n = 0, bool do_bridson = false) { // vary r, collect timings for each algorithm // Do at least min_iter runs of MPS (set to 0 if no requirements) // Continue to do iterations until the time it takes is greater than cutoff_t (set to 0 if no requirements) // " " " number of samples produced is greater than cutoff_n (set to 0 if no requirements) // // Iterations will stop only when *all three* conditions are met Timing_Stats run_time; run_time.start_clock(); // get file names std::stringstream file0ss, file1ss, file2ss, file3ss; // junk filenames in order to not overwrite any interesting data if (!do_spoke) file0ss << "00empty_"; if (!do_favored) file1ss << "00empty_"; if (!do_two) file2ss << "00empty_"; if (!do_bridson) file3ss << "00empty_"; file0ss << prefix << dim; file1ss << prefix << dim; file2ss << prefix << dim; file3ss << prefix << dim; if (is_periodic) { file0ss << "_P_"; file1ss << "_P_"; file2ss << "_P_"; file3ss << "_P_"; } else { file0ss << "_n_"; file1ss << "_n_"; file2ss << "_n_"; file3ss << "_n_"; } std::string search_s; switch (search_type) { case Search_Factory::ARRAY: search_s = "a"; break; case Search_Factory::GRID: search_s = "g"; break; case Search_Factory::RANGE: search_s = "r"; break; case Search_Factory::TREE: search_s = "t"; break; case Search_Factory::UNSPECIFIED: search_s = "u"; break; } file0ss << search_s << "_0spoke.txt"; file1ss << search_s << "_1favored.txt"; file2ss << search_s << "_2two.txt"; file3ss << search_s << "_3bridson.txt"; // open files std::fstream file0( file0ss.str().c_str(), std::ios::out); std::fstream file1( file1ss.str().c_str(), std::ios::out); std::fstream file2( file2ss.str().c_str(), std::ios::out); std::fstream file3( file3ss.str().c_str(), std::ios::out); // header file0 << "0 " << dim << " " << is_periodic << " " << search_s << " spoke " << dim << "d" << std::endl; file1 << "1 " << dim << " " << is_periodic << " " << search_s << " favored " << dim << "d" << std::endl; file2 << "2 " << dim << " " << is_periodic << " " << search_s << " two " << dim << "d" << std::endl; file3 << "3 " << dim << " " << is_periodic << " " << search_s << " bridson " << dim << "d" << std::endl; write_header(file0); write_header(file1); write_header(file2); write_header(file3); // number of seconds allowed // do one iteration past this value, which could take up to 4x as long if O(n^2) // const double cutoff = 540; // three minutes // const double cutoff = 180; // three minutes // const double cutoff = 24; // 2 seconds // const double cutoff = 4; // const double cutoff = 0.01; // testing // time taken last iter double t_spoke = 0.; double t_favored = 0.; double t_two = 0.; double t_bridson = 0.; // number of real samples produced last iter size_t n_spoke(0), n_favored(0), n_two(0), n_bridson(0); const double min_r0 = 1.; // MPS_Spoke::max_radius( is_periodic ); // 0.161; const double min_r1 = 1.; // MPS_Favored::max_radius( is_periodic ); // 0.102; const double min_r2 = 1.; // MPS_Two_Spoke::max_radius( is_periodic); // 0.071; const double min_r3 = 1.; // MPS_Bridson::max_radius( is_periodic); // 0.071; // double first_n = 10; // double r = 1. / ( pow( first_n, 1. / (double) (dim) )); // double r = 1. - (1. / (4. * (double) dim ) ); // if ( r > min_r0 ) double r = min_r0; size_t spoke_iter(0), favored_iter(0), two_iter(0), bridson_iter(0); for (int i=0; i<1000; ++i) { std::cout << std::endl << "scaling_by_n r = " << r << std::endl; { if ( do_spoke && (r <= min_r0) && (more_t( t_spoke, cutoff_t) || more_n( n_spoke, cutoff_n ) || more_n( spoke_iter, min_iter)) ) { t_spoke = run_spokes(file0, dim, is_periodic, r, search_type, n_spoke); spoke_iter++; } if ( do_favored && (r <= min_r1) && (more_t( t_favored, cutoff_t) || more_n( n_favored, cutoff_n ) || more_n( favored_iter, min_iter))) { t_favored = run_favored(file1, dim, is_periodic, r, search_type, n_favored); favored_iter++; } if ( do_two && (r <= min_r2) && (more_t( t_two, cutoff_t) || more_n( n_two, cutoff_n ) || more_n( two_iter, min_iter)) ) { t_two = run_two(file2, dim, is_periodic, r, search_type, n_two); two_iter++; } if ( do_bridson && (r <= min_r3) && (more_t( t_bridson, cutoff_t) || more_n( n_bridson, cutoff_n ) || more_n( bridson_iter, min_iter)) ) { t_bridson = run_bridson(file3, dim, is_periodic, r, search_type, n_bridson); bridson_iter++; } } // double n each time // this could quadruple time // r *= 1./sqrt(2); r *= 1./ pow(2., 1./double(dim)); if ( 1/r > 20000 ) break; } file0.close(); file1.close(); file2.close(); file3.close(); run_time.collect_stats(); std::cout << "scaling_by_n runtime = " << run_time.cpu_time << std::endl; }