Generated on Wed Nov 1 15:04:28 2006 for Gecode by doxygen 1.4.5

support.cc

Go to the documentation of this file.
00001 /*
00002  *  Main authors:
00003  *     Christian Schulte <schulte@gecode.org>
00004  *
00005  *  Copyright:
00006  *     Christian Schulte, 2004
00007  *
00008  *  Last modified:
00009  *     $Date: 2006-08-16 13:07:15 +0200 (Wed, 16 Aug 2006) $ by $Author: zayenz $
00010  *     $Revision: 3541 $
00011  *
00012  *  This file is part of Gecode, the generic constraint
00013  *  development environment:
00014  *     http://www.gecode.org
00015  *
00016  *  See the file "LICENSE" for information on usage and
00017  *  redistribution of this file, and for a
00018  *     DISCLAIMER OF ALL WARRANTIES.
00019  *
00020  */
00021 
00022 #include "examples/support.hh"
00023 
00024 /*
00025  * Parses options for examples
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-fails (unsigned int) default: "
00072            << (fails<0 ? "(no limit) " : "") << fails << endl
00073            << "\t\tset number of allowed fails before stopping (solution-mode)"
00074            << endl
00075            << "\t-time (unsigned int) default: "
00076            << (fails<0 ? "(no limit) " : "") << time << endl
00077            << "\t\tset allowed time before stopping (solution-mode)" << endl
00078            << "\t-naive default: "
00079            << bool2str[naive] << endl
00080            << "\t\tuse naive version" << endl
00081            << "\t-smart default: "
00082            << bool2str[!naive] << endl
00083            << "\t\tuse smart version" << endl
00084            << "\t(unsigned int) default: " << size << endl
00085            << "\t\twhich version/size for example" << endl;
00086       exit(EXIT_SUCCESS);
00087     } else if (!strcmp(argv[i],"-icl")) {
00088       if (++i == argc) goto missing;
00089       if (!strcmp(argv[i],"def")) {
00090         icl = ICL_DEF;
00091       } else if (!strcmp(argv[i],"val")) {
00092         icl = ICL_VAL;
00093       } else if (!strcmp(argv[i],"bnd")) {
00094         icl = ICL_BND;
00095       } else if (!strcmp(argv[i],"dom")) {
00096         icl = ICL_DOM;
00097       } else {
00098         e = "expecting: def, val, bnd, or dom";
00099         goto error;
00100       }
00101     } else if (!strcmp(argv[i],"-c_d")) {
00102       if (++i == argc) goto missing;
00103       c_d = atoi(argv[i]);
00104     } else if (!strcmp(argv[i],"-a_d")) {
00105       if (++i == argc) goto missing;
00106       a_d = atoi(argv[i]);
00107     } else if (!strcmp(argv[i],"-quiet")) {
00108       quiet = true;
00109     } else if (!strcmp(argv[i],"-mode")) {
00110       if (++i == argc) goto missing;
00111       if (!strcmp(argv[i],"solution")) {
00112         mode = EM_SOLUTION;
00113       } else if (!strcmp(argv[i],"time")) {
00114         mode = EM_TIME;
00115       } else if (!strcmp(argv[i],"stat")) {
00116         mode = EM_STAT;
00117       } else {
00118         e = "expecting: solution, time, or stat";
00119         goto error;
00120       }
00121     } else if (!strcmp(argv[i],"-samples")) {
00122       if (++i == argc) goto missing;
00123       samples = atoi(argv[i]);
00124     } else if (!strcmp(argv[i],"-solutions")) {
00125       if (++i == argc) goto missing;
00126       solutions = atoi(argv[i]);
00127     } else if (!strcmp(argv[i],"-fails")) {
00128       if (++i == argc) goto missing;
00129       fails = atoi(argv[i]);
00130     } else if (!strcmp(argv[i],"-time")) {
00131       if (++i == argc) goto missing;
00132       time = atoi(argv[i]);
00133     } else if (!strcmp(argv[i],"-iterations")) {
00134       if (++i == argc) goto missing;
00135       iterations = atoi(argv[i]);
00136     } else if (!strcmp(argv[i],"-naive")) {
00137       naive = true;
00138     } else if (!strcmp(argv[i],"-smart")) {
00139       naive = false;
00140     } else {
00141       char* unused;
00142       size = strtol(argv[i], &unused, 10);
00143       if ('\0' != *unused) {
00144         i++;
00145         goto error;
00146       }
00147     }
00148     i++;
00149   }
00150   return;
00151  missing:
00152   e = "missing argument";
00153  error:
00154   cerr << "Erroneous argument (" << argv[i-1] << ")" << endl;
00155   if (e) cerr << e << endl;
00156   exit(EXIT_FAILURE);
00157 }
00158 
00159 // STATISTICS: example-any
00160