ColPack
|
00001 // An example for using GraphColoringInterface to color Graph 00002 /* 00003 How to compile this driver manually: 00004 Please make sure that "baseDir" point to the directory (folder) containing the input matrix file, and 00005 s_InputFile should point to the input file that you want to use 00006 To compile the code, replace the Main.cpp file in Main directory with this file 00007 and run "make" in ColPack installation directory. Make will generate "ColPack.exe" executable 00008 Run "ColPack.exe" 00009 00010 Note: If you got "symbol lookup error ... undefined symbol " 00011 Please make sure that your LD_LIBRARY_PATH contains libColPack.so 00012 00013 Any time you have trouble understanding what a routine does, how to use a routine, or what are the accepted values for a parameter, 00014 please reference the COLPACK's online documentation (temporarily located at 00015 http://www.cscapes.org/dox/ColPack/html/ ). 00016 00017 For more information, please visit our webpage http://www.cscapes.org/coloringpage/ 00018 //*/ 00019 00020 #include "ColPackHeaders.h" 00021 00022 using namespace ColPack; 00023 using namespace std; 00024 00025 #ifndef TOP_DIR 00026 #define TOP_DIR "." 00027 #endif 00028 00029 // baseDir should point to the directory (folder) containing the input file 00030 string baseDir=TOP_DIR; 00031 00032 //* A SHORT VERSION 00033 int main(int argc, char ** argv) 00034 { 00035 // s_InputFile = baseDir + <name of the input file> 00036 string s_InputFile; //path of the input file. PICK A SYMMETRIC MATRIX!!! 00037 s_InputFile = baseDir; 00038 s_InputFile += DIR_SEPARATOR; s_InputFile += "Graphs"; s_InputFile += DIR_SEPARATOR; s_InputFile += "mtx-spear-head.mtx"; 00039 00040 //Generate and color the graph 00041 GraphColoringInterface * g = new GraphColoringInterface(SRC_FILE, s_InputFile.c_str(), "AUTO_DETECTED"); 00042 00043 //Color the bipartite graph with the specified ordering 00044 g->Coloring("LARGEST_FIRST", "DISTANCE_TWO"); 00045 00046 /*Done with coloring. Below are possible things that you may 00047 want to do after coloring: 00048 //*/ 00049 00050 /* 1. Check DISTANCE_TWO coloring result 00051 cout<<"Check DISTANCE_TWO coloring result"<<endl; 00052 g->CheckDistanceTwoColoring(); 00053 Pause(); 00054 //*/ 00055 00056 //* 2. Print coloring results 00057 g->PrintVertexColoringMetrics(); 00058 Pause(); 00059 //*/ 00060 00061 //* 3. Get the list of colorID of vertices 00062 vector<int> vi_VertexColors; 00063 g->GetVertexColors(vi_VertexColors); 00064 00065 //Display vector of VertexColors 00066 printf("vector of VertexColors (size %d) \n", (int)vi_VertexColors.size()); 00067 displayVector(&vi_VertexColors[0], vi_VertexColors.size(), 1); 00068 Pause(); 00069 //*/ 00070 00071 /* 4. Get seed matrix 00072 int i_SeedRowCount = 0; 00073 int i_SeedColumnCount = 0; 00074 double** Seed = g->GetSeedMatrix(&i_SeedRowCount, &i_SeedColumnCount); 00075 00076 //Display Seed 00077 printf("Seed matrix %d x %d \n", i_SeedRowCount, i_SeedColumnCount); 00078 displayMatrix(Seed, i_SeedRowCount, i_SeedColumnCount, 1); 00079 Pause(); 00080 //*/ 00081 00082 delete g; 00083 return 0; 00084 } 00085 //*/ 00086 00087 /* A LONGER VERSION showing steps actually executed by the constructor. 00088 int main(int argc, char ** argv) 00089 { 00090 // s_InputFile = baseDir + <name of the input file> 00091 string s_InputFile; //path of the input file. PICK A SYMMETRIC MATRIX!!! 00092 s_InputFile = baseDir + "bcsstk01_symmetric\\bcsstk01_symmetric.mtx"; 00093 GraphColoringInterface * g = new GraphColoringInterface(); 00094 00095 //Read a matrix from an input file and generate a corresponding graph. 00096 //The input format will be determined based on the file extension and a correct reading routine will be used to read the file. 00097 //Note: the input matrix MUST be SYMMETRIC in order for a graph to be generated correctly 00098 // If you are new to COLPACK, pick either a .graph file (MeTiS format) or a symmetric .mtx (Matrix Market format) 00099 if ( g->ReadAdjacencyGraph(s_InputFile) == _FALSE) { 00100 cout<<"ReadAdjacencyGraph() Failed!!!"<<endl; 00101 return _FALSE; 00102 } 00103 cout<<"Done with ReadAdjacencyGraph()"<<endl; 00104 //Pause(); 00105 00106 //(Distance-2)Color the graph using "LARGEST_FIRST" Ordering. Other coloring and ordering can also be used. 00107 g->Coloring("DISTANCE_TWO", "LARGEST_FIRST"); 00108 cout<<"Done with Coloring()"<<endl; 00109 //Pause(); 00110 00111 //Print coloring results 00112 g->PrintVertexColoringMetrics(); 00113 cout<<"Done with PrintVertexColoringMetrics()"<<endl; 00114 delete g; 00115 //Pause(); 00116 00117 return _TRUE; 00118 } 00119 //*/