File: Main.cpp

package info (click to toggle)
colpack 1.0.10-8
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 10,704 kB
  • sloc: cpp: 49,807; ansic: 1,231; makefile: 419; sh: 13
file content (264 lines) | stat: -rw-r--r-- 10,377 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
#include "ColPackHeaders.h"
#include <cstring>
#include <unordered_set>
using namespace ColPack;
void usage();
void general_coloring(int argc, char* argv[]);
void partial_coloring(int argc, char* argv[]);
void bicoloring(int argc, char* argv[]);


const unordered_set<string> GENERAL_COLORING({
        "DISTANCE_ONE", 
        "ACYCLIC", 
        "ACYCLIC_FOR_INDIRECT_RECOVERY", 
        "STAR", 
        "RESTRICTED_STAR", 
        "DISTANCE_TWO"});
const unordered_set<string> BICOLORING({
        "IMPLICIT_COVERING__STAR_BICOLORING",
        "EXPLICIT_COVERING__STAR_BICOLORING",
        "EXPLICIT_COVERING__MODIFIED_STAR_BICOLORING",
        "IMPLICIT_COVERING__GREEDY_STAR_BICOLORING"});
const unordered_set<string> PARTIAL_COLORING({
        "COLUMN_PARTIAL_DISTANCE_TWO",
        "ROW_PARTIAL_DISTANCE_TWO"});


int main(int argc, char* argv[]) {
    string method="";
    for(int i=1; i<argc; i++){
        if( !strcmp(argv[i],"-m")) {
            method = argv[++i]; break;
        }
    }
    if(      GENERAL_COLORING.count(method) ) 
        general_coloring(argc, argv);
    else if( PARTIAL_COLORING.count(method) ) 
        partial_coloring(argc, argv);
    else if( BICOLORING.count(method)       ) 
        bicoloring(argc,argv);
    else{
        usage();
        exit(1);
    }
    return 0;
}



void general_coloring(int argc, char* argv[]){
    vector<string> fnames;
    vector<string> methds;
    vector<string> orders(1,"RANDOM"); 
    bool   bVerbose(false);
    for(int i=1; i<argc; i++){
        if( !strcmp(argv[i], "-f") ){
            for(int j=i+1; j<argc; j++, i++){
                if(argv[j][0]=='-') break;
                fnames.push_back( argv[j]);
            }
        }
        else if(!strcmp(argv[i],"-m")){
            for(int j=i+1; j<argc; j++, i++){
                if(argv[j][0]=='-') break;
                if(GENERAL_COLORING.count(argv[j])) 
                    methds.push_back( argv[j]);
            }
        }
        else if(!strcmp(argv[i], "-o")){
            orders.clear();
            for(int j=i+1; j<argc; j++, i++){
                if(argv[j][0]=='-') break;
                orders.push_back( argv[j]);
            }
        }
        else if(!strcmp(argv[i],"-v")){
            bVerbose=true;
        }
        else{
            printf("\nWarning: unknown input argument\"%s\".\n", argv[i]);
        }
    }

    if (fnames.empty()) { usage(); exit(1); }
    for(auto fname : fnames){
        GraphColoringInterface *g = new GraphColoringInterface(SRC_FILE, fname.c_str(), "AUTO_DETECTED");
        for(auto m : methds){
            for(auto o : orders){
                if(bVerbose) printf("\ngraph: %s\norder: %s\nmethd: %s\nGeneral Graph Coloring\n",fname.c_str(), o.c_str(), m.c_str());
                g->Coloring(o.c_str(), m.c_str());
                if(bVerbose) {
                    double t1 = g->GetVertexOrderingTime();
                    double t2 = g->GetVertexColoringTime();
                    printf("order+color time = %f = %f+%f\n",t1+t2, t1,t2);
                    printf("number of colors: ");
                    printf("%d\n",g->GetVertexColorCount());
                }
                else {
                    printf("%d\n",g->GetVertexColorCount());
                }
            }
        }
        delete g;
    }
}


