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],"-quiet")) {
00101 quiet = true;
00102 } else if (!strcmp(argv[i],"-mode")) {
00103 if (++i == argc) goto missing;
00104 if (!strcmp(argv[i],"solution")) {
00105 mode = EM_SOLUTION;
00106 } else if (!strcmp(argv[i],"time")) {
00107 mode = EM_TIME;
00108 } else if (!strcmp(argv[i],"stat")) {
00109 mode = EM_STAT;
00110 } else {
00111 e = "expecting: solution, time, or stat";
00112 goto error;
00113 }
00114 } else if (!strcmp(argv[i],"-samples")) {
00115 if (++i == argc) goto missing;
00116 samples = atoi(argv[i]);
00117 } else if (!strcmp(argv[i],"-solutions")) {
00118 if (++i == argc) goto missing;
00119 solutions = atoi(argv[i]);
00120 } else if (!strcmp(argv[i],"-iterations")) {
00121 if (++i == argc) goto missing;
00122 iterations = atoi(argv[i]);
00123 } else if (!strcmp(argv[i],"-naive")) {
00124 naive = true;
00125 } else if (!strcmp(argv[i],"-smart")) {
00126 naive = false;
00127 } else {
00128 char* unused;
00129 size = strtol(argv[i], &unused, 10);
00130 if ('\0' != *unused) {
00131 i++;
00132 goto error;
00133 }
00134 }
00135 i++;
00136 }
00137 return;
00138 missing:
00139 e = "missing argument";
00140 error:
00141 cerr << "Erroneous argument (" << argv[i-1] << ")" << endl
00142 << e << endl;
00143 exit(EXIT_FAILURE);
00144 }
00145
00146
00147