comparison defical-c/src/main.cpp @ 0:ebed2bd0d300

Initial import from svn. History be damned.
author Edho P. Arief <me@myconan.net>
date Fri, 02 Apr 2010 23:11:57 +0700
parents
children 758381a85d76
comparison
equal deleted inserted replaced
-1:000000000000 0:ebed2bd0d300
1 #include "main.h"
2
3 const uint32_t INTMAX=100000;
4 const char separator[40]= "=======================================";
5
6 int main(int argc, const char *argv[])
7 {
8 uint32_t numVer,numDef,graphType,isAllI;
9 int32_t start,end;
10 string graphTypeS,algorithm;
11 bool isAll;
12 //defaults
13 numVer=numDef=isAllI=INTMAX;
14 isAllI=1;
15 isAll=false;
16 graphTypeS="x";
17 algorithm="x";
18 //end defaults
19 dsr::Argument_helper ah;
20 ah.set_author("Edho Prima Arief <me@myconan.net>");
21 ah.set_description("Calculates deficiency for various graphs.");
22 ah.set_build_date("2009");
23 ah.set_name("defical");
24 ah.set_version("0.1");
25 ah.new_named_unsigned_int('n',"numver","","Number of vertices.",numVer);
26 ah.new_named_unsigned_int('d',"numdef","","Number of deficiencies.",numDef);
27 ah.new_named_string('g',"graph","","Type of graph.",graphTypeS);
28 ah.new_named_string('a',"algorithm","","Choice of algorithm.",algorithm);
29 ah.new_named_unsigned_int('c',"complete","","Don't stop on found.",isAllI);
30 ah.process(argc,argv);
31 if(isAllI==1)
32 isAll=true;
33 if(graphTypeS=="wheel")
34 graphType=3;
35 else if(graphTypeS=="fan")
36 graphType=4;
37 else if(graphTypeS=="doublefan")
38 graphType=5;
39 else
40 {
41 printf("Invalid graph type. Accepted: wheel, fan, doublefan.\n");
42 return 1;
43 }
44 if(numVer<5 || numVer>=INTMAX)
45 {
46 printf("Number of vertices must be more than 5 (or less than %d).\n",INTMAX);
47 return 1;
48 }
49 if(numDef>=INTMAX)
50 {
51 printf("Ha ha ha funny. Just give up (number of deficiencies must be less than %d.\n",INTMAX);
52 return 1;
53 }
54 if(algorithm!="backtrack")
55 {
56 printf("Invalid algorithm specified.\n");
57 return 1;
58 }
59 printf(separator);
60 printf("\nNumber of vertices: %d\n",numVer);
61 printf("Number of deficiencies: %d\n",numDef);
62 cout << "Graph type: " << graphTypeS << endl;
63 cout << "Algorithm: " << algorithm << endl;
64 cout << separator << endl;
65 gettime *mytime=new gettime();
66 cout << "[I] " << mytime->time_v << ": Started" << endl;
67 cout << separator << endl;
68 if(algorithm=="backtrack")
69 {
70 start=1;
71 end=(numVer+numDef+1)/2;
72 bool isFinished=false;
73 #ifdef _OPENMP
74 #pragma omp parallel for num_threads(3)
75 #endif
76 for(int32_t i=start;i<=end;i++){
77 if(!isFinished){
78 bt::backtrack *bt1=new bt::backtrack(graphType,numVer,numDef,i,isAll);
79 bt1->Walk();
80 if(!isFinished)
81 {
82 if(bt1->IsSemt)
83 {
84 if(!isAll)
85 isFinished=true;
86 gettime *mytime=new gettime();
87 printf("[F] %s: Found\n%s\n%s%s\n",mytime->time_v,separator,bt1->Result.c_str(),separator);
88 bt1->IsSemt=false;
89 }
90 else {
91 if(!isFinished)
92 {
93 gettime *mytime=new gettime();
94 printf("[N] %s: Unable to construct with first label %d\n",mytime->time_v,i);
95 }
96 }
97 }
98 }
99 }
100 }
101 return 0;
102 }