void partial_coloring(int argc, char* argv[]){
    vector<string> fnames;
    vector<string> methds;
    vector<string> orders; 
    bool   bVerbose(false);

    for(int i=1; i<argc; i++){
        if( !strcmp(argv[i], "-f") ){
            for(int j=i+1; j<argc; j++, i++){
                if(argv[j][0]=='-') break;
                fnames.push_back( argv[j]);
            }
        }
        else if(!strcmp(argv[i],"-m")){
            for(int j=i+1; j<argc; j++, i++){
                if(argv[j][0]=='-') break;
                if(PARTIAL_COLORING.count(argv[j])) 
                    methds.push_back( argv[j]);
            }
        }
        else if(!strcmp(argv[i], "-o")){
            for(int j=i+1; j<argc; j++, i++){
                if(argv[j][0]=='-') break;
                orders.push_back( argv[j]);
            }
        }
        else if(!strcmp(argv[i],"-v")){
            bVerbose=true;
        }
        else{
            printf("\nWarning: unknown input argument\"%s\".\n", argv[i]);
        }
    }   

    for(auto fname : fnames){
        BipartiteGraphPartialColoringInterface *g = new BipartiteGraphPartialColoringInterface(0, fname.c_str(), "AUTO_DETECTED");
        for(auto m : methds){
            for(auto o : orders){
                if(bVerbose) printf("\ngraph: %s\norder: %s\nmethd: %s\nPartial Distance Two Bipartite Graph Coloring\n",fname.c_str(), o.c_str(), m.c_str());
                g->PartialDistanceTwoColoring(o.c_str(), m.c_str());
                if(bVerbose) {
                    double t1 = g->GetVertexOrderingTime();
                    double t2 = g->GetVertexColoringTime();
                    printf("order+color time = %f = %f+%f\n",t1+t2, t1,t2);
                    printf("number of colors: ");
                    printf("%d\n",g->GetVertexColorCount());
                }
                else {
                    printf("%d\n",g->GetVertexColorCount());
                }
            }
        }
        delete g;
    }
    return;
}
 


void bicoloring(int argc, char* argv[]){
    vector<string> fnames;
    vector<string> methds;
    vector<string> orders; 
    bool   bVerbose(false);

    for(int i=1; i<argc; i++){
        if( !strcmp(argv[i], "-f") ){
            for(int j=i+1; j<argc; j++, i++){
                if(argv[j][0]=='-') break;
                fnames.push_back( argv[j]);
            }
        }
        else if(!strcmp(argv[i],"-m")){
            for(int j=i+1; j<argc; j++, i++){
                if(argv[j][0]=='-') break;
                if(BICOLORING.count(argv[j])) 
                    methds.push_back( argv[j]);
            }
        }
        else if(!strcmp(argv[i], "-o")){
            for(int j=i+1; j<argc; j++, i++){
                if(argv[j][0]=='-') break;
                orders.push_back( argv[j]);
            }
        }
        else if(!strcmp(argv[i],"-v")){
            bVerbose=true;
        }
        else{
            printf("\nWarning: unknown input argument\"%s\".\n", argv[i]);
        }
    }   

    for(auto fname : fnames){
        BipartiteGraphBicoloringInterface *g = new BipartiteGraphBicoloringInterface(0, fname.c_str(), "AUTO_DETECTED");

        for(auto m : methds){
            for(auto o : orders){
                if(bVerbose) printf("\ngraph: %s\norder: %s\nmethd: %s\nBiColoring Bipartite Graph Coloring\n",fname.c_str(), o.c_str(), m.c_str());
                g->Bicoloring(o.c_str(), m.c_str());
                if(bVerbose) {
                    double t1 = g->GetVertexOrderingTime();
                    double t2 = g->GetVertexColoringTime();
                    printf("order+color time = %f = %f+%f\n",t1+t2, t1,t2);
                    printf("number of colors: ");
                    printf("%d\n",g->GetVertexColorCount());
                }
                else {
                    printf("%d\n",g->GetVertexColorCount());
                }
            }
        }
        delete g;
    }
    return;
}
 


