ColPack
|
00001 #include "stat.h" 00002 00003 vector<string> getListOfGraphs(string location_of_graph_list) 00004 { 00005 static vector<string> list; 00006 string temp; 00007 int i=0, max_iteration=1000; 00008 00009 //Make sure that this function only run once despite how many times I call toFile...() functions 00010 //Help make the statistics data consistent between files. 00011 static bool is_run_already = false; 00012 if (is_run_already) return list; 00013 else is_run_already = true; 00014 00015 ifstream input (location_of_graph_list.c_str()); 00016 if(!input) {cout<<"**ERR getListOfGraphs: "<<location_of_graph_list<<" is not found"<<endl;return list;} 00017 else cout<<"getListOfGraphs: Found file. The following graphs will be read:"<<endl; 00018 list.clear(); 00019 input>>temp; 00020 while(temp!="*" && i<max_iteration) { 00021 if(temp[temp.size()-1]=='*') 00022 temp = temp.substr(0,temp.size()-1); 00023 list.push_back(temp); 00024 00025 //Display 00026 cout<<"\t "<<temp<<endl; 00027 00028 input>>temp; 00029 00030 i++; 00031 } 00032 if (i==max_iteration) { 00033 cerr<<"**ERR getListOfGraphs(): i==max_iteration. May be you forget to use the \"*\" to terminate the list of graphs?"<<endl; 00034 } 00035 input.close(); 00036 return list; 00037 } 00038 00039 00040 00041 void toFileC_forColoringBasedOrdering(string baseDir, string stat_output_suffix , bool stat_output_append, bool stat_refresh_list ) 00042 { 00043 ofstream stat_out1, stat_out2, stat_out3, stat_out4; 00044 vector <string> listOfGraphs = getListOfGraphs(baseDir+"listOfGraphs.txt"); 00045 string s_OrderingVariant = "", s_ColoringVariant = ""; 00046 00047 if(stat_output_append) { 00048 stat_out1.open((baseDir+"NumberOfColors"+stat_output_suffix+".csv").c_str(),ios::app); 00049 stat_out2.open((baseDir+"Time"+stat_output_suffix+".csv").c_str(),ios::app); 00050 stat_out3.open((baseDir+"MaxBackDegree"+stat_output_suffix+".csv").c_str(),ios::app); 00051 stat_out4.open((baseDir+"Graph_Stat"+stat_output_suffix+".csv").c_str(),ios::app); 00052 stat_out1<<endl<<endl; 00053 stat_out2<<endl<<endl; 00054 stat_out3<<endl<<endl; 00055 stat_out4<<endl<<endl; 00056 } 00057 else { 00058 stat_out1.open((baseDir+"NumberOfColors"+stat_output_suffix+".csv").c_str()); 00059 stat_out2.open((baseDir+"Time"+stat_output_suffix+".csv").c_str()); 00060 stat_out3.open((baseDir+"MaxBackDegree"+stat_output_suffix+".csv").c_str()); 00061 stat_out4.open((baseDir+"Graph_Stat"+stat_output_suffix+".csv").c_str()); 00062 } 00063 00064 //Title 00065 stat_out1<<"Style,Name,N,LF,SL,ID,D2LF,D2SL,D2ID"<<endl; 00066 stat_out2<<"Style,Name,N,,,LF,,,SL,,,ID,,,D2LF,,,D2SL,,,D2ID"<<endl; 00067 stat_out2<<",,OT,CT,TT,OT,CT,TT,OT,CT,TT,OT,CT,TT,OT,CT,TT,OT,CT,TT,OT,CT,TT"<<endl; 00068 stat_out3<<"Style,Name,N,LF,SL,ID,D2LF,D2SL,D2ID"<<endl; 00069 stat_out4<<"Name,|V|,|E|,MaxDegree,MinDegree,AvgDegree"<<endl; 00070 00071 for(unsigned int i=0;i < listOfGraphs.size(); i++){ 00072 printListOfGraphs(listOfGraphs,i); 00073 00074 for(int j=0;j<5;j++) 00075 //for(int j=0;j<1;j++) 00076 { 00077 if(j==3) continue; 00078 cout<<endl; 00079 00080 switch(j) 00081 { 00082 case 0: s_ColoringVariant = "DISTANCE_ONE"; cout<<"D1 "; stat_out1<<"D1,";stat_out2<<"D1,";stat_out3<<"D1,";break;//SL, 00083 case 1: s_ColoringVariant = "ACYCLIC"; cout<<"A "; stat_out1<<"A,";stat_out2<<"A,";stat_out3<<"A,";break; //N 00084 case 2: s_ColoringVariant = "STAR"; cout<<"S "; stat_out1<<"S,";stat_out2<<"S,";stat_out3<<"S,";break; //D2SL 00085 case 3: s_ColoringVariant = "RESTRICTED_STAR"; cout<<"RS "; stat_out1<<"RS,";stat_out2<<"RS,";stat_out3<<"RS,";break; 00086 case 4: s_ColoringVariant = "DISTANCE_TWO"; cout<<"D2 "; stat_out1<<"D2,";stat_out2<<"D2,";stat_out3<<"D2,";break; //SL 00087 } 00088 cout<<"Coloring "<<endl<<flush; 00089 00090 File stat_file_parsor; 00091 stat_file_parsor.Parse(listOfGraphs[i]); 00092 stat_out1<<stat_file_parsor.GetName(); 00093 stat_out2<<stat_file_parsor.GetName(); 00094 stat_out3<<stat_file_parsor.GetName(); 00095 00096 //for (int k= ordering_num ; k < ordering_num + 1; k++) 00097 for (int k=0; k<9; k++) 00098 //for (int k=8; k<9; k++) 00099 //for (int k=2; k<3; k++) 00100 { 00101 //if( (j==0 && k==2) || (j==1 && k==0) || (j==2 && k==5) ) {} else continue; 00102 //if( (j==0 && k==2) || (j==1 && k==0) || (j==2 && k==5) || (j==4 && k==2) ) {} else continue; 00103 //if( (j!=4) && (k==4||k==5||k==6) ) continue; 00104 //if( (j!=2 && j!=3 && j!=4) && (k==4||k==5||k==6) ) continue; 00105 if (j != 0 || (k != 0 && k !=2)) continue; 00106 //if(j!=2||k!=0) continue; 00107 //if(k!=2&&k!=7) continue; 00108 //if(k!=0) continue; 00109 //if(j==0&&k==1) continue; 00110 //gGraph->Reset(); 00111 00112 current_time(); 00113 00114 switch(k) 00115 { 00116 case 0: s_OrderingVariant="NATURAL"; cout<<"NATURAL " ;break; 00117 case 1: s_OrderingVariant="LARGEST_FIRST"; cout<<"LARGEST_FIRST " ;break; 00118 case 2: s_OrderingVariant="SMALLEST_LAST"; cout<<"SMALLEST_LAST " ;break; 00119 case 3: s_OrderingVariant="INCIDENCE_DEGREE"; cout<<"INCIDENCE_DEGREE " ;break; 00120 case 4: s_OrderingVariant="DISTANCE_TWO_LARGEST_FIRST"; cout<<"DISTANCE_TWO_LARGEST_FIRST " ;break; 00121 case 5: s_OrderingVariant="DISTANCE_TWO_SMALLEST_LAST"; cout<<"DISTANCE_TWO_SMALLEST_LAST " ;break; 00122 case 6: s_OrderingVariant="DISTANCE_TWO_INCIDENCE_DEGREE"; cout<<"DISTANCE_TWO_INCIDENCE_DEGREE " ;break; 00123 case 7: s_OrderingVariant="DYNAMIC_LARGEST_FIRST"; cout<<"DYNAMIC_LARGEST_FIRST " ;break; 00124 case 8: s_OrderingVariant="RANDOM"; cout<<"RANDOM " ;break; 00125 } 00126 cout<<"Ordering "<<endl; 00127 00128 00129 GraphColoringInterface * gGraph = new GraphColoringInterface(SRC_FILE,listOfGraphs[i].c_str(), "AUTO_DETECTED"); 00130 gGraph->Coloring(s_OrderingVariant, s_ColoringVariant ); 00131 00132 //cout<<"GetVertexColorCount="<<gGraph->GetVertexColorCount()<<endl<<flush; 00133 stat_out1<<","<<gGraph->GetVertexColorCount()<<flush; 00134 stat_out2<<","<<gGraph->GetVertexOrderingTime()<<","<<gGraph->GetVertexColoringTime()<<","<<gGraph->GetVertexColoringTime()+gGraph->GetVertexOrderingTime()<<flush; 00135 00136 Timer m_T_Timer; 00137 vector<int> output; 00138 gGraph->GetVertexColors(output); 00139 m_T_Timer.Start(); 00140 gGraph->ColoringBasedOrdering(output); 00141 m_T_Timer.Stop(); 00142 double OrderingTime = m_T_Timer.GetWallTime(); 00143 00144 gGraph->SetStringVertexColoringVariant(""); // so that DistanceOneColoring() actually does the coloring 00145 m_T_Timer.Start(); 00146 gGraph->GraphColoring::DistanceOneColoring(); 00147 m_T_Timer.Stop(); 00148 double ColoringTime = m_T_Timer.GetWallTime(); 00149 00150 stat_out1<<","<<gGraph->GetVertexColorCount()<<flush; 00151 stat_out2<<","<<OrderingTime<<","<<ColoringTime<<","<<ColoringTime+OrderingTime<<flush; 00152 00153 00154 //if(k == 2) { // Only get MaxBackDegree of SL ordering 00155 if(j == 0) { 00156 cout<<"GetMaxBackDegree ... MaxBackDegree = "<<flush; 00157 00158 int MaxBackDegree = gGraph->GetMaxBackDegree(); 00159 stat_out3<<","<<MaxBackDegree<<flush; 00160 //stat_out3<<","<<gGraph->GetMaxBackDegree2()<<flush; 00161 00162 cout<<MaxBackDegree; 00163 00164 if(k == 0) { // only get statistics once for each graph 00165 stat_out4<<stat_file_parsor.GetName(); 00166 stat_out4<<","<<gGraph->GetVertexCount(); 00167 stat_out4<<","<<gGraph->GetEdgeCount(); 00168 stat_out4<<","<<gGraph->GetMaximumVertexDegree(); 00169 stat_out4<<","<<gGraph->GetMinimumVertexDegree(); 00170 stat_out4<<","<<gGraph->GetAverageVertexDegree(); 00171 stat_out4<<endl<<flush; 00172 } 00173 } 00174 cout<<" DONE"<<endl; 00175 delete gGraph; 00176 //system("pause"); 00177 //break; 00178 } 00179 stat_out1<<endl; 00180 stat_out2<<endl; 00181 stat_out3<<endl; 00182 //break; 00183 } 00184 00185 cout<<"***Finish 1 graph"<<endl<<endl<<endl; 00186 } 00187 00188 stat_out1.close(); 00189 stat_out2.close(); 00190 stat_out3.close(); 00191 stat_out4.close(); 00192 } 00193 00194 void toFileC(string baseDir, string stat_output_suffix, vector<string> Orderings, vector<string> Colorings, map<string, bool> stat_flags ) { 00195 ofstream out_NumberOfColors, out_Time, out_MaxBackDegree, out_Graph_Stat; 00196 vector <string> listOfGraphs = getListOfGraphs(baseDir+"listOfGraphs.txt"); 00197 00198 // ****************************************************** 00199 // Open appropriate output stream 00200 if( stat_flags["output_append"] ) { 00201 if(stat_flags["NumberOfColors"]) { 00202 cout<<"NumberOfColors: Append to "<<(baseDir+"NumberOfColors"+"-Coloring"+stat_output_suffix+".csv")<<endl; 00203 out_NumberOfColors.open((baseDir+"NumberOfColors"+"-Coloring"+stat_output_suffix+".csv").c_str(),ios::app); 00204 out_NumberOfColors<<endl<<endl; 00205 } 00206 00207 if(stat_flags["Time"]) { 00208 cout<<"Time: Append to "<<(baseDir+"Time"+"-Coloring"+stat_output_suffix+".csv")<<endl; 00209 out_Time.open((baseDir+"Time"+"-Coloring"+"-Coloring"+stat_output_suffix+".csv").c_str(),ios::app); 00210 out_Time<<endl<<endl; 00211 } 00212 00213 if(stat_flags["MaxBackDegree"]) { 00214 cout<<"MaxBackDegree: Append to "<<(baseDir+"MaxBackDegree"+"-Coloring"+stat_output_suffix+".csv")<<endl; 00215 out_MaxBackDegree.open((baseDir+"MaxBackDegree"+"-Coloring"+stat_output_suffix+".csv").c_str(),ios::app); 00216 out_MaxBackDegree<<endl<<endl; 00217 } 00218 00219 if(stat_flags["Graph_Stat"]) { 00220 cout<<"Graph_Stat: Append to "<<(baseDir+"Graph_Stat"+"-Coloring"+stat_output_suffix+".csv")<<endl; 00221 out_Graph_Stat.open((baseDir+"Graph_Stat"+"-Coloring"+stat_output_suffix+".csv").c_str(),ios::app); 00222 out_Graph_Stat<<endl<<endl; 00223 } 00224 } 00225 else { 00226 if(stat_flags["NumberOfColors"]) { 00227 cout<<"NumberOfColors: Write to "<<(baseDir+"NumberOfColors"+"-Coloring"+stat_output_suffix+".csv")<<endl; 00228 out_NumberOfColors.open((baseDir+"NumberOfColors"+"-Coloring"+stat_output_suffix+".csv").c_str()); 00229 } 00230 00231 if(stat_flags["Time"]) { 00232 cout<<"Time: Write to "<<(baseDir+"Time"+"-Coloring"+stat_output_suffix+".csv")<<endl; 00233 out_Time.open((baseDir+"Time"+"-Coloring"+stat_output_suffix+".csv").c_str()); 00234 } 00235 00236 if(stat_flags["MaxBackDegree"]) { 00237 cout<<"MaxBackDegree: Write to "<<(baseDir+"MaxBackDegree"+"-Coloring"+stat_output_suffix+".csv")<<endl; 00238 out_MaxBackDegree.open((baseDir+"MaxBackDegree"+"-Coloring"+stat_output_suffix+".csv").c_str()); 00239 } 00240 00241 if(stat_flags["Graph_Stat"]) { 00242 cout<<"Graph_Stat: Write to "<<(baseDir+"Graph_Stat"+"-Coloring"+stat_output_suffix+".csv")<<endl; 00243 out_Graph_Stat.open((baseDir+"Graph_Stat"+"-Coloring"+stat_output_suffix+".csv").c_str()); 00244 } 00245 } 00246 00247 // ****************************************************** 00248 // Create titles 00249 if(stat_flags["NumberOfColors"]) { 00250 out_NumberOfColors<<"Style, Name"; 00251 for(int i=0; i< Orderings.size(); i++) { 00252 out_NumberOfColors<<", "<<Orderings[i]; 00253 } 00254 out_NumberOfColors<<endl; 00255 } 00256 00257 if(stat_flags["Time"]) { 00258 // line 1 00259 out_Time<<"Style,Name"; 00260 for(int i=0; i< Orderings.size(); i++) { 00261 out_Time<<", "<<Orderings[i]<<", , "; 00262 } 00263 out_Time<<endl; 00264 00265 // line 2 00266 out_Time<<","; 00267 for(int i=0; i< Orderings.size(); i++) { 00268 out_Time<<", OT, CT, TT"; 00269 } 00270 out_Time<<endl; 00271 } 00272 00273 if(stat_flags["MaxBackDegree"]) { 00274 out_MaxBackDegree<<"Name"; 00275 for(int i=0; i< Orderings.size(); i++) { 00276 out_MaxBackDegree<<", "<<Orderings[i]; 00277 } 00278 out_MaxBackDegree<<endl; 00279 } 00280 00281 if(stat_flags["Graph_Stat"]) { 00282 out_Graph_Stat<<"Name,|V|,|E|,MaxDegree,MinDegree,AvgDegree"<<endl; 00283 } 00284 00285 for(unsigned int i=0;i < listOfGraphs.size(); i++){ 00286 printListOfGraphs(listOfGraphs,i); 00287 00288 for(int j=0;j < Colorings.size();j++) { 00289 cout<<Colorings[j]<<" Coloring"<<endl<<flush; 00290 if(stat_flags["NumberOfColors"]) out_NumberOfColors<<Colorings[j]<<", "; 00291 if(stat_flags["Time"]) out_Time<<Colorings[j]<<", "; 00292 00293 File stat_file_parsor; 00294 stat_file_parsor.Parse(listOfGraphs[i]); 00295 if(stat_flags["NumberOfColors"]) out_NumberOfColors<<stat_file_parsor.GetName(); 00296 if(stat_flags["Time"]) out_Time<<stat_file_parsor.GetName(); 00297 if(stat_flags["MaxBackDegree"] && j == 0) out_MaxBackDegree<<stat_file_parsor.GetName(); 00298 00299 for(int k=0;k < Orderings.size();k++) { 00300 current_time(); 00301 00302 cout<<Orderings[k]<<" Ordering"<<endl<<flush; 00303 00304 GraphColoringInterface * gGraph = new GraphColoringInterface(SRC_FILE,listOfGraphs[i].c_str(), "AUTO_DETECTED"); 00305 gGraph->Coloring(Orderings[k], Colorings[j] ); 00306 00307 /* 00308 if(Colorings[j] == "ACYCLIC") { 00309 int result = gGraph->CheckAcyclicColoring(); 00310 if(result) { 00311 cout<<"gGraph->CheckAcyclicColoring() fail. Violation count = "<<result; 00312 } 00313 else { 00314 cout<<"gGraph->CheckAcyclicColoring() success. Violation count = "<<result; 00315 } 00316 } 00317 //*/ 00318 if(Colorings[j] == "STAR") { 00319 if(gGraph->GraphColoring::CheckStarColoring()) { 00320 cout<<"CheckStarColoring(): problem found"<<endl; 00321 exit(1); 00322 } else { 00323 cout<<"CheckStarColoring(): no problem found"<<endl; 00324 } 00325 00326 } 00327 00328 00329 if(stat_flags["NumberOfColors"]) out_NumberOfColors<<","<<gGraph->GetVertexColorCount()<<flush; 00330 if(stat_flags["Time"]) out_Time<<","<<gGraph->GetVertexOrderingTime()<<","<<gGraph->GetVertexColoringTime()<<","<<gGraph->GetVertexColoringTime()+gGraph->GetVertexOrderingTime()<<flush; 00331 00332 // Only get MaxBackDegree of one coloring 00333 if(j == 0) { 00334 if(stat_flags["MaxBackDegree"]) { 00335 cout<<"GetMaxBackDegree ... MaxBackDegree = "<<flush; 00336 00337 int MaxBackDegree = gGraph->GetMaxBackDegree(); 00338 out_MaxBackDegree<<","<<MaxBackDegree<<flush; 00339 cout<<MaxBackDegree<<endl; 00340 } 00341 00342 //populate Graph_Stat, done once for each graph 00343 if(stat_flags["Graph_Stat"] && k == 0) { 00344 out_Graph_Stat<<stat_file_parsor.GetName(); 00345 out_Graph_Stat<<","<<gGraph->GetVertexCount(); 00346 out_Graph_Stat<<","<<gGraph->GetEdgeCount(); 00347 out_Graph_Stat<<","<<gGraph->GetMaximumVertexDegree(); 00348 out_Graph_Stat<<","<<gGraph->GetMinimumVertexDegree(); 00349 out_Graph_Stat<<","<<gGraph->GetAverageVertexDegree(); 00350 out_Graph_Stat<<endl<<flush; 00351 } 00352 } 00353 00354 cout<<endl<<" DONE"<<endl; 00355 delete gGraph; 00356 } 00357 00358 if(stat_flags["NumberOfColors"]) out_NumberOfColors<<endl; 00359 if(stat_flags["Time"]) out_Time<<endl; 00360 if(stat_flags["MaxBackDegree"] && j == 0) out_MaxBackDegree<<endl; 00361 } 00362 00363 cout<<"***Finish 1 graph"<<endl<<endl<<endl; 00364 00365 if(stat_flags["refresh_list"]) { 00366 listOfGraphs = getListOfGraphs(baseDir+"listOfGraphs.txt"); 00367 } 00368 } 00369 00370 if(stat_flags["NumberOfColors"]) out_NumberOfColors.close(); 00371 if(stat_flags["Time"]) out_Time.close(); 00372 if(stat_flags["MaxBackDegree"]) out_MaxBackDegree.close(); 00373 if(stat_flags["Graph_Stat"]) out_Graph_Stat.close(); 00374 } 00375 00376 00377 void toFileStatisticForGraph(string baseDir, string stat_output_suffix , map<string, bool> stat_flags ) 00378 { 00379 ofstream out_Graph_Stat; 00380 vector <string> listOfGraphs = getListOfGraphs(baseDir+"listOfGraphs.txt"); 00381 00382 if(stat_flags["output_append"]) { 00383 out_Graph_Stat.open((baseDir+"Graph_Stat"+stat_output_suffix+".csv").c_str(),ios::app); 00384 out_Graph_Stat<<endl<<endl; 00385 } 00386 else { 00387 out_Graph_Stat.open((baseDir+"Graph_Stat"+stat_output_suffix+".csv").c_str()); 00388 } 00389 00390 //Title 00391 out_Graph_Stat<<"Name,|V|,|E|,MaxDegree,MinDegree,AvgDegree"<<endl; 00392 00393 for(unsigned int i=0;i < listOfGraphs.size(); i++){ 00394 00395 current_time(); 00396 00397 cout<<"Graph: "<<listOfGraphs[i]<<endl; 00398 //system("pause"); 00399 00400 GraphColoringInterface * gGraph = new GraphColoringInterface(SRC_FILE, listOfGraphs[i].c_str(), "AUTO_DETECTED"); 00401 00402 //gGraph->PrintGraphStructure(); 00403 00404 File stat_file_parsor; 00405 stat_file_parsor.Parse(listOfGraphs[i]); 00406 out_Graph_Stat<<stat_file_parsor.GetName(); 00407 out_Graph_Stat<<","<<gGraph->GetVertexCount(); 00408 out_Graph_Stat<<","<<gGraph->GetEdgeCount(); 00409 out_Graph_Stat<<","<<gGraph->GetMaximumVertexDegree(); 00410 out_Graph_Stat<<","<<gGraph->GetMinimumVertexDegree(); 00411 out_Graph_Stat<<","<<gGraph->GetAverageVertexDegree(); 00412 out_Graph_Stat<<endl<<flush; 00413 00414 delete gGraph; 00415 cout<<"***Finish 1 graph"<<endl<<endl<<endl; 00416 00417 if(stat_flags["refresh_list"]) { 00418 listOfGraphs = getListOfGraphs(baseDir+"listOfGraphs.txt"); 00419 } 00420 } 00421 00422 out_Graph_Stat.close(); 00423 } 00424 00425 void toFileStatisticForBipartiteGraph(string baseDir, string stat_output_suffix, map<string, bool> stat_flags ) 00426 { 00427 ofstream out_Graph_Stat; 00428 vector <string> listOfGraphs = getListOfGraphs(baseDir+"listOfGraphs.txt"); 00429 00430 if( stat_flags["output_append"] ) { 00431 out_Graph_Stat.open((baseDir+"BiGraph_Stat"+stat_output_suffix+".csv").c_str(),ios::app); 00432 out_Graph_Stat<<endl<<endl; 00433 } 00434 else { 00435 out_Graph_Stat.open((baseDir+"BiGraph_Stat"+stat_output_suffix+".csv").c_str()); 00436 } 00437 00438 //Title 00439 out_Graph_Stat<<"Name,|E|,Density,Col|V|,ColMax,ColMin,ColAvg,Row|V|,RowMax,RowMin,RowAvg"<<endl; 00440 00441 for(unsigned int i=0;i < listOfGraphs.size(); i++){ 00442 00443 current_time(); 00444 00445 cout<<"Graph: "<<listOfGraphs[i]<<endl; 00446 //system("pause"); 00447 00448 //readBipartiteGraph(gGraph, listOfGraphs[i]); 00449 BipartiteGraphBicoloringInterface * gGraph = new BipartiteGraphBicoloringInterface(SRC_FILE, listOfGraphs[i].c_str(), "AUTO_DETECTED"); 00450 00451 //gGraph->PrintBipartiteGraph(); 00452 00453 File stat_file_parsor; 00454 stat_file_parsor.Parse(listOfGraphs[i]); 00455 out_Graph_Stat<<stat_file_parsor.GetName(); 00456 out_Graph_Stat<<","<<gGraph->GetEdgeCount(); 00457 out_Graph_Stat<<","<<((double)gGraph->GetEdgeCount())/(gGraph->GetColumnVertexCount()*gGraph->GetRowVertexCount()); 00458 out_Graph_Stat<<","<<gGraph->GetColumnVertexCount(); 00459 out_Graph_Stat<<","<<gGraph->GetMaximumColumnVertexDegree(); 00460 out_Graph_Stat<<","<<gGraph->GetMinimumColumnVertexDegree(); 00461 out_Graph_Stat<<","<<gGraph->GetAverageColumnVertexDegree(); 00462 out_Graph_Stat<<","<<gGraph->GetRowVertexCount(); 00463 out_Graph_Stat<<","<<gGraph->GetMaximumRowVertexDegree(); 00464 out_Graph_Stat<<","<<gGraph->GetMinimumRowVertexDegree(); 00465 out_Graph_Stat<<","<<gGraph->GetAverageRowVertexDegree(); 00466 out_Graph_Stat<<endl<<flush; 00467 00468 delete gGraph; 00469 cout<<"***Finish 1 graph"<<endl<<endl<<endl; 00470 00471 if( stat_flags["refresh_list"] ) { 00472 listOfGraphs = getListOfGraphs(baseDir+"listOfGraphs.txt"); 00473 } 00474 } 00475 00476 out_Graph_Stat.close(); 00477 } 00478 00479 void printListOfGraphs(vector <string>& listOfGraphs, int selected) { 00480 for(int i=0; i<listOfGraphs.size();i++) { 00481 if(i!=selected) cout<<" Graph: "<<listOfGraphs[i]<<endl; 00482 else cout<<"=>Graph: "<<listOfGraphs[i]<<endl; 00483 } 00484 } 00485 00486 void toFileBiC(string baseDir, string stat_output_suffix , vector<string> Orderings, vector<string> Colorings, map<string, bool> stat_flags ) 00487 { 00488 ofstream out_NumberOfColors, out_Time; 00489 vector <string> listOfGraphs = getListOfGraphs(baseDir+"listOfGraphs.txt"); 00490 00491 // ****************************************************** 00492 // Open appropriate output stream 00493 if( stat_flags["output_append"] ) { 00494 if(stat_flags["NumberOfColors"]) { 00495 cout<<"NumberOfColors: Append to "<<(baseDir+"NumberOfColors"+"-BiColoring"+stat_output_suffix+".csv")<<endl; 00496 out_NumberOfColors.open((baseDir+"NumberOfColors"+"-BiColoring"+stat_output_suffix+".csv").c_str(),ios::app); 00497 out_NumberOfColors<<endl<<endl; 00498 } 00499 00500 if(stat_flags["Time"]) { 00501 cout<<"Time: Append to "<<(baseDir+"Time"+"-BiColoring"+stat_output_suffix+".csv")<<endl; 00502 out_Time.open((baseDir+"Time"+"-BiColoring"+stat_output_suffix+".csv").c_str(),ios::app); 00503 out_Time<<endl<<endl; 00504 } 00505 } 00506 else { 00507 if(stat_flags["NumberOfColors"]) { 00508 cout<<"NumberOfColors: Write to "<<(baseDir+"NumberOfColors"+"-BiColoring"+stat_output_suffix+".csv")<<endl; 00509 out_NumberOfColors.open((baseDir+"NumberOfColors"+"-BiColoring"+stat_output_suffix+".csv").c_str()); 00510 } 00511 00512 if(stat_flags["Time"]) { 00513 cout<<"Time: Write to "<<(baseDir+"Time"+"-BiColoring"+stat_output_suffix+".csv")<<endl; 00514 out_Time.open((baseDir+"Time"+"-BiColoring"+stat_output_suffix+".csv").c_str()); 00515 } 00516 } 00517 00518 // ****************************************************** 00519 // Create titles 00520 if(stat_flags["NumberOfColors"]) { 00521 out_NumberOfColors<<"Style, Name"; 00522 for(int i=0; i< Orderings.size(); i++) { 00523 out_NumberOfColors<<", "<<Orderings[i]<<", , "; 00524 } 00525 out_NumberOfColors<<endl; 00526 00527 // line 2 00528 out_NumberOfColors<<","; 00529 for(int i=0; i< Orderings.size(); i++) { 00530 out_NumberOfColors<<", LEFT, RIGHT, TOTAL"; 00531 } 00532 out_NumberOfColors<<endl; 00533 } 00534 00535 if(stat_flags["Time"]) { 00536 // line 1 00537 out_Time<<"Style,Name"; 00538 for(int i=0; i< Orderings.size(); i++) { 00539 out_Time<<", "<<Orderings[i]<<", , "; 00540 } 00541 out_Time<<endl; 00542 00543 // line 2 00544 out_Time<<","; 00545 for(int i=0; i< Orderings.size(); i++) { 00546 out_Time<<", OT, CT, TT"; 00547 } 00548 out_Time<<endl; 00549 } 00550 00551 for(unsigned int i=0;i < listOfGraphs.size(); i++){ 00552 printListOfGraphs(listOfGraphs,i); 00553 00554 for(int j=0;j<Colorings.size();j++) 00555 { 00556 cout<<Colorings[j]<<" Coloring"<<endl<<flush; 00557 if(stat_flags["NumberOfColors"]) out_NumberOfColors<<Colorings[j]<<", "; 00558 if(stat_flags["Time"]) out_Time<<Colorings[j]<<", "; 00559 00560 File stat_file_parsor; 00561 stat_file_parsor.Parse(listOfGraphs[i]); 00562 if(stat_flags["NumberOfColors"]) out_NumberOfColors<<stat_file_parsor.GetName(); 00563 if(stat_flags["Time"]) out_Time<<stat_file_parsor.GetName(); 00564 00565 for (int k=0; k<Orderings.size(); k++) 00566 { 00567 current_time(); 00568 00569 cout<<Orderings[k]<<" Ordering"<<endl<<flush; 00570 00571 //readBipartiteGraph(gGraph, listOfGraphs[i]); 00572 BipartiteGraphBicoloringInterface * gGraph = new BipartiteGraphBicoloringInterface(SRC_FILE, listOfGraphs[i].c_str(), "AUTO_DETECTED"); 00573 gGraph->Bicoloring(Orderings[k], Colorings[j]); 00574 00575 if(stat_flags["NumberOfColors"]) out_NumberOfColors<<","<<gGraph->GetLeftVertexColorCount()<<","<<gGraph->GetRightVertexColorCount()<<","<<gGraph->GetVertexColorCount()<<flush; 00576 if(stat_flags["Time"]) out_Time<<','<<gGraph->GetVertexOrderingTime()<<','<<gGraph->GetVertexColoringTime()<<','<<gGraph->GetVertexOrderingTime() + gGraph->GetVertexColoringTime()<<flush; 00577 00578 //system("pause"); 00579 //break; 00580 00581 cout<<endl<<" DONE"<<endl; 00582 delete gGraph; 00583 } 00584 00585 if(stat_flags["NumberOfColors"]) out_NumberOfColors<<endl; 00586 if(stat_flags["Time"]) out_Time<<endl; 00587 } 00588 cout<<"***Finish 1 graph"<<endl<<endl<<endl; 00589 00590 if(stat_flags["refresh_list"]) { 00591 listOfGraphs = getListOfGraphs(baseDir+"listOfGraphs.txt"); 00592 } 00593 } 00594 00595 if(stat_flags["NumberOfColors"]) out_NumberOfColors.close(); 00596 if(stat_flags["Time"]) out_Time.close(); 00597 } 00598 00599 00600 void toFileBiPC(string baseDir, string stat_output_suffix, vector<string> Orderings, vector<string> Colorings, map<string, bool> stat_flags ) 00601 { 00602 ofstream out_NumberOfColors, out_Time; 00603 vector <string> listOfGraphs = getListOfGraphs(baseDir+"listOfGraphs.txt"); 00604 00605 // ****************************************************** 00606 // Open appropriate output stream 00607 if( stat_flags["output_append"] ) { 00608 if(stat_flags["NumberOfColors"]) { 00609 cout<<"NumberOfColors: Append to "<<(baseDir+"NumberOfColors"+"-PD2Coloring"+stat_output_suffix+".csv")<<endl; 00610 out_NumberOfColors.open((baseDir+"NumberOfColors"+"-PD2Coloring"+stat_output_suffix+".csv").c_str(),ios::app); 00611 out_NumberOfColors<<endl<<endl; 00612 } 00613 00614 if(stat_flags["Time"]) { 00615 cout<<"Time: Append to "<<(baseDir+"Time"+"-PD2Coloring"+stat_output_suffix+".csv")<<endl; 00616 out_Time.open((baseDir+"Time"+"-PD2Coloring"+stat_output_suffix+".csv").c_str(),ios::app); 00617 out_Time<<endl<<endl; 00618 } 00619 } 00620 else { 00621 if(stat_flags["NumberOfColors"]) { 00622 cout<<"NumberOfColors: Write to "<<(baseDir+"NumberOfColors"+"-PD2Coloring"+stat_output_suffix+".csv")<<endl; 00623 out_NumberOfColors.open((baseDir+"NumberOfColors"+"-PD2Coloring"+stat_output_suffix+".csv").c_str()); 00624 } 00625 00626 if(stat_flags["Time"]) { 00627 cout<<"Time: Write to "<<(baseDir+"Time"+"-PD2Coloring"+stat_output_suffix+".csv")<<endl; 00628 out_Time.open((baseDir+"Time"+"-PD2Coloring"+stat_output_suffix+".csv").c_str()); 00629 } 00630 } 00631 00632 // ****************************************************** 00633 // Create titles 00634 if(stat_flags["NumberOfColors"]) { 00635 out_NumberOfColors<<"Style, Name"; 00636 for(int i=0; i< Orderings.size(); i++) { 00637 out_NumberOfColors<<", "<<Orderings[i]; 00638 } 00639 out_NumberOfColors<<endl; 00640 } 00641 00642 if(stat_flags["Time"]) { 00643 // line 1 00644 out_Time<<"Style,Name"; 00645 for(int i=0; i< Orderings.size(); i++) { 00646 out_Time<<", "<<Orderings[i]<<", , "; 00647 } 00648 out_Time<<endl; 00649 00650 // line 2 00651 out_Time<<","; 00652 for(int i=0; i< Orderings.size(); i++) { 00653 out_Time<<", OT, CT, TT"; 00654 } 00655 out_Time<<endl; 00656 } 00657 00658 for(unsigned int i=0;i < listOfGraphs.size(); i++){ 00659 printListOfGraphs(listOfGraphs,i); 00660 00661 for(int j=0;j<Colorings.size();j++) 00662 { 00663 cout<<Colorings[j]<<" Coloring"<<endl<<flush; 00664 if(stat_flags["NumberOfColors"]) out_NumberOfColors<<Colorings[j]<<", "; 00665 if(stat_flags["Time"]) out_Time<<Colorings[j]<<", "; 00666 00667 File stat_file_parsor; 00668 stat_file_parsor.Parse(listOfGraphs[i]); 00669 if(stat_flags["NumberOfColors"]) out_NumberOfColors<<stat_file_parsor.GetName(); 00670 if(stat_flags["Time"]) out_Time<<stat_file_parsor.GetName(); 00671 00672 for (int k=0; k<Orderings.size(); k++) { 00673 current_time(); 00674 00675 cout<<Orderings[k]<<" Ordering"<<endl<<flush; 00676 00677 BipartiteGraphPartialColoringInterface * gGraph = new BipartiteGraphPartialColoringInterface(SRC_FILE, listOfGraphs[i].c_str(), "AUTO_DETECTED"); 00678 gGraph->PartialDistanceTwoColoring(Orderings[k], Colorings[j] ); 00679 00680 if(stat_flags["NumberOfColors"]) { 00682 if(j==0) out_NumberOfColors<<','<<gGraph->GetRightVertexColorCount(); 00683 else out_NumberOfColors<<','<<gGraph->GetLeftVertexColorCount(); 00684 } 00685 if(stat_flags["Time"]) out_Time<<','<<gGraph->GetVertexOrderingTime()<<','<<gGraph->GetVertexColoringTime()<<','<<gGraph->GetVertexOrderingTime()+gGraph->GetVertexColoringTime(); 00686 00687 cout<<endl<<" DONE"<<endl; 00688 delete gGraph; 00689 } 00690 00691 if(stat_flags["NumberOfColors"]) out_NumberOfColors<<endl; 00692 if(stat_flags["Time"]) out_Time<<endl; 00693 } 00694 00695 cout<<"Finish 1 graph"<<endl; 00696 00697 if(stat_flags["refresh_list"]) { 00698 listOfGraphs = getListOfGraphs(baseDir+"listOfGraphs.txt"); 00699 } 00700 } 00701 00702 if(stat_flags["NumberOfColors"]) out_NumberOfColors.close(); 00703 if(stat_flags["Time"]) out_Time.close(); 00704 }