Mercurial > defical
diff 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 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/defical-c/src/main.cpp Fri Apr 02 23:11:57 2010 +0700 @@ -0,0 +1,102 @@ +#include "main.h" + +const uint32_t INTMAX=100000; +const char separator[40]= "======================================="; + +int main(int argc, const char *argv[]) +{ + uint32_t numVer,numDef,graphType,isAllI; + int32_t start,end; + string graphTypeS,algorithm; + bool isAll; + //defaults + numVer=numDef=isAllI=INTMAX; + isAllI=1; + isAll=false; + graphTypeS="x"; + algorithm="x"; + //end defaults + dsr::Argument_helper ah; + ah.set_author("Edho Prima Arief <me@myconan.net>"); + ah.set_description("Calculates deficiency for various graphs."); + ah.set_build_date("2009"); + ah.set_name("defical"); + ah.set_version("0.1"); + ah.new_named_unsigned_int('n',"numver","","Number of vertices.",numVer); + ah.new_named_unsigned_int('d',"numdef","","Number of deficiencies.",numDef); + ah.new_named_string('g',"graph","","Type of graph.",graphTypeS); + ah.new_named_string('a',"algorithm","","Choice of algorithm.",algorithm); + ah.new_named_unsigned_int('c',"complete","","Don't stop on found.",isAllI); + ah.process(argc,argv); + if(isAllI==1) + isAll=true; + if(graphTypeS=="wheel") + graphType=3; + else if(graphTypeS=="fan") + graphType=4; + else if(graphTypeS=="doublefan") + graphType=5; + else + { + printf("Invalid graph type. Accepted: wheel, fan, doublefan.\n"); + return 1; + } + if(numVer<5 || numVer>=INTMAX) + { + printf("Number of vertices must be more than 5 (or less than %d).\n",INTMAX); + return 1; + } + if(numDef>=INTMAX) + { + printf("Ha ha ha funny. Just give up (number of deficiencies must be less than %d.\n",INTMAX); + return 1; + } + if(algorithm!="backtrack") + { + printf("Invalid algorithm specified.\n"); + return 1; + } + printf(separator); + printf("\nNumber of vertices: %d\n",numVer); + printf("Number of deficiencies: %d\n",numDef); + cout << "Graph type: " << graphTypeS << endl; + cout << "Algorithm: " << algorithm << endl; + cout << separator << endl; + gettime *mytime=new gettime(); + cout << "[I] " << mytime->time_v << ": Started" << endl; + cout << separator << endl; + if(algorithm=="backtrack") + { + start=1; + end=(numVer+numDef+1)/2; + bool isFinished=false; +#ifdef _OPENMP +#pragma omp parallel for num_threads(3) +#endif + for(int32_t i=start;i<=end;i++){ + if(!isFinished){ + bt::backtrack *bt1=new bt::backtrack(graphType,numVer,numDef,i,isAll); + bt1->Walk(); + if(!isFinished) + { + if(bt1->IsSemt) + { + if(!isAll) + isFinished=true; + gettime *mytime=new gettime(); + printf("[F] %s: Found\n%s\n%s%s\n",mytime->time_v,separator,bt1->Result.c_str(),separator); + bt1->IsSemt=false; + } + else { + if(!isFinished) + { + gettime *mytime=new gettime(); + printf("[N] %s: Unable to construct with first label %d\n",mytime->time_v,i); + } + } + } + } + } + } + return 0; +}