void usage(){
    fprintf(stderr, "\n"
            "NAME\n"
            "       ColPack - do graph coloring\n"
            "\n"
            "SYNOPISIS\n"
            "       ColPack [-f <list of graphs>] [-m <list of methods>] [-o <list of orders>] ...\n"
            "\n"
            "DESCRIPTION\n"
            "       the ColPack application shall take a list of commands and do the graph coloring. And display the results to the screen.\n"
            "       There are some specific commands for different methods. Find more details on 'https://github.com/ProbShin/ColPack'\n"
            "\n"
            "OPTIONS\n"
            "       the following options shall be supported:\n"
            "\n"
            "       -f files    Indicates the graph file path name.\n"
            "       -v          Indicates verbose flag will be truned on and there will display more rich infomration.\n" 
            "       -o orders   Indicates the orderings. Could be 'RANDOM','NATURAL','LARGEST_FIRST','SMALLEST_LAST','DYNAMIC_LARGEST_FIRST','INCIDENCE_DEGREE'... . There could be some specific ordering for specific methods\n"
            "       -m methods  Indicates the methods. Could be 'DISTANCE_ONE','ACYCLIC','STAR','DISTNACE_TWO','ROW_PARTIAL_DISTANCE_TWO','D1_OMP_GMMP','PD2_OMP_GMMP',...\n"
            "       -nT         Indicates number of threads used of parallel graph coloring\n"
            "       -side       Indiecate Row (L) or Column (R) side of coloring for parallel partial colroing.\n"
            "\n"
            "DESCRIPTION\n"
            "       if the method is one of 'DISTANCE_ONE','ACYCLIC','STAR','DISTANCE_TWO','ROW_PARTIAL_DISTANCE_TWO' The method belongs to gereral coloring on general graphs.\n" 
            "       if the method is one of 'ROW_PARTIAL_DISTANCE_TWO','COLUMN_PARTIAL_DISTANCE_TWO' The method belongs to partial coloring on bipartite graphs.\n" 
            "       if the method is one of 'IMPLICIT_COVERING__STAR_BICOLORING','EXPLICIT_COVERING__STAR_BICOLORING',EXPLICIT_COVERING__MODIFIED_STAR_BICOLORING','IMPLICIT_COVERING__GREEDY_STAR_BICOLORING'. The method belongs to bicoloring on bipartite graphs.\n" 
            "       if the method is one of 'D1_OMP_GM3P, D1_OMP_GM3P_LF, D1_OMP_GMMP, D1_OMP_GMMP_LF,D1_OMP_SERIAL, D1_OMP_SERIAL_LF, D1_OMP_JP, D1_OMP_JP_LF ,D1_OMP_MTJP, D1_OMP_MTJP_LF, D1_OMP_HBJP_GM3P, D1_OMP_HBJP_GM3P_.., D1_OMP_HBJP_GMMP.., D1_OMP_HBJP_.... ,D1_OMP_HBMTP_GM3P, D1_OMP_HBMTJP_GM3P_.., D1_OMP_HBMTJP_GMMP.., D1_OMP_HBMTJP_.... ,D2_OMP_GM3P, D2_OMP_GM3P_LF ,D2_OMP_GMMP, D2_OMP_GMMP_LF ,D2_OMP_SERIAL, D2_OMP_SERIAL_LF' the method belongs to parallel general graph coloring\n"
            "\n"
            "EXAMPLE\n"
            "./ColPack -f ../Graphs/bcsstk01.mtx -o LARGEST_FIRST RANDOM -m DISTANCE_ONE -v\n"
            "./ColPack -f ../Graphs/bcsstk01.mtx -o SMALLEST_LAST LARGEST_FIRST -m ACYCLIC -v\n"
            "./ColPack -f ../Graphs/bcsstk01.mtx -o RANDOM -m D1_OMP_GMMP -v -np 2\n"
            "./ColPack -f ../Graphs/bcsstk01.mtx -o RANDOM -m PD2_OMP_GMMP -v -np 4\n"
            "\n"
           ); 
}