Diploma Thesis Percolation Simulation C++ Sourcecode Documentation |
Functions | |
void | new_vs_old_algo (int dimension) |
void | compare_recursion_and_Stoddard_iteration (int dimension) |
void | choose_dividings (int dimension) |
void | choose_cuts_with_reference_algo (int dimension) |
void | testspeedof_intersection_procedures () |
void | run_different_cuts (int dimension) |
void | double_N_and_run_specified_cuts (int dimension, char *filename) |
void | double_N_and_run_all_faster_cuts (int dimension, char *filename) |
void | test_average_time_for_specified_cuts (const char *filename, int criterion, REAL ratio, int dimension, COUNTER Nsteps, NUMBER *NN, COUNTER *loops, COUNTER cuts[][2]) |
void | cuts_test_average_time (int criterion, REAL ratio, string compname) |
void | frontend_cuts_test_average_time (int criterion, REAL ratio) |
string | concat_filename (string path, string name, int dim, int maxdim) |
|
Definition at line 420 of file speedtest.h. References COUNTER, counters::divide_by_c_cuts_count_and_analyze(), GRIDSIZE, increasing_integers(), counters::maximal_dividings_in_one_coordinate(), ms(), counters::naive_arraycount_and_analyze(), NUMBER, pow(), R_critical(), R_critical_guessed(), REAL, analyze::sameresult(), set_clusternumber(), set_dim(), set_radius(), analyze::show_twohisto(), throw_spheres(), and waitanykey(). Referenced by main().
00420 { 00421 00422 NUMBER N; 00423 cout <<"Please type in NUMBER of spheres: "; 00424 cin >> N; 00425 00426 sphere *spheres = new sphere[N+1]; 00427 set_dim(spheres,0,N,dimension); 00428 00429 throw_spheres(spheres, 1, N); // randomly throw spheres from 1 to N in array scatter 00430 00431 double rr=R_critical(N,GRIDSIZE, dimension); 00432 if (rr!=-1) { 00433 cout << "The theoretically critical radius in "; 00434 cout <<dimension<<"dim is "<<rr; 00435 } 00436 else { 00437 rr=R_critical_guessed(N,GRIDSIZE,dimension); 00438 cout << "The critical radius in "; 00439 cout <<dimension<<"dim is approximately "<<rr; 00440 } 00441 cout <<"\nPlease type in the radius of one sphere: "; 00442 REAL R; cin >> R; 00443 cout <<"**************************************************"<<endl; 00444 00445 set_radius(spheres,1,N,R); 00446 00447 COUNTER cut_max=dimension*maximal_dividings_in_one_coordinate(GRIDSIZE,R); 00448 00449 cout <<"\nPlease type in how often [1..."<<cut_max<<"] "; 00450 cout <<"you want the space \nto be cut in halves: "; 00451 COUNTER cuts; cin >> cuts; 00452 cout <<"OK - these "<<cuts<<" cuts are distributed among "<<dimension<<" dimensions,"<<endl; 00453 cout <<"so by average "<<(cuts/(REAL)dimension)<<" cuts per dimensional coordinate"<<endl; 00454 cout <<"The spheres will be divided into "<<pow(2,cuts)<<" little boxes, "<<endl; 00455 cout <<"then the clusters will be counted and the boxes will be pairwise combined."<<endl; 00456 00457 NUMBER *histo1=new NUMBER[(N+1)]; 00458 NUMBER biggestcl1; REAL averagecl1; 00459 cout<<"\narraycount (old algo for reference)..."<<endl; 00460 clock_t time1=clock(); 00461 set_clusternumber(spheres,1,N,0); 00462 naive_arraycount_and_analyze(spheres, 1, N, histo1, biggestcl1,averagecl1); 00463 time1 = clock()-time1; 00464 00465 NUMLIST all; 00466 increasing_integers (all, N); // fill the list "all" with the numbers of all spheres 00467 NUMBER *histo2=new NUMBER[(N+1)]; 00468 NUMBER biggestcl2; 00469 REAL averagecl2; 00470 clock_t time2=clock(); 00471 cout <<"\ndivide_"<<cuts<<"times count..."<<endl; 00472 set_clusternumber(spheres,1,N,0); 00473 divide_by_c_cuts_count_and_analyze(spheres, all, cuts,histo2, biggestcl2, averagecl2); 00474 time2=clock()-time2; 00475 00476 if (sameresult(histo1,histo2, 1, biggestcl1)) 00477 cout <<"\n! YEAH - the new algo, that divides by "<<cuts<<" cuts is correct!"; 00478 else 00479 cout <<"\nLOOSER - the two-times-dividing gives differing results !!!"; 00480 00481 delete[] spheres, histo1, histo2; 00482 cout <<"\n\n biggestcluster: \t"<<biggestcl1<<"\t"<<biggestcl2; 00483 cout <<"\n averagecluster: \t"<<averagecl1<<"\t"<<averagecl2; 00484 00485 cout <<"\n\nnormalcount: \t"<<ms(time1)<<"ms"; 00486 cout <<"\ndivide"<<cuts<<"times count: \t"<<ms(time2)<<"ms"<<endl; 00487 00488 cout <<"if you want to see the histograms, "; 00489 waitanykey(); 00490 show_twohisto(histo1, histo2, biggestcl1); 00491 } |
|
Definition at line 327 of file speedtest.h. References COUNTER, counters::divide_d_times_count_and_analyze(), counters::divide_two_times_count_and_analyze(), GRIDSIZE, increasing_integers(), counters::maximal_dividings_in_one_coordinate(), ms(), counters::naive_arraycount_and_analyze(), NUMBER, pow(), R_critical(), R_critical_guessed(), REAL, analyze::sameresult(), set_clusternumber(), set_dim(), set_radius(), analyze::show_threehisto(), throw_spheres(), and waitanykey(). Referenced by main().
00327 { 00328 00329 00330 NUMBER N; 00331 cout <<"Please type in NUMBER of spheres: "; 00332 cin >> N; 00333 00334 sphere *spheres = new sphere[N+1]; sphere *temp = new sphere[N+1]; 00335 set_dim(spheres,0,N,dimension); set_dim(temp,0,N,dimension); 00336 00337 throw_spheres(spheres, 1, N); // randomly throw spheres from 1 to N in array scatter 00338 00339 double rr=R_critical(N,GRIDSIZE, dimension); 00340 if (rr!=-1) { 00341 cout << "The theoretically critical radius in "; 00342 cout <<dimension<<"dim is "<<rr; 00343 } 00344 else { 00345 rr=R_critical_guessed(N,GRIDSIZE,dimension); 00346 cout << "The critical radius in "; 00347 cout <<dimension<<"dim is approximately "<<rr; 00348 } 00349 cout <<"\nPlease type in the radius of one sphere: "; 00350 REAL R; cin >> R; 00351 cout <<"**************************************************"<<endl; 00352 00353 set_radius(spheres,1,N,R); 00354 00355 COUNTER nd_max=maximal_dividings_in_one_coordinate(GRIDSIZE,R); 00356 00357 cout <<"\nPlease type in how often [1..."<<nd_max<<"] "; 00358 cout <<"you want the space \nto be cut in halves (in one direction): "; 00359 COUNTER nd; cin >> nd; 00360 cout <<"OK - in "<<dimension<<" dimensions, these are "<<dimension*nd<<" cuts,"<<endl; 00361 cout <<"so the spheres are divided into "<<pow(2,nd*dimension)<<" little boxes, "<<endl; 00362 cout <<"then the clusters are counted and pairwise combined."<<endl; 00363 00364 NUMBER *histo1=new NUMBER[(N+1)]; 00365 NUMBER biggestcl1; REAL averagecl1; 00366 cout<<"\narraycount..."<<endl; 00367 clock_t time1=clock(); 00368 set_clusternumber(spheres,1,N,0); 00369 NUMBER bigclno1=naive_arraycount_and_analyze(spheres, 1, N, histo1, biggestcl1,averagecl1); 00370 time1 = clock()-time1; 00371 00372 NUMLIST all; 00373 increasing_integers (all, N); // fill the list "all" with the numbers of all spheres 00374 00375 NUMBER *histo3=new NUMBER[(N+1)]; 00376 NUMBER biggestcl3; 00377 REAL averagecl3; 00378 clock_t time3=clock(); 00379 cout <<"\ndivide_2times count..."<<endl; 00380 set_clusternumber(spheres,1,N,0); 00381 NUMBER bigclno3=divide_two_times_count_and_analyze(spheres, temp, all, N,histo3, biggestcl3, averagecl3); 00382 time3=clock()-time3; 00383 00384 NUMBER *histo4=new NUMBER[(N+1)]; 00385 NUMBER biggestcl4; 00386 REAL averagecl4; 00387 clock_t time4=clock(); 00388 cout <<"\ndivide_"<<nd*dimension<<"times count..."<<endl; 00389 set_clusternumber(spheres,1,N,0); 00390 NUMBER bigclno4=divide_d_times_count_and_analyze(spheres, 00391 all, N,nd,histo4, 00392 biggestcl4, averagecl4); 00393 00394 time4=clock()-time4; 00395 00396 if (sameresult(histo1,histo3, 1, biggestcl1)) cout <<"\n! YEAH2 - the new algo, that divides two times is correct!"; 00397 else cout <<"\nLOOSER - the two-times-dividing gives differing results !!!"; 00398 00399 if (sameresult(histo1,histo4, 1, biggestcl1)) cout <<"\n! YEAH3 - even the new one, that divides d times is correct!"; 00400 else cout <<"\nLOOSER - the "<<nd*dimension<<"-times-dividing gives differing results !!!"; 00401 00402 delete[] spheres, temp, histo1, histo3, histo4; 00403 cout <<"\n\n biggestcluster: \t"<<biggestcl1<<"\t"<<biggestcl3<<"\t"<<biggestcl4; 00404 cout <<"\n averagecluster: \t"<<averagecl1<<"\t"<<averagecl3<<"\t"<<averagecl4; 00405 cout <<"\nname of biggest cluster:\t"<<bigclno1<<"\t"<<bigclno3<<"\t"<<bigclno4; 00406 00407 cout <<"\n\nnormalcount: \t"<<ms(time1)<<"ms"; 00408 cout <<"\ndivide2times count: \t"<<ms(time3)<<"ms"; 00409 cout <<"\ndivide"<<nd*dimension<<"times count: \t"<<ms(time4)<<"ms"<<endl; 00410 00411 cout <<"if you want to see the histograms, "; 00412 waitanykey(); 00413 show_threehisto(histo1, histo3, histo4, biggestcl1); 00414 00415 } |
|
Definition at line 234 of file speedtest.h. References counters::count_clusters_iteratively(), counters::count_clusters_iteratively_only_selected_spherenumbers(), COUNTER, analyze::erasehisto(), GRIDSIZE, increasing_integers(), make_clusterlist_array(), ms(), counters::naive_arraycount_and_analyze(), NUMBER, R_critical_guessed(), REAL, reset_clusters(), analyze::sameresult(), set_clusternumber(), set_dim(), set_radius(), and throw_spheres(). Referenced by main().
00234 { 00235 NUMBER N; 00236 cout <<"Please type in NUMBER of spheres: "; 00237 cin >> N; 00238 00239 sphere *spheres = new sphere[N+1]; sphere *temp = new sphere[N+1]; 00240 set_dim(spheres,0,N,dimension); set_dim(temp,0,N,dimension); 00241 NUMBER *histo1=new NUMBER[N+1]; NUMBER *histo5=new NUMBER[N+1]; NUMBER *histo6=new NUMBER[N+1]; 00242 NUMBER biggestcl1, bigclno1; REAL averagecl1; 00243 NUMBER biggestcl5, bigclno5; REAL averagecl5; 00244 NUMBER biggestcl6, bigclno6; REAL averagecl6; 00245 NUMBER totalnumber; NUMBER numberof_cl; 00246 NUMLIST all; 00247 increasing_integers (all, N); 00248 std::vector<NUMBER> sphnumbers; sphnumbers.reserve(N+1); 00249 increasing_integers (sphnumbers, N); 00250 cluson *clusters=new cluson[all.size()+1]; 00251 double rr=R_critical_guessed(N,GRIDSIZE,dimension); 00252 REAL dummy=1.0; // for calculate_moments result type 00253 const COUNTER steps=10; 00254 REAL rep=5; // repetitions for each radius 00255 std::list<clock_t> recursion, iteration, iteration2; 00256 REAL time_recursion[steps+1], time_iteration[steps+1], time_iteration2[steps+1]; 00257 00258 COUNTER index; REAL R; COUNTER i; 00259 00260 cout<<"OK. We now compare at different densities\nthe recursion (r), \nthe iteration (i), \nand the iteration with given spherenumbers (s) \n"; 00261 for (index=0;index<=steps;index++){ 00262 R=2*(REAL)index/steps; 00263 cout <<"\ncritical: "<<R<<" "; 00264 R=R*rr; 00265 set_radius(spheres,1,N,R); 00266 recursion.clear(); iteration.clear(); iteration2.clear(); 00267 for (i=0;i<rep;i++){ 00268 throw_spheres(spheres, 1, N); 00269 00270 // naive recursion 00271 erasehisto(histo1,1,all.size()); 00272 set_clusternumber(spheres,1,N,0); 00273 cout <<"r"<<flush; 00274 clock_t time1=clock(); 00275 bigclno1=naive_arraycount_and_analyze(spheres, 1, N, histo1, biggestcl1,averagecl1); 00276 time1 = clock()-time1; 00277 00278 // naive iteration (Stoddard) 00279 erasehisto(histo5,1,all.size()); 00280 set_clusternumber(spheres,1,N,0); 00281 cout <<"i"<<flush; 00282 clock_t time5=clock(); 00283 numberof_cl=count_clusters_iteratively(spheres, 1, N, 1); 00284 reset_clusters(clusters,N); 00285 make_clusterlist_array (spheres, all, clusters); 00286 totalnumber=makehistogram ( clusters, 1,numberof_cl-1, histo5, bigclno5, biggestcl5, averagecl5); 00287 time5=clock()-time5; 00288 00289 // naive iteration (Stoddard) with selected spherenumbers 00290 erasehisto(histo6,1,all.size()); 00291 set_clusternumber(spheres,1,N,0); 00292 cout <<"s"<<flush; 00293 clock_t time6=clock(); 00294 numberof_cl=count_clusters_iteratively_only_selected_spherenumbers(spheres, sphnumbers, N, 1); 00295 reset_clusters(clusters,N); 00296 make_clusterlist_array (spheres, all, clusters); 00297 totalnumber=makehistogram ( clusters, 1,numberof_cl-1, histo6, bigclno6, biggestcl6, averagecl6); 00298 time6=clock()-time6; 00299 00300 00301 if (!sameresult(histo1,histo5, 1, biggestcl1)) cout <<"\nLOOSER - 2 algorithm -> differing results !!!"; 00302 if (!sameresult(histo1,histo6, 1, biggestcl1)) cout <<"\nLOOSER - 2 algorithm -> differing results (sph#) !!!"; 00303 recursion.push_back(time1); 00304 iteration.push_back(time5); 00305 iteration2.push_back(time6); 00306 } 00307 time_recursion[index]=calculate_moments<REAL,clock_t>(&manipdata<clock_t>::linear, 00308 42, recursion, dummy).mu.av(); 00309 time_iteration[index]=calculate_moments<REAL,clock_t>(&manipdata<clock_t>::linear, 00310 42, iteration, dummy).mu.av(); 00311 time_iteration2[index]=calculate_moments<REAL,clock_t>(&manipdata<clock_t>::linear, 00312 42, iteration2, dummy).mu.av(); 00313 00314 } 00315 00316 cout <<"\nresults of time complexity measurement (in milliseconds):\ncritical\trecursion\titeration\titeration-only-sph#"<<endl; 00317 for (index=0;index<=steps;index++){ 00318 R=2*(REAL)index/steps; 00319 cout <<R<<"\t\t"<<1/rep * ms(time_recursion[index])<<"\t\t"<<1/rep * ms(time_iteration[index]); 00320 cout <<"\t\t"<<1/rep * ms(time_iteration2[index])<<"\n"; 00321 } 00322 00323 delete[] clusters; 00324 } |
|
Definition at line 415 of file optimizealgo.h. Referenced by cuts_test_average_time().
00415 { 00416 char buffer[16]; 00417 00418 sprintf(buffer, "dim%d_(maxdim%d", dim, maxdim); 00419 00420 return path+name+string(buffer)+").txt"; 00421 } |
|
Definition at line 423 of file optimizealgo.h. References concat_filename(), COUNTER, FILEHEAD2, GRIDSIZE, MAXDIM, NUMBER, REAL, test_average_time_for_specified_cuts(), and datafiles::write_averaged_cuts_intro(). Referenced by frontend_cuts_test_average_time(), and commandline::start_subprg().
00423 { 00424 00425 int dimension; 00426 string fname="cuts-range_"; 00427 00428 // These are optimized ranges for ffS !!! not for ffC 00429 00430 /* 00431 // 1dim 00432 dimension=1; 00433 const COUNTER Nsteps1=12; 00434 NUMBER scan_N1[Nsteps1]= {312, 625, 1250, 2500, 5000, 10000, 20000, 40000, 80000, 160000, 320000, 480000}; 00435 COUNTER loops1[Nsteps1]= {50 , 50 , 15, 12, 10, 8, 8, 6, 4, 3, 3, 3}; 00436 COUNTER cuts1[Nsteps1][2]={{0,8},{0,8},{2,8},{3,8},{4,9},{5,9},{6,11},{7,11},{7,12}, {9,13}, {10,13}, {10,14}}; 00437 COUNTER steps1=12; 00438 00439 string filename1=concat_filename(FILEHEAD2, fname, dimension, MAXDIM); 00440 cout << "\n\n1dim...The following results will be written into: "<<endl; 00441 cout << filename1<<endl; 00442 00443 write_averaged_cuts_intro(filename1.c_str(), compname, GRIDSIZE, dimension, criterion); 00444 test_average_time_for_specified_cuts(filename1.c_str(), criterion, ratio, dimension, steps1, scan_N1, loops1, cuts1); 00445 00446 00447 // 2dim 00448 dimension=2; 00449 const COUNTER Nsteps2=12; 00450 NUMBER scan_N2[Nsteps2]= {312, 625, 1250, 2500, 5000, 10000, 20000, 40000, 80000, 160000, 320000, 480000}; 00451 COUNTER loops2[Nsteps2]= {40 , 30 , 15, 12, 10, 8, 8, 6, 4, 3, 3, 3}; 00452 COUNTER cuts2[Nsteps2][2]={{0,7},{0,7},{1,8},{2,8},{3,8},{4,9},{5,9},{6,9},{7,10}, {7,10}, {7,11}, {7,11}}; 00453 00454 COUNTER steps2=12; 00455 00456 string filename2=concat_filename(FILEHEAD2, fname, dimension, MAXDIM); 00457 cout << "\n\n2dim...The following results will be written into: "<<endl; 00458 cout << filename2<<endl; 00459 00460 write_averaged_cuts_intro(filename2.c_str(), compname, GRIDSIZE, dimension, criterion); 00461 test_average_time_for_specified_cuts(filename2.c_str(), criterion, ratio, dimension, steps2, scan_N2, loops2, cuts2); 00462 00463 00464 // 3dim 00465 dimension=3; 00466 const COUNTER Nsteps3=12; 00467 NUMBER scan_N3[Nsteps3]= {312, 625, 1250, 2500, 5000, 10000, 20000, 40000, 80000, 160000, 320000, 480000}; 00468 COUNTER loops3[Nsteps3]= { 40 , 30 , 30, 15, 10, 10, 7, 5, 4, 4, 3, 3}; 00469 COUNTER cuts3[Nsteps3][2]={{0,6},{0,6},{0,6},{0,7}, {0,7}, {0,7},{1,7}, {2,8}, {5,9},{5,9},{5,9}, {6,10}}; 00470 00471 COUNTER steps3=11; 00472 00473 string filename3=concat_filename(FILEHEAD2, fname, dimension, MAXDIM); 00474 cout << "\n\n3dim...The following results will be written into: "<<endl; 00475 cout << filename3<<endl; 00476 00477 write_averaged_cuts_intro(filename3.c_str(), compname, GRIDSIZE, dimension, criterion); 00478 test_average_time_for_specified_cuts(filename3.c_str(), criterion, ratio, dimension, steps3, scan_N3, loops3, cuts3); 00479 00480 00481 00482 // 4dim 00483 dimension=4; 00484 const COUNTER Nsteps4=12; 00485 NUMBER scan_N4[Nsteps4]= {312, 625, 1250, 2500, 5000, 10000, 20000, 40000, 80000, 160000, 320000, 480000}; 00486 COUNTER loops4[Nsteps4]= {30 , 20 , 15, 15, 10, 10, 7, 5, 4, 4, 3, 3}; 00487 COUNTER cuts4[Nsteps4][2]={{0,5},{0,6},{0,6},{0,7},{0,7}, {1,7}, {1,7}, {2,7}, {3,7}, {3,7}, {4,7}, {4,8}}; 00488 00489 COUNTER steps4=10; 00490 string filename4=concat_filename(FILEHEAD2, fname, dimension, MAXDIM); 00491 cout << "\n\n4dim...The following results will be written into: "<<endl; 00492 cout << filename4<<endl; 00493 00494 write_averaged_cuts_intro(filename4.c_str(), compname, GRIDSIZE, dimension, criterion); 00495 test_average_time_for_specified_cuts(filename4.c_str(),criterion, ratio, dimension, steps4, scan_N4, loops4, cuts4); 00496 00497 00498 00499 // 5dim 00500 dimension=5; 00501 const COUNTER Nsteps5=12; 00502 NUMBER scan_N5[Nsteps5]= {312, 625, 1250, 2500, 5000, 10000, 20000, 40000, 80000, 160000, 320000, 480000}; 00503 COUNTER loops5[Nsteps5]= {50 , 30 , 20, 12, 10, 8, 8, 6, 4, 3, 3, 3}; 00504 COUNTER cuts5[Nsteps5][2]={{0,6},{0,6},{0,6},{0,6},{0,6},{0,6},{0,6},{2,7}, { 2,7}, {2,7}, {4,9}, {4,9}}; 00505 00506 COUNTER steps5=10; 00507 00508 string filename5=concat_filename(FILEHEAD2, fname, dimension, MAXDIM); 00509 cout << "\n\n5dim...The following results will be written into: "<<endl; 00510 cout << filename5<<endl; 00511 00512 write_averaged_cuts_intro(filename5.c_str(), compname, GRIDSIZE, dimension, criterion); 00513 test_average_time_for_specified_cuts(filename5.c_str(), criterion, ratio, dimension, steps5, scan_N5, loops5, cuts5); 00514 00515 00516 // 6dim 00517 dimension=6; 00518 const COUNTER Nsteps6=12; 00519 NUMBER scan_N6[Nsteps6]= {312, 625, 1250, 2500, 5000, 10000, 20000, 40000, 80000, 160000, 320000, 480000}; 00520 COUNTER loops6[Nsteps6]= {50 , 30 , 20, 12, 10, 8, 8, 6, 4, 3, 3, 3}; 00521 COUNTER cuts6[Nsteps6][2]={{0,6},{0,6},{0,6},{0,5},{0,5},{0,6},{0,5},{1,6}, { 2,6}, {2,7}, {2,7}, {3,9}}; 00522 00523 COUNTER steps6=10; 00524 string filename6=concat_filename(FILEHEAD2, fname, dimension, MAXDIM); 00525 cout << "\n\n6dim...The following results will be written into: "<<endl; 00526 cout << filename6<<endl; 00527 00528 write_averaged_cuts_intro(filename6.c_str(), compname, GRIDSIZE, dimension, criterion); 00529 test_average_time_for_specified_cuts(filename6.c_str(), criterion, ratio, dimension, steps6, scan_N6, loops6, cuts6); 00530 00531 00532 00533 00534 // 7dim 00535 dimension=7; 00536 const COUNTER Nsteps7=12; 00537 NUMBER scan_N7[Nsteps7]= {312, 625, 1250, 2500, 5000, 10000, 20000, 40000, 80000, 160000, 320000, 480000}; 00538 COUNTER loops7[Nsteps7]= {50 , 30 , 20, 12, 10, 8, 8, 6, 4, 3, 3, 3}; 00539 COUNTER cuts7[Nsteps7][2]={{0,4},{0,4},{0,4},{0,4},{0,4},{0,4},{0,4},{0,4}, { 0,4}, {0,5}, {0,6}, {1,6}}; 00540 00541 COUNTER steps7=10; 00542 string filename7=concat_filename(FILEHEAD2, fname, dimension, MAXDIM); 00543 cout << "\n\n7dim...The following results will be written into: "<<endl; 00544 cout << filename7<<endl; 00545 00546 write_averaged_cuts_intro(filename7.c_str(), compname, GRIDSIZE, dimension, criterion); 00547 test_average_time_for_specified_cuts(filename7.c_str(), criterion, ratio, dimension, steps7, scan_N7, loops7, cuts7); 00548 00549 */ 00550 00551 // 8dim 00552 dimension=8; 00553 const COUNTER Nsteps8=12; 00554 NUMBER scan_N8[Nsteps8]= {312, 625, 1250, 2500, 5000, 10000, 20000, 40000, 80000, 160000, 320000, 480000}; 00555 COUNTER loops8[Nsteps8]= {50 , 30 , 20, 12, 10, 8, 8, 6, 4, 3, 3, 3}; 00556 COUNTER cuts8[Nsteps8][2]={{0,5},{0,5},{0,5},{0,5},{0,5},{0,5},{0,5},{0,5}, { 0,6}, {1,5}, {1,6}, {1,6}}; 00557 00558 COUNTER steps8=9; 00559 00560 string filename8=concat_filename(FILEHEAD2, fname, dimension, MAXDIM); 00561 cout << "\n\n8dim...The following results will be written into: "<<endl; 00562 cout << filename8<<endl; 00563 00564 write_averaged_cuts_intro(filename8.c_str(), compname, GRIDSIZE, dimension, criterion); 00565 test_average_time_for_specified_cuts(filename8.c_str(), criterion, ratio, dimension, steps8, scan_N8, loops8, cuts8); 00566 00567 // 9dim 00568 dimension=9; 00569 const COUNTER Nsteps9=12; 00570 NUMBER scan_N9[Nsteps9]= {312, 625, 1250, 2500, 5000, 10000, 20000, 40000, 80000, 160000, 320000, 480000}; 00571 COUNTER loops9[Nsteps9]= {50 , 30 , 20, 12, 10, 8, 8, 6, 4, 3, 3, 3}; 00572 COUNTER cuts9[Nsteps9][2]={{0,3},{0,3},{0,3},{0,3},{0,4},{0,4},{0,4},{0,4}, { 0,5}, {1,5}, {1,6}, {1,6}}; 00573 00574 COUNTER steps9=9; 00575 00576 string filename9=concat_filename(FILEHEAD2, fname, dimension, MAXDIM); 00577 cout << "\n\n9dim...The following results will be written into: "<<endl; 00578 cout << filename9<<endl; 00579 00580 write_averaged_cuts_intro(filename9.c_str(), compname, GRIDSIZE, dimension, criterion); 00581 test_average_time_for_specified_cuts(filename9.c_str(), criterion, ratio, dimension, steps9, scan_N9, loops9, cuts9); 00582 00583 // 10dim 00584 dimension=10; 00585 const COUNTER Nsteps10=12; 00586 NUMBER scan_N10[Nsteps10]= {312, 625, 1250, 2500, 5000, 10000, 20000, 40000, 80000, 160000, 320000, 480000}; 00587 COUNTER loops10[Nsteps10]= {50 , 30 , 20, 12, 10, 8, 8, 6, 4, 3, 3, 3}; 00588 COUNTER cuts10[Nsteps10][2]={{0,3},{0,3},{0,3},{0,3},{0,4},{0,4},{0,4},{0,4}, { 0,5}, {1,5}, {1,6}, {1,6}}; 00589 00590 COUNTER steps10=8; 00591 00592 string filename10=concat_filename(FILEHEAD2, fname, dimension, MAXDIM); 00593 cout << "\n\n10dim...The following results will be written into: "<<endl; 00594 cout << filename10<<endl; 00595 write_averaged_cuts_intro(filename10.c_str(), compname, GRIDSIZE, dimension, criterion); 00596 test_average_time_for_specified_cuts(filename10.c_str(), criterion, ratio, dimension, steps10, scan_N10, loops10, cuts10); 00597 00598 // 11dim 00599 dimension=11; 00600 const COUNTER Nsteps11=12; 00601 NUMBER scan_N11[Nsteps11]= {312, 625, 1250, 2500, 5000, 10000, 20000, 40000, 80000, 160000, 320000, 480000}; 00602 COUNTER loops11[Nsteps11]= {50 , 30 , 20, 12, 10, 8, 8, 6, 4, 3, 3, 3}; 00603 COUNTER cuts11[Nsteps11][2]={{0,3},{0,3},{0,3},{0,3},{0,4},{0,4},{0,4},{0,4}, { 0,5}, {1,5}, {1,6}, {1,6}}; 00604 00605 COUNTER steps11=8; 00606 string filename11=concat_filename(FILEHEAD2, fname, dimension, MAXDIM); 00607 cout << "\n\n11dim...The following results will be written into: "<<endl; 00608 cout << filename11<<endl; 00609 00610 write_averaged_cuts_intro(filename11.c_str(), compname, GRIDSIZE, dimension, criterion); 00611 test_average_time_for_specified_cuts(filename11.c_str(), criterion, ratio, dimension, steps11, scan_N11, loops11, cuts11); 00612 00613 00614 00615 00616 /* 00617 The perfect settings for ffC: 00618 00619 // 1dim 00620 dimension=1; 00621 char filename1[]="c:\\results\\doublenumber01_11.txt"; 00622 cout << "\n\n1dim...The following results will be written into: "; 00623 cout << filename1<<endl; 00624 const COUNTER Nsteps1=12; 00625 NUMBER scan_N1[Nsteps1]= {312, 625, 1250, 2500, 5000, 10000, 20000, 40000, 80000, 160000, 320000, 480000}; 00626 COUNTER loops1[Nsteps1]= {20 , 20 , 15, 12, 10, 8, 8, 6, 4, 3, 3, 3}; 00627 COUNTER cuts1[Nsteps1][2]={{0,8},{0,8},{1,9},{3,9},{3,10},{5,10},{5,12},{7,12},{7,13}, {8,14}, {9,14}, {9,15}}; 00628 00629 write_averaged_cuts_intro(filename1, compname, GRIDSIZE, dimension); 00630 test_average_time_for_specified_cuts(filename1, criterion, ratio, dimension, Nsteps1, scan_N1, loops1, cuts1); 00631 00632 00633 // 2dim 00634 dimension=2; 00635 char filename2[]="c:\\results\\doublenumber02_11.txt"; 00636 cout << "\n\n2dim...The following results will be written into: "; 00637 cout << filename2<<endl; 00638 const COUNTER Nsteps2=12; 00639 NUMBER scan_N2[Nsteps2]= {312, 625, 1250, 2500, 5000, 10000, 20000, 40000, 80000, 160000, 320000, 480000}; 00640 COUNTER loops2[Nsteps2]= {20 , 20 , 15, 12, 10, 8, 8, 6, 4, 3, 3, 3}; 00641 COUNTER cuts2[Nsteps2][2]={{0,7},{0,7},{1,9},{3,9},{3,9},{5,9},{5,10},{7,11},{7,11}, {8,12}, {9,13}, {9,13}}; 00642 00643 write_averaged_cuts_intro(filename2, compname, GRIDSIZE, dimension); 00644 test_average_time_for_specified_cuts(filename2, criterion, ratio, dimension, Nsteps2, scan_N2, loops2, cuts2); 00645 00646 00647 // 3dim 00648 dimension=3; 00649 char filename3[]="c:\\results\\doublenumber03_11.txt"; 00650 cout << "\n\n3dim...The following results will be written into: "; 00651 cout << filename3<<endl; 00652 const COUNTER Nsteps3=12; 00653 NUMBER scan_N3[Nsteps3]= {312, 625, 1250, 2500, 5000, 10000, 20000, 40000, 80000, 160000, 320000, 480000}; 00654 COUNTER loops3[Nsteps3]= { 30 , 20 , 15, 15, 10, 10, 7, 5, 4, 4, 3, 3}; 00655 COUNTER cuts3[Nsteps3][2]={{0,7},{0,7},{1,7},{3,8}, {3,8}, {4,9},{5,9}, {6,10}, {6,10},{6,11},{6,11}, {6,12}}; 00656 00657 write_averaged_cuts_intro(filename3, compname, GRIDSIZE, dimension); 00658 test_average_time_for_specified_cuts(filename3, criterion, ratio, dimension, Nsteps3, scan_N3, loops3, cuts3); 00659 00660 00661 // 4dim 00662 dimension=4; 00663 char filename4[]="c:\\results\\doublenumber04_11.txt"; 00664 cout << "\n\n4dim...The following results will be written into: "; 00665 cout << filename4<<endl; 00666 const COUNTER Nsteps4=12; 00667 NUMBER scan_N4[Nsteps4]= {312, 625, 1250, 2500, 5000, 10000, 20000, 40000, 80000, 160000, 320000, 480000}; 00668 COUNTER loops4[Nsteps4]= {30 , 20 , 15, 15, 10, 10, 7, 5, 4, 4, 3, 3}; 00669 COUNTER cuts4[Nsteps4][2]={{0,7},{1,7},{2,7},{3,8},{3,8}, {4,8}, {4,8}, {4,8}, {4,9}, {5,10}, {5,10}, {5,12}}; 00670 00671 write_averaged_cuts_intro(filename4, compname, GRIDSIZE, dimension); 00672 test_average_time_for_specified_cuts(filename4, criterion, ratio, dimension, Nsteps4, scan_N4, loops4, cuts4); 00673 00674 00675 // 5dim 00676 dimension=5; 00677 char filename5[]="c:\\results\\doublenumber05_11.txt"; 00678 cout << "\n\n5dim...The following results will be written into: "; 00679 cout << filename5<<endl; 00680 const COUNTER Nsteps5=12; 00681 NUMBER scan_N5[Nsteps5]= {312, 625, 1250, 2500, 5000, 10000, 20000, 40000, 80000, 160000, 320000, 480000}; 00682 COUNTER loops5[Nsteps5]= {50 , 30 , 20, 12, 10, 8, 8, 6, 4, 3, 3, 3}; 00683 COUNTER cuts5[Nsteps5][2]={{0,6},{0,7},{2,7},{3,8},{3,8},{4,8},{4,8},{4,9},{5,9}, {5,9}, {5,10}, {5,11}}; 00684 00685 write_averaged_cuts_intro(filename5, compname, GRIDSIZE, dimension); 00686 test_average_time_for_specified_cuts(filename5, criterion, ratio, dimension, Nsteps5, scan_N5, loops5, cuts5); 00687 00688 00689 // 6dim 00690 dimension=6; 00691 char filename6[]="c:\\results\\doublenumber06_11.txt"; 00692 cout << "\n\n6dim...The following results will be written into: "; 00693 cout << filename6<<endl; 00694 const COUNTER Nsteps6=12; 00695 NUMBER scan_N6[Nsteps6]= {312, 625, 1250, 2500, 5000, 10000, 20000, 40000, 80000, 160000, 320000, 480000}; 00696 COUNTER loops6[Nsteps6]= {50 , 30 , 20, 12, 10, 8, 8, 6, 4, 3, 3, 3}; 00697 COUNTER cuts6[Nsteps6][2]={{0,6},{0,7},{2,7},{3,8},{3,8},{4,8},{4,8},{4,9},{5,9}, {5,9}, {5,10}, {5,11}}; 00698 00699 write_averaged_cuts_intro(filename6, compname, GRIDSIZE, dimension); 00700 test_average_time_for_specified_cuts(filename6, criterion, ratio, dimension, Nsteps6, scan_N6, loops6, cuts6); 00701 00702 00703 // 7dim 00704 dimension=7; 00705 char filename7[]="c:\\results\\doublenumber07_11.txt"; 00706 cout << "\n\n7dim...The following results will be written into: "; 00707 cout << filename7<<endl; 00708 const COUNTER Nsteps7=12; 00709 NUMBER scan_N7[Nsteps7]= {312, 625, 1250, 2500, 5000, 10000, 20000, 40000, 80000, 160000, 320000, 480000}; 00710 COUNTER loops7[Nsteps7]= {50 , 30 , 20, 12, 10, 8, 8, 6, 4, 3, 3, 3}; 00711 COUNTER cuts7[Nsteps7][2]={{0,6},{0,7},{2,7},{3,8},{3,8},{4,8},{4,8},{4,9},{5,9}, {5,9}, {5,10}, {5,11}}; 00712 00713 write_averaged_cuts_intro(filename7, compname, GRIDSIZE, dimension); 00714 test_average_time_for_specified_cuts(filename7, criterion, ratio, dimension, Nsteps7, scan_N7, loops7, cuts7); 00715 00716 // 8dim 00717 dimension=8; 00718 char filename8[]="c:\\results\\doublenumber08_11.txt"; 00719 cout << "\n\n8dim...The following results will be written into: "; 00720 cout << filename8<<endl; 00721 const COUNTER Nsteps8=12; 00722 NUMBER scan_N8[Nsteps8]= {312, 625, 1250, 2500, 5000, 10000, 20000, 40000, 80000, 160000, 320000, 480000}; 00723 COUNTER loops8[Nsteps8]= {50 , 30 , 20, 12, 10, 8, 8, 6, 4, 3, 3, 3}; 00724 COUNTER cuts8[Nsteps8][2]={{0,6},{0,7},{2,7},{3,8},{3,8},{4,8},{4,8},{4,9},{5,9}, {5,9}, {5,10}, {5,11}}; 00725 COUNTER steps8=9; 00726 write_averaged_cuts_intro(filename8, compname, GRIDSIZE, dimension); 00727 test_average_time_for_specified_cuts(filename8, criterion, ratio, dimension, steps8, scan_N8, loops8, cuts8); 00728 00729 // 9dim 00730 dimension=9; 00731 char filename9[]="c:\\results\\doublenumber09_11.txt"; 00732 cout << "\n\n9dim...The following results will be written into: "; 00733 cout << filename9<<endl; 00734 const COUNTER Nsteps9=12; 00735 NUMBER scan_N9[Nsteps9]= {312, 625, 1250, 2500, 5000, 10000, 20000, 40000, 80000, 160000, 320000, 480000}; 00736 COUNTER loops9[Nsteps9]= {50 , 30 , 20, 12, 10, 8, 8, 6, 4, 3, 3, 3}; 00737 COUNTER cuts9[Nsteps9][2]={{0,6},{0,7},{2,7},{3,8},{3,8},{4,8},{4,8},{4,9},{5,9}, {5,9}, {5,10}, {5,11}}; 00738 COUNTER steps9=9; 00739 write_averaged_cuts_intro(filename9, compname, GRIDSIZE, dimension); 00740 test_average_time_for_specified_cuts(filename9, criterion, ratio, dimension, steps9, scan_N9, loops9, cuts9); 00741 00742 // 10dim 00743 dimension=10; 00744 char filename10[]="c:\\results\\doublenumber10_11.txt"; 00745 cout << "\n\n10dim...The following results will be written into: "; 00746 cout << filename10<<endl; 00747 const COUNTER Nsteps10=12; 00748 NUMBER scan_N10[Nsteps10]= {312, 625, 1250, 2500, 5000, 10000, 20000, 40000, 80000, 160000, 320000, 480000}; 00749 COUNTER loops10[Nsteps10]= {50 , 30 , 20, 12, 10, 8, 8, 6, 4, 3, 3, 3}; 00750 COUNTER cuts10[Nsteps10][2]={{0,6},{0,7},{2,7},{3,8},{3,8},{4,8},{4,8},{4,9},{5,9}, {5,9}, {5,10}, {5,11}}; 00751 00752 COUNTER steps10=9; 00753 write_averaged_cuts_intro(filename10, compname, GRIDSIZE, dimension); 00754 test_average_time_for_specified_cuts(filename10, criterion, ratio, dimension, steps10, scan_N10, loops10, cuts10); 00755 00756 // 11dim 00757 dimension=11; 00758 char filename11[]="c:\\results\\doublenumber11_11.txt"; 00759 cout << "\n\n11dim...The following results will be written into: "; 00760 cout << filename11<<endl; 00761 const COUNTER Nsteps11=12; 00762 NUMBER scan_N11[Nsteps11]= {312, 625, 1250, 2500, 5000, 10000, 20000, 40000, 80000, 160000, 320000, 480000}; 00763 COUNTER loops11[Nsteps11]= {50 , 30 , 20, 12, 10, 8, 8, 6, 4, 3, 3, 3}; 00764 COUNTER cuts11[Nsteps11][2]={{0,6},{0,7},{2,7},{3,8},{3,8},{4,8},{4,8},{4,9},{5,9}, {5,9}, {5,10}, {5,11}}; 00765 00766 COUNTER steps11=9; 00767 write_averaged_cuts_intro(filename11, compname, GRIDSIZE, dimension); 00768 test_average_time_for_specified_cuts(filename11, criterion, ratio, dimension, steps11, scan_N11, loops11, cuts11); 00769 00770 */ 00771 } |
|
Definition at line 224 of file optimizealgo.h. References COUNTER, counters::divide_by_c_cuts_count_and_analyze(), GRIDSIZE, increasing_integers(), counters::maximal_dividings_in_one_coordinate(), ms(), counters::naive_arraycount_and_analyze(), NUMBER, pow(), R_critical(), R_critical_guessed(), REAL, analyze::sameresult(), set_clusternumber(), set_dim(), set_radius(), throw_spheres(), datafiles::write_cuts_intro(), datafiles::write_intro(), and datafiles::write_one_cut(). Referenced by main().
00224 { 00225 00226 write_intro(filename,1,1, 1, dimension); 00227 00228 REAL NN; 00229 cout <<"Please type in the starting NUMBER of spheres: "; 00230 cin >> NN; 00231 00232 char compname[80]; 00233 cout <<"Please type in a name for the calculating computer: "; 00234 cin >> compname; 00235 00236 cout << "The results will be written into: "; 00237 cout << filename<<endl; 00238 00239 cout <<"\nNow please leave your computer alone...thanks\n"<<endl; 00240 00241 write_cuts_intro(filename, 00242 compname, 00243 GRIDSIZE, 1, dimension); 00244 00245 NUMBER N; 00246 for(;;) { 00247 N=(int)NN; 00248 cout <<"******** N="<<N<< "********"<<endl; 00249 sphere *spheres = new sphere[N+1]; 00250 set_dim(spheres,0,N,dimension); 00251 throw_spheres(spheres, 1, N); // randomly throw spheres from 1 to N in array scatter 00252 double rr=R_critical(N,GRIDSIZE, dimension); 00253 if (rr!=-1) { 00254 cout << "The theoretically critical radius in "; 00255 cout <<dimension<<"dim is "<<rr; 00256 } 00257 else { 00258 rr=R_critical_guessed(N,GRIDSIZE,dimension); 00259 cout << "The critical radius in "; 00260 cout <<dimension<<"dim is approximately "<<rr; 00261 } 00262 REAL R=rr; 00263 set_radius(spheres,1,N,R); 00264 COUNTER cut_max=dimension*maximal_dividings_in_one_coordinate(GRIDSIZE,R); 00265 cout <<"\nTheoretically, the spheres of this radius should not be placed in boxes"; 00266 cout <<"\nthat are made by more than "<<cut_max<<" cuts."<<endl; 00267 cout <<"But the algo doesn't seem to care about that :-)"<<endl; 00268 00269 NUMBER *histo1=new NUMBER[(N+1)]; 00270 NUMBER biggestcl1; REAL averagecl1; 00271 cout<<"\narraycount (old algo for reference; ~same as cuts=0).."<<flush; 00272 clock_t time1=clock(); 00273 set_clusternumber(spheres,1,N,0); 00274 naive_arraycount_and_analyze(spheres, 1, N, histo1, biggestcl1,averagecl1); 00275 time1 = clock()-time1; 00276 cout <<". took "<<ms(time1)<< "ms."<<endl; 00277 00278 write_one_cut(filename, N, rr, cut_max,0, time1); 00279 00280 NUMLIST all; 00281 increasing_integers (all, N); // fill the list "all" with the numbers of all spheres 00282 NUMBER *histo2=new NUMBER[(N+1)]; 00283 NUMBER biggestcl2; 00284 REAL averagecl2; 00285 00286 COUNTER cuts=1; 00287 clock_t time2=0; 00288 00289 while (time2<time1) { 00290 00291 time2=clock(); 00292 cout <<"divide_"<<cuts<<"times count ("<<pow(2,cuts)<<" boxes)..."<<flush; 00293 set_clusternumber(spheres,1,N,0); 00294 divide_by_c_cuts_count_and_analyze(spheres, all, cuts,histo2, biggestcl2, averagecl2); 00295 time2=clock()-time2; 00296 00297 if (sameresult(histo1,histo2, 1, biggestcl1)) 00298 cout <<" !correct result!"; 00299 else { 00300 cout <<"\nLOOSER - the divide_by_c_cuts gives differing results !!!"; 00301 exit (1); 00302 } 00303 cout << " time= "<<ms(time2)<<"ms."<<endl; 00304 write_one_cut(filename, N, rr, cut_max,cuts, time2); 00305 00306 cuts++; 00307 } 00308 00309 delete[] spheres, histo1, histo2; 00310 write_one_cut(filename, N, 0, 0,0,0); 00311 00312 NN*=2; 00313 } ; 00314 } |
|
Definition at line 103 of file optimizealgo.h. References COUNTER, counters::divide_by_c_cuts_count_and_analyze(), GRIDSIZE, increasing_integers(), counters::maximal_dividings_in_one_coordinate(), ms(), NUMBER, pow(), R_critical(), R_critical_guessed(), REAL, set_clusternumber(), set_dim(), set_radius(), throw_spheres(), datafiles::write_cuts_intro(), datafiles::write_intro(), and datafiles::write_one_cut(). Referenced by main().
00103 { 00104 00105 write_intro(filename,1,1, 1, dimension); 00106 00107 REAL NN; 00108 cout <<"Please type in the starting NUMBER of spheres: "; 00109 cin >> NN; 00110 00111 COUNTER lower_c, upper_c; 00112 cout <<"Please type in the range for the cuts ( e.g. [1...20] )"<<endl; 00113 cout <<"cuts=0 means: old algo"<<endl; 00114 /* 00115 cout <<"N.B.: The old algo (cuts=0) is computed for reference, anyway"<<endl; 00116 */ 00117 cout <<"starting number of cuts :"; 00118 cin >> lower_c; 00119 cout <<"ending number of cuts :"; 00120 cin >> upper_c; 00121 00122 char compname[80]; 00123 cout <<"Please type in a name for the calculating computer: "; 00124 cin >> compname; 00125 00126 cout << "The results will be written into: "; 00127 cout << filename<<endl; 00128 00129 cout <<"\nNow please leave your computer alone...thanks\n"<<endl; 00130 00131 write_cuts_intro(filename, 00132 compname, 00133 GRIDSIZE, 1, dimension); 00134 00135 00136 NUMBER N; 00137 00138 for (;;) { 00139 N=(int)NN; 00140 cout <<"******** N="<<N<< "********"<<endl; 00141 sphere *spheres = new sphere[N+1]; 00142 set_dim(spheres,0,N,dimension); 00143 00144 throw_spheres(spheres, 1, N); // randomly throw spheres from 1 to N in array scatter 00145 00146 double rr=R_critical(N,GRIDSIZE, dimension); 00147 if (rr!=-1) { 00148 cout << "The theoretically critical radius in "; 00149 cout <<dimension<<"dim is "<<rr; 00150 } 00151 else { 00152 rr=R_critical_guessed(N,GRIDSIZE,dimension); 00153 cout << "The critical radius in "; 00154 cout <<dimension<<"dim is approximately "<<rr; 00155 } 00156 00157 REAL R=rr; 00158 set_radius(spheres,1,N,R); 00159 COUNTER cut_max=dimension*maximal_dividings_in_one_coordinate(GRIDSIZE,R); 00160 cout <<"\nTheoretically, the spheres of this radius should not be placed in boxes"; 00161 cout <<"\nthat are made by more than "<<cut_max<<" cuts."<<endl; 00162 cout <<"But the algo doesn't seem to care about that :-)"<<endl; 00163 00164 NUMBER *histo1=new NUMBER[(N+1)]; 00165 00166 00167 /* 00168 NUMBER biggestcl1; 00169 REAL averagecl1; 00170 cout<<"\narraycount (old algo for reference; ~same as cuts=0).."<<flush; 00171 clock_t time1=clock(); 00172 set_clusternumber(spheres,1,N,0); 00173 NUMBER bigclno1=arraycount_and_analyze(spheres, 1, N, histo1, biggestcl1,averagecl1); 00174 time1 = clock()-time1; 00175 cout <<". took "<<ms(time1)<< "ms."<<endl; 00176 00177 write_one_cut(filename, N, rr, cut_max,0, time1); 00178 */ 00179 00180 NUMLIST all; 00181 increasing_integers (all, N); // fill the list "all" with the numbers of all spheres 00182 NUMBER *histo2=new NUMBER[(N+1)]; 00183 NUMBER biggestcl2; 00184 REAL averagecl2; 00185 00186 COUNTER cuts=lower_c; 00187 clock_t time2=0; 00188 00189 while (cuts<=upper_c) { 00190 time2=clock(); 00191 cout <<"divide_"<<cuts<<"times count ("<<pow(2,cuts)<<" boxes)..."<<flush; 00192 set_clusternumber(spheres,1,N,0); 00193 divide_by_c_cuts_count_and_analyze(spheres, all, cuts,histo2, biggestcl2, averagecl2); 00194 time2=clock()-time2; 00195 00196 /* 00197 if (sameresult(histo1,histo2, 1, biggestcl1)) 00198 cout <<" !correct result!"; 00199 else { 00200 cout <<"\nLOOSER - the divide_by_c_cuts gives differing results !!!"; 00201 exit (1); 00202 } 00203 */ 00204 cout << " time= "<<ms(time2)<<"ms."<<endl; 00205 write_one_cut(filename, N, rr, cut_max,cuts, time2); 00206 00207 cuts++; 00208 } 00209 00210 delete[] spheres, histo1, histo2; 00211 write_one_cut(filename, N, 0, 0,0,0); 00212 00213 NN*=2; 00214 } 00215 } |
|
Definition at line 401 of file optimizealgo.h. References cuts_test_average_time(), REAL, and waitanykey(). Referenced by main().
00401 { 00402 string compname; 00403 cout <<" P.. P...Pl.. Please type in a name for the calculating computer: "; 00404 cin >> compname; 00405 00406 char filenameXX[]="c:\\results\\doublenumberXX.txt"; 00407 cout << "\n\nThe results will be written into Files like this: "; 00408 cout << filenameXX<<endl; 00409 cout <<"\nAfter <anykey>+<return> please leave your computer alone...thanks\n"<<endl; 00410 waitanykey(); 00411 00412 cuts_test_average_time(criterion, ratio, compname); 00413 } |
|
Definition at line 35 of file speedtest.h. References COORDFLOAT, copy_array(), counters::count_clusters_iteratively(), counters::count_clusters_iteratively_only_selected_spherenumbers(), COUNTER, counters::divide_once_count_and_analyze(), counters::divide_two_times_count_and_analyze(), counters::dividecount(), analyze::erasehisto(), GRIDSIZE, increasing_integers(), make_clusterlist_array(), grid::maximal_slots_that_can_be_numbered(), ms(), counters::naive_arraycount_and_analyze(), NUMBER, R_critical(), R_critical_guessed(), REAL, reset_clusters(), analyze::sameresult(), set_clusternumber(), set_clustersizes(), set_dim(), set_radius(), analyze::show_sevenhisto(), throw_spheres(), and waitanykey(). Referenced by main().
00035 { 00036 NUMBER N; 00037 cout <<"Please type in NUMBER of spheres: "; 00038 cin >> N; 00039 00040 sphere *spheres = new sphere[N+1]; sphere *temp = new sphere[N+1]; sphere *backup = new sphere[N+1]; 00041 set_dim(spheres,0,N,dimension); set_dim(temp,0,N,dimension); set_dim(backup,0,N,dimension); 00042 00043 cout <<"Please give a random seed: "; 00044 int randseed; cin >>randseed; 00045 srand(randseed); 00046 throw_spheres(spheres, 1, N); // randomly throw spheres from 1 to N in array scatter 00047 00048 double rr=R_critical(N,GRIDSIZE, dimension); 00049 if (rr!=-1) { 00050 cout << "The theoretically critical radius in "; 00051 cout <<dimension<<"dim is "<<rr; 00052 } 00053 else { 00054 rr=R_critical_guessed(N,GRIDSIZE,dimension); 00055 cout << "The critical radius in "; 00056 cout <<dimension<<"dim is approximately "<<rr; 00057 } 00058 cout <<"\nPlease type in the radius of one sphere: "; 00059 REAL R; cin >> R; 00060 cout <<"**************************************************"<<endl; 00061 00062 set_radius(spheres,1,N,R); 00063 00064 // naive recursion 00065 NUMBER *histo1=new NUMBER[(N+1)]; 00066 NUMBER biggestcl1; REAL averagecl1; 00067 cout<<"\nnaive recursion..."<<endl; 00068 set_clusternumber(spheres,1,N,0); 00069 clock_t time1=clock(); 00070 NUMBER bigclno1=naive_arraycount_and_analyze(spheres, 1, N, histo1, biggestcl1,averagecl1); 00071 time1 = clock()-time1; 00072 00073 // a list of all sphere-numbers (used for the divide-algorithms) 00074 NUMLIST all; 00075 increasing_integers (all, N); // fill the list "all" with the numbers 1->N of all spheres 00076 00077 // divide once, then naive recursion 00078 NUMBER *histo2=new NUMBER[(N+1)]; 00079 NUMBER biggestcl2; 00080 REAL averagecl2; 00081 cout <<"\ndivide_once count..."<<endl; 00082 set_clusternumber(spheres,1,N,0); 00083 clock_t time2=clock(); 00084 NUMBER bigclno2=divide_once_count_and_analyze(spheres, temp, all, N,histo2, biggestcl2, averagecl2); 00085 time2=clock()-time2; 00086 00087 // divide twice 00088 NUMBER *histo3=new NUMBER[(N+1)]; 00089 NUMBER biggestcl3; 00090 REAL averagecl3; 00091 cout <<"\ndivide_2times count..."<<endl; 00092 set_clusternumber(spheres,1,N,0); 00093 clock_t time3=clock(); 00094 NUMBER bigclno3=divide_two_times_count_and_analyze(spheres, temp, all, N,histo3, biggestcl3, averagecl3); 00095 time3=clock()-time3; 00096 00097 // use a table of clusterlists (used for the histogram, partly for the algos) 00098 cluson *clusters=new cluson[all.size()+1]; 00099 00100 // divide by c cuts, then naive recursion 00101 NUMBER *histo4=new NUMBER[all.size()+1]; 00102 erasehisto(histo4,1,all.size()); 00103 NUMBER biggestcl4, bigclno4; REAL averagecl4; 00104 cout <<"\n3_cut_stages - count..."<<endl; 00105 set_clusternumber(spheres,1,N,0); 00106 COUNTER cuts=3; 00107 clock_t time4=clock(); 00108 NUMBER numberof_cl=dividecount(spheres, all, 00109 0,GRIDSIZE,(COORDFLOAT)0,GRIDSIZE, 00110 0, cuts, 00111 dimension,dimension, 00112 clusters, 1); 00113 // only for testing: 00114 set_clustersizes(spheres, all, clusters); 00115 copy_array(spheres, backup, 1, N); 00116 // only for testing (END) 00117 00118 NUMBER totalnumber= makehistogram ( clusters, 00119 1,numberof_cl-1, 00120 histo4, 00121 bigclno4, 00122 biggestcl4, 00123 averagecl4); 00124 time4=clock()-time4; 00125 00126 00127 // naive iteration (Stoddard) 00128 NUMBER *histo5=new NUMBER[all.size()+1]; 00129 erasehisto(histo5,1,all.size()); 00130 NUMBER biggestcl5, bigclno5; REAL averagecl5; 00131 cout <<"\nnaive iteration (Stoddard)..."<<endl; 00132 reset_clusters(clusters,N); 00133 set_clusternumber(spheres,1,N,0); 00134 clock_t time5=clock(); 00135 numberof_cl=count_clusters_iteratively(spheres, 1, N, 1); 00136 make_clusterlist_array (spheres, all, clusters); 00137 totalnumber= makehistogram ( clusters, 00138 1,numberof_cl-1, 00139 histo5, 00140 bigclno5, 00141 biggestcl5, 00142 averagecl5); 00143 00144 time5=clock()-time5; 00145 00146 // naive iteration (Stoddard) - but only selected spherenumbers through vector<NUMBER> sphnumber 00147 NUMBER *histo6=new NUMBER[all.size()+1]; 00148 erasehisto(histo6,1,all.size()); 00149 NUMBER biggestcl6, bigclno6; REAL averagecl6; 00150 cout <<"\nnaive iteration (Stoddard), but selected spherenumbers..."<<endl; 00151 reset_clusters(clusters,N); 00152 set_clusternumber(spheres,1,N,0); 00153 std::vector<NUMBER> sphnumbers; sphnumbers.resize(N+1); 00154 increasing_integers(sphnumbers, N); 00155 clock_t time6=clock(); 00156 numberof_cl=count_clusters_iteratively_only_selected_spherenumbers(spheres, sphnumbers, N, 1); 00157 make_clusterlist_array (spheres, all, clusters); 00158 totalnumber= makehistogram ( clusters, 00159 1,numberof_cl-1, 00160 histo6, 00161 bigclno6, 00162 biggestcl6, 00163 averagecl6); 00164 00165 time6=clock()-time6; 00166 00167 00168 // boxcount 00169 00170 NUMBER *histo7=new NUMBER[all.size()+1]; 00171 NUMBER biggestcl7=0, bigclno7=0; REAL averagecl7=0; 00172 NUMBER n=(NUMBER)(GRIDSIZE/(2*R) /2);// heuristic: number of slots in one direction 00173 NUMBER maxn=(NUMBER)maximal_slots_that_can_be_numbered(dimension); 00174 clock_t time7=0; 00175 00176 /* 00177 erasehisto(histo7,1,all.size()); 00178 cout <<"\nboxcount recursion..."<<endl; 00179 reset_clusters(clusters,N); 00180 set_clusternumber(spheres,1,N,0); 00181 cout <<" |n="<<n<<" maxn="<<maxn<<"| "; 00182 n=maxn<n?n=maxn:n; 00183 time7=clock(); 00184 numberof_cl=boxcount_and_analyze(spheres, all, 2 , 2*R, histo7, biggestcl7, averagecl7, bigclno7); 00185 time7=clock()-time7; 00186 */ 00187 00188 delete[] clusters; 00189 00190 00191 if (sameresult(histo1,histo2, 1, biggestcl1)) cout <<"\n! YEAH - I've got a new algorithm - the results for divide_once are the same!"; 00192 else cout <<"\nLOOSER - the new algorithm for divide_once gives differing results !!!"; 00193 00194 if (sameresult(histo1,histo3, 1, biggestcl1)) cout <<"\n! YEAH2 - even the new one, that divides two times is correct!"; 00195 else cout <<"\nLOOSER - the two-times-dividing gives differing results !!!"; 00196 00197 if (sameresult(histo1,histo4, 1, biggestcl1)) cout <<"\n! YEAH4 - even the new one, that cuts on three levels is correct!"; 00198 else cout <<"\nLOOSER - the 3-level-cutting gives differing results !!!"; 00199 00200 if (sameresult(histo1,histo5, 1, biggestcl1)) cout <<"\n! YEAH5 - even the new one, that counts iteratively is correct!"; 00201 else cout <<"\nLOOSER - the iterative counting gives differing results !!!"; 00202 00203 if (sameresult(histo1,histo6, 1, biggestcl1)) cout <<"\n! YEAH6 - even the new one, that counts iteratively with selected sph# is correct!"; 00204 else cout <<"\nLOOSER - the selected sph# iterative counting gives differing results !!!"; 00205 00206 if (sameresult(histo1,histo7, 1, biggestcl1)) cout <<"\n! YEAH7 - even the new one, the boxcount is correct!"; 00207 else { 00208 cout <<"\nLOOSER - the boxcount gives differing results !!!"; 00209 // compare_clustersizes(backup, spheres, 1, N); 00210 } 00211 00212 00213 cout <<"\n\n biggestcluster: \t"<<biggestcl1<<"\t"<<biggestcl2<<"\t"<<biggestcl3<<"\t"<<biggestcl4<<"\t"<<biggestcl5<<"\t"<<biggestcl6<<"\t"<<biggestcl7; 00214 cout <<"\n averagecluster: \t"<<averagecl1<<"\t"<<averagecl2<<"\t"<<averagecl3<<"\t"<<averagecl4<<"\t"<<averagecl5<<"\t"<<averagecl6<<"\t"<<averagecl7; 00215 cout <<"\nname of biggest cluster:\t"<<bigclno1<<"\t"<<bigclno2<<"\t"<<bigclno3<<"\t"<<bigclno4<<"\t"<<bigclno5<<"\t"<<bigclno6<<"\t"<<bigclno7; 00216 00217 cout <<"\n\nnaive recursion: \t"<<ms(time1)<<"ms"; 00218 cout <<"\ndivide_once count: \t"<<ms(time2)<<"ms"; 00219 cout <<"\ndivide2times count: \t"<<ms(time3)<<"ms"; 00220 cout <<"\ncut-on-3-levels count: \t"<<ms(time4)<<"ms"; 00221 cout <<"\nStoddard iteration: \t"<<ms(time5)<<"ms"; 00222 cout <<"\nwith selected sph#: \t"<<ms(time6)<<"ms"; 00223 cout <<"\nboxcount: \t"<<ms(time7)<<"ms"<<endl; 00224 00225 cout <<"if you want to see the histograms, "; 00226 waitanykey(); 00227 show_sevenhisto(histo1, histo2, histo3, histo4, histo5, histo6, histo7, N); 00228 00229 delete[] spheres, temp, histo1, histo2, histo3, histo4, histo5, histo6, histo7; 00230 00231 } |
|
Definition at line 20 of file optimizealgo.h. References COUNTER, counters::divide_by_c_cuts_count_and_analyze(), GRIDSIZE, increasing_integers(), counters::maximal_dividings_in_one_coordinate(), ms(), counters::naive_arraycount_and_analyze(), NUMBER, pow(), R_critical(), R_critical_guessed(), REAL, analyze::sameresult(), set_clusternumber(), set_dim(), set_radius(), analyze::show_twohisto(), throw_spheres(), and waitanykey(). Referenced by main().
00020 { 00021 00022 NUMBER N; 00023 cout <<"Please type in NUMBER of spheres: "; 00024 cin >> N; 00025 00026 sphere *spheres = new sphere[N+1]; 00027 set_dim(spheres,0,N,dimension); 00028 00029 throw_spheres(spheres, 1, N); // randomly throw spheres from 1 to N in array scatter 00030 00031 double rr=R_critical(N,GRIDSIZE, dimension); 00032 if (rr!=-1) { 00033 cout << "The theoretically critical radius in "; 00034 cout <<dimension<<"dim is "<<rr; 00035 } 00036 else { 00037 rr=R_critical_guessed(N,GRIDSIZE,dimension); 00038 cout << "The critical radius in "; 00039 cout <<dimension<<"dim is approximately "<<rr; 00040 } 00041 cout <<"\nPlease type in the radius of one sphere: "; 00042 REAL R; cin >> R; 00043 cout <<"**************************************************"<<endl; 00044 00045 set_radius(spheres,1,N,R); 00046 00047 COUNTER cut_max=dimension*maximal_dividings_in_one_coordinate(GRIDSIZE,R); 00048 00049 cout <<"Theoretically, the spheres of this radius should not be placed in boxes"; 00050 cout <<"\nthat are made by more than "<<cut_max<<" cuts."<<endl; 00051 cout <<"But the algo doesn't seem to care about that :-)"<<endl; 00052 00053 NUMBER *histo1=new NUMBER[(N+1)]; 00054 NUMBER biggestcl1; REAL averagecl1; 00055 cout<<"\narraycount (old algo for reference; ~same as cuts=0).."<<flush; 00056 clock_t time1=clock(); 00057 set_clusternumber(spheres,1,N,0); 00058 naive_arraycount_and_analyze(spheres, 1, N, histo1, biggestcl1,averagecl1); 00059 time1 = clock()-time1; 00060 cout <<". took "<<ms(time1)<< "ms."<<endl; 00061 00062 NUMLIST all; 00063 increasing_integers (all, N); // fill the list "all" with the numbers of all spheres 00064 NUMBER *histo2=new NUMBER[(N+1)]; 00065 NUMBER biggestcl2=0; 00066 REAL averagecl2=0; 00067 00068 COUNTER cuts=0; 00069 clock_t time2=0; 00070 00071 while (time2<time1) { 00072 cuts++; 00073 time2=clock(); 00074 cout <<"divide_"<<cuts<<"times count ("<<pow(2,cuts)<<" boxes)..."<<flush; 00075 set_clusternumber(spheres,1,N,0); 00076 divide_by_c_cuts_count_and_analyze(spheres, all, cuts,histo2, biggestcl2, averagecl2); 00077 time2=clock()-time2; 00078 00079 if (sameresult(histo1,histo2, 1, biggestcl1)) 00080 cout <<" !correct result!"; 00081 else { 00082 cout <<"\nLOOSER - the divide_by_c_cuts gives differing results !!!"; 00083 exit (1); 00084 } 00085 cout << " time= "<<ms(time2)<<"ms."<<endl; 00086 } 00087 00088 delete[] spheres, histo1, histo2; 00089 cout <<"\n\n biggestcluster: \t"<<biggestcl1<<"\t"<<biggestcl2; 00090 cout <<"\n averagecluster: \t"<<averagecl1<<"\t"<<averagecl2; 00091 00092 cout <<"\n\nnormalcount: \t"<<ms(time1)<<"ms"; 00093 cout <<"\ndivide"<<cuts<<"times count: \t"<<ms(time2)<<"ms"<<endl; 00094 00095 cout <<"if you want to see the histograms, "; 00096 waitanykey(); 00097 show_twohisto(histo1, histo2, biggestcl1); 00098 } |
|
Definition at line 317 of file optimizealgo.h. References COUNTER, counters::divide_by_c_cuts_count_and_analyze(), ff::give_one_stepfunction(), give_radius(), GRIDSIZE, increasing_integers(), ms(), NUMBER, pow(), R_critical_guessed(), REAL, rounded(), set_clusternumber(), set_dim(), set_radius(), throw_spheres(), and datafiles::write_one_averaged_cut(). Referenced by cuts_test_average_time().
00324 { 00325 00326 NUMBER N; 00327 COUNTER lower_c, upper_c; 00328 REAL rc; 00329 00330 NUMLIST all; 00331 NUMBER *histo; 00332 NUMBER biggestcl; 00333 REAL averagecl; 00334 00335 clock_t eachtime; 00336 REAL time_mean, time_sdev; 00337 std::list<clock_t> time_results; 00338 std::list<clock_t>::iterator onetime; 00339 00340 fillingfactor_functions ff_fn; 00341 ff_fn=give_one_stepfunction(criterion); 00342 00343 00344 for (COUNTER Nstep=0;Nstep<Nsteps;Nstep++){ 00345 N=NN[Nstep]; 00346 sphere *spheres = new sphere[N+1]; 00347 set_dim(spheres,0,N,dimension); 00348 increasing_integers (all, N); // fill the list "all" with the numbers of all spheres 00349 histo=new NUMBER[(N+1)]; // make a new histogram table 00350 00351 cout <<"\n N="<<N<< "; "<<flush; 00352 00353 00354 REAL ff = ff_fn.theory(N, dimension, ratio); 00355 rc=give_radius (ff, N, GRIDSIZE, dimension); 00356 00357 00358 if (rc!=-1) cout << "rc(dim="<<dimension<<", N="<<N<<", area="<<pow(GRIDSIZE, dimension)<<")="<<rc; 00359 else { 00360 rc=R_critical_guessed(N,GRIDSIZE,dimension); 00361 cout << "chosen guessed critical radius as rc(dim="<<dimension<<") :"<<rc; 00362 } 00363 00364 lower_c=cuts[Nstep][0]; 00365 upper_c=cuts[Nstep][1]; 00366 for (COUNTER cuts=lower_c;cuts<=upper_c;cuts++){ 00367 00368 cout <<"\ncuts="<<cuts<<" (divide into "<<pow(2,cuts)<<" boxes)..."<<flush; 00369 cout <<"for "<<loops[Nstep]<< " averaging times:"<<endl; 00370 00371 time_results.clear(); 00372 for (COUNTER loop=0;loop<loops[Nstep];loop++){ 00373 throw_spheres(spheres, 1, N); // randomly throw spheres from 1 to N in array scatter 00374 set_radius(spheres,1,N,rc); 00375 set_clusternumber(spheres,1,N,0); 00376 eachtime=clock(); 00377 divide_by_c_cuts_count_and_analyze(spheres, all, cuts,histo, biggestcl, averagecl); 00378 eachtime=clock()-eachtime; 00379 time_results.push_back(eachtime); 00380 cout << ms(eachtime)<<"ms "<<flush; 00381 } 00382 00383 averaging<clock_t> (time_results, time_mean, time_sdev); 00384 00385 cout<<"\naverage time: "<<ms((clock_t)time_mean)<<"ms +/- "<<ms((clock_t)time_sdev)<<"ms" <<endl; 00386 write_one_averaged_cut(filename, N, rc, loops[Nstep], cuts, 00387 (clock_t)rounded(time_mean), (clock_t)rounded(time_sdev)); 00388 } 00389 00390 delete[] spheres, histo; 00391 all.clear(); 00392 00393 write_one_averaged_cut(filename, N, 0, 0,0,0,0); 00394 } 00395 } |
|
Definition at line 495 of file speedtest.h. References COUNTER, intersection_of_sortedlists(), intersection_of_unsortedlists(), ms(), and NUMBER.
00495 { 00496 NUMLIST a, b, c1, c2; 00497 NUMBER N1,N2; 00498 cout <<"How many random numbers? "<<endl; 00499 cout <<"in list a: "; 00500 cin >>N1; 00501 cout <<"in list b: "; 00502 cin >>N2; 00503 00504 cout <<"generating random numbers in two lists..."<<endl; 00505 NUMBER i; 00506 for (i=0;i<N1;i++){ 00507 a.push_back(rand()); 00508 } 00509 for (i=0;i<N2;i++){ 00510 b.push_back(rand()); 00511 } 00512 cout <<"sorting the numbers in each list..."<<endl; 00513 clock_t t3=clock(); 00514 a.sort(); 00515 b.sort(); 00516 t3=clock()-t3; 00517 00518 cout <<"erasing the doubles in each list..."<<endl; 00519 clock_t t4=clock(); 00520 a.unique(); 00521 b.unique(); 00522 t4=clock()-t4; 00523 00524 cout <<"intersection of lists as if they were unsorted (NAIVE)..."<<endl; 00525 c1.clear(); 00526 clock_t t1=clock(); 00527 COUNTER n1=intersection_of_unsortedlists(a,b,c1); 00528 t1=clock()-t1; 00529 00530 cout <<"intersection of lists knowing they are sorted (CLEVER)..."<<endl; 00531 c2.clear(); 00532 clock_t t2=clock(); 00533 COUNTER n2=intersection_of_sortedlists(a,b,c2); 00534 t2=clock()-t2; 00535 00536 cout <<"\n"; 00537 cout <<a.size()<<" in list a, "<<b.size()<<" in list b."<<endl; 00538 cout <<c1.size()<<" in intersection:"<<endl; 00539 NUMLIST::iterator each1, each2; 00540 each2=c2.begin(); 00541 00542 for (each1=c1.begin(); each1!=c1.end(); each1++){ 00543 if ((*each1!=*each2)) { 00544 cout <<"\n"<<*each1<<"\t"<<*each2<<"\t"<<*each2<<"\t"<<endl; 00545 exit(0); 00546 } 00547 else cout <<*each1<<"\t"; 00548 each2++; 00549 } 00550 cout <<endl; 00551 cout <<"time(ms) \tfor 2*sort:\t"<<ms(t3)<<" \n\t\tfor 2*unique:\t"<<ms(t4)<<endl; 00552 cout <<"for intersection of unsorted list:\t"<<ms(t1)<<" \n\t\t of sorted list: \t"<<ms(t2)<<"\t"<<endl; 00553 cout <<"number of intersections: "<<n1<<"\t"<<n2<<endl; 00554 cout <<"completely equal? "<< ((c1==c2)?"yes":"no") <<endl; 00555 00556 } |
Diploma Thesis Sourcecode
Documentation check out the text and the executable binaries |