support.cc
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "examples/support.hh"
00023
00024
00025
00026
00027
00028
00029 static const char* icl2str[] =
00030 { "val", "bnd", "dom", "def" };
00031
00032 static const char* em2str[] =
00033 { "solution", "time", "stat" };
00034
00035 static const char* bool2str[] =
00036 { "false", "true" };
00037
00038 void
00039 Options::parse(int argc, char** argv) {
00040 using namespace std;
00041 int i = 1;
00042 const char* e = NULL;
00043 while (i < argc) {
00044 if (!strcmp(argv[i],"-help") || !strcmp(argv[i],"--help")) {
00045 cerr << "Options for example " << name << ":"
00046 << endl
00047 << "\t-icl (def,val,bnd,dom) default: " << icl2str[icl]
00048 << endl
00049 << "\t\tinteger consistency level" << endl
00050 << "\t-c_d (unsigned int) default: " << c_d << endl
00051 << "\t\tcopying recomputation distance" << endl
00052 << "\t-a_d (unsigned int) default: " << a_d << endl
00053 << "\t\tadaption recomputation distance" << endl
00054 << "\t-mode (solution, time, stat) default: "
00055 << em2str[mode] << endl
00056 << "\t\twhether to print solutions, measure time, "
00057 << "or print statistics" << endl
00058 << "\t-samples (unsigned int) default: "
00059 << samples << endl
00060 << "\t\thow many samples (time-mode)" << endl
00061 << "\t-iterations (unsigned int) default: "
00062 << iterations << endl
00063 << "\t\thow many iterations per sample (time-mode)" << endl
00064 << "\t-solutions (unsigned int) default: ";
00065 if (solutions == 0)
00066 cerr << "all (0)";
00067 else
00068 cerr << solutions;
00069 cerr << endl
00070 << "\t\thow many solutions to search (solution-mode)" << endl
00071 << "\t-naive default: "
00072 << bool2str[naive] << endl
00073 << "\t\tuse naive version" << endl
00074 << "\t-smart default: "
00075 << bool2str[!naive] << endl
00076 << "\t\tuse smart version" << endl
00077 << "\t(unsigned int) default: " << size << endl
00078 << "\t\twhich version/size for example" << endl;
00079 exit(EXIT_SUCCESS);
00080 } else if (!strcmp(argv[i],"-icl")) {
00081 if (++i == argc) goto missing;
00082 if (!strcmp(argv[i],"def")) {
00083 icl = ICL_DEF;
00084 } else if (!strcmp(argv[i],"val")) {
00085 icl = ICL_VAL;
00086 } else if (!strcmp(argv[i],"bnd")) {
00087 icl = ICL_BND;
00088 } else if (!strcmp(argv[i],"dom")) {
00089 icl = ICL_DOM;
00090 } else {
00091 e = "expecting: def, val, bnd, or dom";
00092 goto error;
00093 }
00094 } else if (!strcmp(argv[i],"-c_d")) {
00095 if (++i == argc) goto missing;
00096 c_d = atoi(argv[i]);
00097 } else if (!strcmp(argv[i],"-a_d")) {
00098 if (++i == argc) goto missing;
00099 a_d = atoi(argv[i]);
00100 } else if (!strcmp(argv[i],"-mode")) {
00101 if (++i == argc) goto missing;
00102 if (!strcmp(argv[i],"solution")) {
00103 mode = EM_SOLUTION;
00104 } else if (!strcmp(argv[i],"time")) {
00105 mode = EM_TIME;
00106 } else if (!strcmp(argv[i],"stat")) {
00107 mode = EM_STAT;
00108 } else {
00109 e = "expecting: solution, time, or stat";
00110 goto error;
00111 }
00112 } else if (!strcmp(argv[i],"-samples")) {
00113 if (++i == argc) goto missing;
00114 samples = atoi(argv[i]);
00115 } else if (!strcmp(argv[i],"-solutions")) {
00116 if (++i == argc) goto missing;
00117 solutions = atoi(argv[i]);
00118 } else if (!strcmp(argv[i],"-iterations")) {
00119 if (++i == argc) goto missing;
00120 iterations = atoi(argv[i]);
00121 } else if (!strcmp(argv[i],"-naive")) {
00122 naive = true;
00123 } else if (!strcmp(argv[i],"-smart")) {
00124 naive = false;
00125 } else {
00126 char* unused;
00127 size = strtol(argv[i], &unused, 10);
00128 if ('\0' != *unused) {
00129 i++;
00130 goto error;
00131 }
00132 }
00133 i++;
00134 }
00135 return;
00136 missing:
00137 e = "missing argument";
00138 error:
00139 cerr << "Erroneous argument (" << argv[i-1] << ")" << endl
00140 << e << endl;
00141 exit(EXIT_FAILURE);
00142 }
00143
00144
00145