MultiAgentDecisionProcess  Release 0.2.1
argumentHandlers.cpp
Go to the documentation of this file.
1 
28 #include "argumentHandlers.h"
29 #include <string.h>
30 
31 using namespace ArgumentHandlers;
32 
33 namespace ArgumentHandlers {
34 
36 "<faolieho@science.uva.nl>, <mtjspaan@isr.ist.utl.pt>";
37 
38 // a group for input arguments
39 static const int GID_INPUTARG=1;
40 
41 
42 //Dec-POMDP File options (problemFile)
43 static const int GID_PROBLEMFILE=GID_INPUTARG;
44 const char *problemFile_argp_version = ".dpomdp file argument parser 0.1";
45 static const char *problemFile_args_doc = "PROBLEM";
46 static const char *problemFile_doc =
47 "This is the documentation for the .dpomdp file argument parser\
48 This parser should be included as a child argp parser in the \
49 main argp parser of your application.(and this message will\
50 not be shown)\
51 \vPROBLEM is either \n\
52 a) one of the following standard problems: DT, FF\n\
53 or \n\
54 b) a Dec-POMDP problem filename (.dpomdp or .toi-dpomdp). \
55 If it includes an extension, PROBLEM will be attempted to be loaded as is, \
56 otherwise the <PROBLEMSDIR> will be searched. \
57 I.e., ~/.madp/problems/PROBLEM.{toi-}dpomdp will be loaded.\n\
58 Some of the standard problems take options.";
59 
60 static const int OPT_NRAGENTS=1; //#agents
61 static const int OPT_NRHOUSES=2; //#houses
62 static const int OPT_NRFLS=3; //#FLs
63 static struct argp_option problemFile_options[] = {
64 {"agents", OPT_NRAGENTS, "NRAGENTS", 0, "FireFighting: the number of agents (2)" },
65 {"houses", OPT_NRHOUSES, "NRHOUSES", 0, "FireFighting: the number of houses (3)" },
66 {"firelevels", OPT_NRFLS, "NRFLS", 0, "FireFighting: the number of firelevels (3)"},
67 { 0 }
68 };
69 error_t
70 problemFile_parse_argument (int key, char *arg, struct argp_state *state)
71 {
72  static bool got_problemFile = 0;
73  //if we already got the dec-pomdp file return
74  if(got_problemFile)
75  return ARGP_ERR_UNKNOWN;
76  /* Get the input argument from argp_parse, which we
77  know is a pointer to our arguments structure. */
78  struct Arguments *theArgumentsStruc = (struct Arguments*) state->input;
79 
80  switch (key)
81  {
82  case OPT_NRAGENTS:
83  theArgumentsStruc->nrAgents = atoi(arg);
84  break;
85  case OPT_NRHOUSES:
86  theArgumentsStruc->nrHouses = atoi(arg);
87  break;
88  case OPT_NRFLS:
89  theArgumentsStruc->nrFLs = atoi(arg);
90  break;
91  case ARGP_KEY_NO_ARGS:
92  argp_usage (state);
93  break;
94  case ARGP_KEY_ARG:
95  {
96  theArgumentsStruc->dpf = std::string("").c_str();
97  if(strcmp(arg, "DT") == 0)
98  theArgumentsStruc->problem_type = ProblemType::DT;
99  else if(strcmp(arg, "FF") == 0)
100  theArgumentsStruc->problem_type = ProblemType::FF;
101  else
102  theArgumentsStruc->dpf = arg;
103  got_problemFile = 1;
104  break;
105  }
106  default:
107  return ARGP_ERR_UNKNOWN;
108  }
109  return 0;
110 }
112 extern const struct argp_child problemFile_child = {&problemFile_argp, 0, "Problem specification options", GID_PROBLEMFILE};
113 
114 
115 
116 //global options (globalOptions)
117 static const int GID_GLOBALOPTIONS=8;
118 const char *globalOptions_argp_version = "global options parser 0.1";
119 static const char *globalOptions_args_doc = 0;
120 static const char *globalOptions_doc =
121 "This is the documentation for the global options parser\
122 This parser should be included as a child argp parser in the \
123 main argp parser of your application. (and this message will\
124 not be shown)";
125 //\v";
126 static struct argp_option globalOptions_options[] = {
127 {"verbose", 'v', 0, 0, "Produce verbose output. Specifying this option multiple times increases verbosity." },
128 {"quiet", 'q', 0, 0, "Don't produce any output" },
129 {"silent", 's', 0, OPTION_ALIAS },
130 { 0 }
131 };
132 error_t
133 globalOptions_parse_argument (int key, char *arg, struct argp_state *state)
134 {
135  /* Get the input argument from argp_parse, which we
136  know is a pointer to our arguments structure. */
137  struct Arguments *theArgumentsStruc = (struct Arguments*) state->input;
138 
139  switch (key)
140  {
141  case 'q': case 's':
142  theArgumentsStruc->verbose--;
143  break;
144  case 'v':
145  theArgumentsStruc->verbose++;
146  break;
147  default:
148  return ARGP_ERR_UNKNOWN;
149  }
150  return 0;
151 }
153 const struct argp_child globalOptions_child = {&globalOptions_argp, 0, "General options", GID_GLOBALOPTIONS};
154 
155 
156 
157 //model options modelOptions
158 static const int GID_MODELOPTIONS=3;
159 const char *modelOptions_argp_version = "Model options parser 0.1";
160 static const char *modelOptions_args_doc = 0;
161 static const char *modelOptions_doc =
162 "This is the documentation for the model options parser\
163 This parser should be included as a child argp parser in the \
164 main argp parser of your application. (and this message will\
165 not be shown)\
166 \v";
167 
168 static const int OPT_TOI=1;
169 static struct argp_option modelOptions_options[] = {
170 {"sparse", 's',0, 0, "Use sparse transition and observation models" },
171 {"toi", OPT_TOI, 0, 0, "Indicate that PROBLEM is a transition observation independent Dec-POMDP" },
172 {"discount", 'g', "GAMMA", 0, "Set the problem's discount parameter (overriding its default)" },
173 { 0 }
174 };
175 error_t
176 modelOptions_parse_argument (int key, char *arg, struct argp_state *state)
177 {
178  /* Get the input argument from argp_parse, which we
179  know is a pointer to our arguments structure. */
180  struct Arguments *theArgumentsStruc = (struct Arguments*) state->input;
181 
182  switch (key)
183  {
184  case 's':
185  theArgumentsStruc->sparse = 1;
186  break;
187  case OPT_TOI:
188  theArgumentsStruc->isTOI=1;
189  break;
190  case 'g':
191  theArgumentsStruc->discount = strtof(arg,0);
192  break;
193  default:
194  return ARGP_ERR_UNKNOWN;
195  }
196  return 0;
197 }
199 const struct argp_child modelOptions_child = {&modelOptions_argp, 0, "Model options", GID_MODELOPTIONS};
200 
201 
202 //Solution method options (solutionMethodOptions)
203 const char *solutionMethodOptions_argp_version = "Solution method options parser 0.1";
204 static const char *solutionMethodOptions_args_doc = 0;
205 static const char *solutionMethodOptions_doc =
206 "This is the documentation for the solution method options parser\
207 This parser should be included as a child argp parser in the \
208 main argp parser of your application. (and this message will\
209 not be shown)";
210 //\v";
211 
212 //we define a special solution method group ID, so it is easier to group other
213 //parsers with this one
214 static const int GID_SM=2;
215 static const int OPT_INF=1;
216 static struct argp_option solutionMethodOptions_options[] = {
217 {"horizon",'h',"HOR", 0, "Specifies the horizon to be considered" },
218 {"inf", OPT_INF , 0, 0, "Indicate that horizon is infinite" },
219 { 0 }
220 };
221 error_t
222 solutionMethodOptions_parse_argument (int key, char *arg, struct argp_state *state)
223 {
224  /* Get the input argument from argp_parse, which we
225  know is a pointer to our arguments structure. */
226  struct Arguments *theArgumentsStruc = (struct Arguments*) state->input;
227 
228  switch (key)
229  {
230  case 'h':
231  theArgumentsStruc->horizon = atoi(arg);
232  break;
233  case OPT_INF:
234  theArgumentsStruc->infiniteHorizon=1;
235  break;
236  default:
237  return ARGP_ERR_UNKNOWN;
238  }
239  return 0;
240 }
242 const struct argp_child solutionMethodOptions_child = {&solutionMethodOptions_argp, 0, "Solution method options", GID_SM };
243 
244 
245 //joint policy argument parser (jpolIndex)
246 static const int GID_JPOLINDEX=GID_INPUTARG;
247 const char *jpolIndex_argp_version = "joint policy index argument parser 0.1";
248 static const char *jpolIndex_args_doc = "JPOL-INDEX";
249 static const char *jpolIndex_doc =
250 "This is the documentation for the joint policy index argument parser\
251 This parser should be included as a child argp parser in the \
252 main argp parser of your application.(and this message will\
253 not be shown)\
254 \vJPOL-INDEX is a (long long) integer that is the index of the joint \
255 policy to be considered.";
256 static struct argp_option jpolIndex_options[] = {
257 //{"none", 'v', 0, 0, "no options" },
258 { 0 }
259 };
260 error_t
261 jpolIndex_parse_argument (int key, char *arg, struct argp_state *state)
262 {
263  static bool got_jpolIndex = 0;
264  //if we already got the dec-pomdp file return
265  if(got_jpolIndex)
266  return ARGP_ERR_UNKNOWN;
267  /* Get the input argument from argp_parse, which we
268  know is a pointer to our arguments structure. */
269  struct Arguments *theArgumentsStruc = (struct Arguments*) state->input;
270 
271  switch (key)
272  {
273  case ARGP_KEY_NO_ARGS:
274  argp_usage (state);
275  break;
276  case ARGP_KEY_ARG:
277  {
278  char *left;
279  theArgumentsStruc->jpolIndex = strtoull(arg,&left,10);
280  if(*left != '\0')
281  {
282  std::stringstream ss;
283  ss << "Could not entirely parse the JPOL-INDEX: arg='"
284  << arg <<"', left='" << left
285  << "', found jpol index='"<< theArgumentsStruc->jpolIndex
286  << "'";
287  throw(E(ss));
288  }
289  got_jpolIndex = 1;
290  break;
291  }
292  default:
293  return ARGP_ERR_UNKNOWN;
294  }
295  return 0;
296 }
298 const struct argp_child jpolIndex_child = {&jpolIndex_argp, 0, 0, GID_PROBLEMFILE};
299 
300 
301 //GMAA options (gmaa)
302 static const int GID_GMAA=GID_SM;
303 const char *gmaa_argp_version = "GMAA options parser 0.1";
304 static const char *gmaa_args_doc = 0;
305 static const char *gmaa_doc =
306 "This is the documentation for the options options parser\
307 This parser should be included as a child argp parser in the \
308 main argp parser of your application. (and this message will\
309 not be shown)\
310 \v\
311 GMAA parameter:\n\
312 0 or MAAstar -> use GMAA_MAAstar\n\
313 1 or kGMAA -> use GMAA_kGMAA (uses K)\n\
314 2 or FSPC -> use Forward Sweep Policy Computation (kGMAA with k=1)\n\
315 \n\
316 BGIP_SOLVERTYPE parameter:\n\
317 0 or BFS\t-\tbrute force search\n\
318 1 or AM \t-\tAlternating Maximization\n";
319 
320 static const int AM_RESTARTS=1;
321 static struct argp_option gmaa_options[] = {
322 {"GMAA", 'G', "GMAA", 0, "Select which GMAA variation to use" },
323 {"BGIP_Solver", 'B', "BGIP_SOLVERTYPE", 0, "Select which Bayesian game solver to use"},
324 {"k", 'k', "K", 0, "Set k in k-GMAA" },
325 {"restarts", 'r', "RESTARTS", 0, "Set the number of restarts"},
326 {"AM-restarts", AM_RESTARTS, "AM_RESTARTS", 0, "nr restarts for solving BGs withFSPC_AM"},
327 { 0 }
328 };
329 error_t
330 gmaa_parse_argument (int key, char *arg, struct argp_state *state)
331 {
332  /* Get the input argument from argp_parse, which we
333  know is a pointer to our arguments structure. */
334  struct Arguments *theArgumentsStruc = (struct Arguments*) state->input;
335 
336  switch (key)
337  {
338 
339  case 'G':
340  if(strlen(arg)==1)
341  theArgumentsStruc->gmaa=static_cast<GMAA_t>(atoi(arg));
342  else if(strcmp(arg,"MAAstar")==0)
343  theArgumentsStruc->gmaa=MAAstar;
344  else if(strcmp(arg,"FSPC")==0)
345  theArgumentsStruc->gmaa=FSPC;
346  else if(strcmp(arg,"kGMAA")==0)
347  theArgumentsStruc->gmaa=kGMAA;
348  else
349  return ARGP_ERR_UNKNOWN;
350  break;
351  case 'B':
352  if(strlen(arg)==1){
353  int methodI=atoi(arg);
354  if (methodI < 0 || methodI > (int)NUMBER_OF_BGIP_SOLVER_TYPES)
355  throw E("Wrong BGIP_SolverType number!");
356  theArgumentsStruc->bgsolver =
357  static_cast<BGIP_SolverType::BGIP_Solver_t>(methodI);
358  }
359  else if(strcmp(arg,"BFS")==0)
360  theArgumentsStruc->bgsolver = BGIP_SolverType::BFS;
361  else if(strcmp(arg,"AM")==0)
362  theArgumentsStruc->bgsolver = BGIP_SolverType::AM;
363  else
364  return ARGP_ERR_UNKNOWN;
365  break;
366 
367  case 'k':
368  theArgumentsStruc->k = atoi(arg);
369  break;
370  case 'r':
371  theArgumentsStruc->nrRestarts = atoi(arg);
372  break;
373  case AM_RESTARTS:
374  theArgumentsStruc->nrAMRestarts = atoi(arg);
375  break;
376  default:
377  return ARGP_ERR_UNKNOWN;
378  }
379  return 0;
380 }
383 };
384 const struct argp_child gmaa_child = {&gmaa_argp, 0, "GMAA options", GID_GMAA};
385 
386 
387 //Perseus options (perseus)
388 static const int GID_PERSEUS=GID_SM;
389 const char *perseus_argp_version = "Perseus options parser 0.1";
390 static const char *perseus_args_doc = 0;
391 static const char *perseus_doc =
392 "This is the documentation for the options options parser\
393 This parser should be included as a child argp parser in the \
394 main argp parser of your application. (and this message will\
395 not be shown)";
396 
397 static struct argp_option perseus_options[] = {
398 {"savePOMDP", 'P', 0, 0, "Save the POMDP to disk" },
399 {"saveIntermediateV", 'V', 0, 0, "Save intermediate value functions to disk" },
400 {"saveTimings", 't', 0, 0, "Save timing results to disk"},
401 {"minNrIterations", 'i', "ITERS", 0, "Make Perseus run at least ITERS iterations" },
402 {"initReward", 'I', 0, 0, "Initialize the value function with the immediate reward."},
403 {"initZero", 'z', 0, 0, "Initialize the value function with 0."},
404 { 0 }
405 };
406 error_t
407 perseus_parse_argument (int key, char *arg, struct argp_state *state)
408 {
409  /* Get the input argument from argp_parse, which we
410  know is a pointer to our arguments structure. */
411  struct Arguments *theArgumentsStruc = (struct Arguments*) state->input;
412 
413  switch (key)
414  {
415  case 'n':
416  theArgumentsStruc->nrBeliefs = atoi(arg);
417  break;
418  case 'P':
419  theArgumentsStruc->savePOMDP=1;
420  break;
421  case 'V':
422  theArgumentsStruc->saveIntermediateV=1;
423  break;
424  case 't':
425  theArgumentsStruc->saveTimings = 1;
426  break;
427  case 'i':
428  theArgumentsStruc->minimumNrIterations = atoi(arg);
429  break;
430  case 'I':
431  theArgumentsStruc->initializeWithImmediateReward=1;
432  break;
433  case 'z':
434  theArgumentsStruc->initializeWithZero=1;
435  break;
436  default:
437  return ARGP_ERR_UNKNOWN;
438  }
439  return 0;
440 }
443 const struct argp_child perseus_child = {&perseus_argp, 0,
444  "Perseus general options", GID_PERSEUS};
445 
446 //Perseus belief set sampling options (perseusbelief)
447 static const int GID_PERSEUSBELIEF=GID_SM;
448 const char *perseusbelief_argp_version = "Perseus Belief options parser 0.1";
449 static const char *perseusbelief_args_doc = 0;
450 static const char *perseusbelief_doc =
451 "This is the documentation for the options options parser\
452 This parser should be included as a child argp parser in the \
453 main argp parser of your application. (and this message will\
454 not be shown)";
455 
456 static struct argp_option perseusbelief_options[] = {
457 {"beliefs",'n', "BELIEFS", 0, "Set the belief set size" },
458 {"saveBeliefs", 'B', 0, 0, "Save beliefs to disk" },
459 {"beliefSamplingHorizon", 'H', "HORIZON", 0, "Introduce an artificial horizon when sampling the beliefs (useful in infinite-horizon case)" },
460 {"uniqueBeliefs", 'u', 0, 0, "Sample unique beliefs (no duplicates)" },
461 {"useQMDP", 'Q', 0, 0, "Follow the QMDP policy while sampling beliefs instead of acting uniformly at random."},
462 {"QMDPexploreProb", 'x', "PROB", 0, "Probability with which to take a random action when using QMDP for belief sampling."},
463 { 0 }
464 };
465 error_t
466 perseusbelief_parse_argument (int key, char *arg, struct argp_state *state)
467 {
468  /* Get the input argument from argp_parse, which we
469  know is a pointer to our arguments structure. */
470  struct Arguments *theArgumentsStruc = (struct Arguments*) state->input;
471 
472  switch (key)
473  {
474  case 'n':
475  theArgumentsStruc->nrBeliefs = atoi(arg);
476  break;
477  case 'B':
478  theArgumentsStruc->saveBeliefs=1;
479  break;
480  case 'H':
481  theArgumentsStruc->resetAfter = atoi(arg);
482  break;
483  case 'u':
484  theArgumentsStruc->uniqueBeliefs=1;
485  break;
486  case 'Q':
487  theArgumentsStruc->useQMDPforSamplingBeliefs=1;
488  break;
489  case 'x':
490  theArgumentsStruc->QMDPexploreProb = strtof(arg,0);
491  break;
492  default:
493  return ARGP_ERR_UNKNOWN;
494  }
495  return 0;
496 }
499 const struct argp_child perseusbelief_child = {&perseusbelief_argp, 0,
500  "Perseus belief set sampling options", GID_PERSEUSBELIEF};
501 
502 //Perseus Backup options (perseusbackup)
503 static const int GID_PERSEUSBACKUP=GID_SM;
504 const char *perseusbackup_argp_version = "Perseus Backup options parser 0.1";
505 static const char *perseusbackup_args_doc = 0;
506 static const char *perseusbackup_doc =
507 "This is the documentation for the options options parser\
508 This parser should be included as a child argp parser in the \
509 main argp parser of your application. (and this message will\
510 not be shown)\
511 \vBACKUP parameter:\n\
512 0 or POMDP -> use PerseusPOMDP (default)\n\
513 1 or BG -> use PerseusBG (BG solver can be specified by BGBACKUP)\n\
514 \n\
515 BGBACKUP parameter (details in AlphaVectorBG.{h,cpp}):\n\
516 0 or EXH_MAX -> use EXHAUSTIVE_ONLYKEEPMAX backup in PerseusBG\n\
517 1 or EXH_ALL -> use EXHAUSTIVE_STOREALL backup in PerseusBG\n\
518 2 or BGS_EXH -> use BGIP_SOLVER_EXHAUSTIVE backup in PerseusBG (default)\n\
519 3 or BGS_ALTMAX -> use BGIP_SOLVER_ALTERNATINGMAXIMIZATION backup in PerseusBG\n\
520 4 or BGS_ALTMAX100 -> use BGIP_SOLVER_ALTERNATINGMAXIMIZATION_100STARTS backup\n\
521 ";
522 
523 static struct argp_option perseusbackup_options[] = {
524 {"backup", 'b', "BACKUP", 0, "Select which backup to use, see below" },
525 {"vectorEachBelief", 'e', 0, 0, "If specified, don't sample from belief set, but compute vector for each belief" },
526 {"BGbackup", 'y', "BGBACKUP", 0, "Select which BG backup to use for PerseusBG" },
527 {"waitPenalty", 'w', "PENALTY", 0, "Set the wait penalty for PerseusImplicitWaiting" },
528 {"weight", 'W', "WEIGHT", 0, "Set the weight for PerseusWeighted{NS}" },
529 {"commModel", 'c', "COMM", 0, "Select the communication model for PerseusWeighted" },
530 { 0 }
531 };
532 error_t
533 perseusbackup_parse_argument (int key, char *arg, struct argp_state *state)
534 {
535  /* Get the input argument from argp_parse, which we
536  know is a pointer to our arguments structure. */
537  struct Arguments *theArgumentsStruc = (struct Arguments*) state->input;
538 
539  switch (key)
540  {
541  case 'y':
542  if(strlen(arg)==1)
543  theArgumentsStruc->bgBackup=static_cast<BGBackupType>(atoi(arg));
544  else if(strcmp(arg,"EXH_MAX")==0)
545  theArgumentsStruc->bgBackup=EXHAUSTIVE_ONLYKEEPMAX;
546  else if(strcmp(arg,"EXH_ALL")==0)
547  theArgumentsStruc->bgBackup=EXHAUSTIVE_STOREALL;
548  else if(strcmp(arg,"BGS_EXH")==0)
549  theArgumentsStruc->bgBackup=BGIP_SOLVER_EXHAUSTIVE;
550  else if(strcmp(arg,"BGS_ALTMAX")==0)
552  else if(strcmp(arg,"BGS_ALTMAX100")==0)
554  else
555  return ARGP_ERR_UNKNOWN;
556  break;
557  case 'b':
558  if(strlen(arg)==1)
559  theArgumentsStruc->backup=static_cast<PerseusBackupType>(atoi(arg));
560  else if(strcmp(arg,"POMDP")==0)
561  theArgumentsStruc->backup=POMDP;
562  else if(strcmp(arg,"BG")==0)
563  theArgumentsStruc->backup=BG;
564  else
565  return ARGP_ERR_UNKNOWN;
566  break;
567  case 'w':
568  theArgumentsStruc->waitPenalty = strtof(arg,0);
569  break;
570  case 'W':
571  theArgumentsStruc->weight = strtof(arg,0);
572  break;
573  case 'c':
574  theArgumentsStruc->commModel = atoi(arg);
575  break;
576  case 'e':
577  theArgumentsStruc->computeVectorForEachBelief = 1;
578  break;
579  default:
580  return ARGP_ERR_UNKNOWN;
581  }
582  return 0;
583 }
588 const struct argp_child perseusbackup_child = {&perseusbackup_argp, 0,
589  "Perseus backup options",
591 
592 //Qheur options (qheur)
593 static const int GID_QHEUR=GID_SM;
594 const char *qheur_argp_version = "QHEUR options parser 0.1";
595 static const char *qheur_args_doc = 0;
596 static const char *qheur_doc =
597 "This is the documentation for the options options parser\
598 This parser should be included as a child argp parser in the \
599 main argp parser of your application. (and this message will\
600 not be shown)\vQHEUR parameter:\n\
601 0 or QMDP (defined on joint beliefs)\n\
602 1 or QPOMDP\n\
603 2 or QBG\n\
604 3 or QMDPc (cached for each joint AO history)";
605 
606 static struct argp_option qheur_options[] = {
607 {"Qheuristic", 'Q', "QHEUR", 0, "Select which Q-heuristic to use" },
608 { 0 }
609 };
610 error_t
611 qheur_parse_argument (int key, char *arg, struct argp_state *state)
612 {
613  /* Get the input argument from argp_parse, which we
614  know is a pointer to our arguments structure. */
615  struct Arguments* theArgumentsStruc = (struct Arguments*) state->input;
616 
617  switch (key)
618  {
619  case 'Q':
620  if(strlen(arg)==1)
621  theArgumentsStruc->qheur=static_cast<Qheur_t>(atoi(arg));
622  else if(strcmp(arg,"QMDP")==0)
623  theArgumentsStruc->qheur=eQMDP;
624  else if(strcmp(arg,"QPOMDP")==0)
625  theArgumentsStruc->qheur=eQPOMDP;
626  else if(strcmp(arg,"QBG")==0)
627  theArgumentsStruc->qheur=eQBG;
628  else if(strcmp(arg,"QMDPc")==0)
629  theArgumentsStruc->qheur=eQMDPc;
630  else
631  return ARGP_ERR_UNKNOWN;
632  break;
633  default:
634  return ARGP_ERR_UNKNOWN;
635  }
636  return 0;
637 }
640 const struct argp_child qheur_child = {&qheur_argp, 0, "Q-heuristic options",
641  GID_QHEUR};
642 
643 
644 //Simulation options (simulation)
645 static const int GID_SIMULATION=7;
646 const char *simulation_argp_version = "Simulation options parser 0.1";
647 static const char *simulation_args_doc = 0;
648 static const char *simulation_doc =
649 "This is the documentation for the options options parser\
650 This parser should be included as a child argp parser in the \
651 main argp parser of your application. (and this message will\
652 not be shown)";
653 //\v";
654 static struct argp_option simulation_options[] = {
655 {"runs", 'r', "RUNS", 0, "Set the number of episodes to simulate" },
656 {"seed", 'S', "SEED", 0, "Set the random seed" },
657 { 0 }
658 };
659 error_t
660 simulation_parse_argument (int key, char *arg, struct argp_state *state)
661 {
662  /* Get the input argument from argp_parse, which we
663  know is a pointer to our arguments structure. */
664  struct Arguments *theArgumentsStruc = (struct Arguments*) state->input;
665 
666  switch (key)
667  {
668  case 'r':
669  theArgumentsStruc->nrRuns=atoi(arg);
670  break;
671  case 'S':
672  theArgumentsStruc->randomSeed=atoi(arg);
673  break;
674  default:
675  return ARGP_ERR_UNKNOWN;
676  }
677  return 0;
678 }
679 static struct argp simulation_argp = { simulation_options,
682 const struct argp_child simulation_child = {&simulation_argp, 0,
683  "Simulation options",
685 
686 //CE options (CE)
687 static const int GID_CE=GID_SM;
688 const char *CE_argp_version = "CE options parser 0.1";
689 static const char *CE_args_doc = 0;
690 static const char *CE_doc =
691 "This is the documentation for the CE (cross entropy) options parser\
692 This parser should be included as a child argp parser in the \
693 main argp parser of your application. (and this message will\
694 not be shown)\
695 \v\
696 Options for using CE (the cross-entropy method) for optimization include \
697 the number of restarts (runs), the number of iteration for each runs, \
698 how much samples are drawn each iteration, and how much of those are \
699 used to update the probability distribution.";
700 
701 static const int CE_RESTARTS = 1;
702 static const int CE_EVALUATION_RUNS = 2;
703 static struct argp_option CE_options[] = {
704 {"CE-restarts", CE_RESTARTS, "CERESTARTS", 0, "Set the number of CE restarts (runs)"},
705 {"CE-eval-runs", CE_EVALUATION_RUNS, "CEEVALRUNS", 0, "Set the number of policy evaluation runs. More runs will result in more accurate evaluation. (set 0 for exact evaluation)."},
706 {"iterations", 'i', "ITERATIONS", 0, "Set the number of iterations per run"},
707 {"samples", 'n', "SAMPLES", 0, "Set the number of samples per iteration"},
708 {"updateSamples", 'u', "UPDATESAMPPLES", 0, "Set the number of samples used to update the prob. distribution."},
709 {"not_strictly_improving", 'N', 0, 0, "Do not use a hard threshold: do not require that newly sampled policies are strictly better then before. (this corresponds to the gamma in the CE papers)"},
710 {"alpha", 'a', "ALPHA", 0, "The learning rate"},
711 { 0 }
712 };
713 error_t
714 CE_parse_argument (int key, char *arg, struct argp_state *state)
715 {
716  /* Get the input argument from argp_parse, which we
717  know is a pointer to our arguments structure. */
718  struct Arguments *theArgumentsStruc = (struct Arguments*) state->input;
719 
720  switch (key)
721  {
722  case CE_EVALUATION_RUNS:
723  theArgumentsStruc->nrCEEvalutionRuns = atoi(arg);
724  break;
725  case CE_RESTARTS:
726  theArgumentsStruc->nrCERestarts = atoi(arg);
727  break;
728  case 'i':
729  theArgumentsStruc->nrCEIterations = atoi(arg);
730  break;
731  case 'n':
732  theArgumentsStruc->nrCESamples = atoi(arg);
733  break;
734  case 'u':
735  theArgumentsStruc->nrCESamplesForUpdate = atoi(arg);
736  break;
737  case 'N':
738  theArgumentsStruc->CE_use_hard_threshold = 0;
739  break;
740  case 'a':
741  theArgumentsStruc->CE_alpha = atof(arg);
742  break;
743  default:
744  return ARGP_ERR_UNKNOWN;
745  }
746  return 0;
747 }
748 static struct argp CE_argp = { CE_options, CE_parse_argument,
749  CE_args_doc, CE_doc };
750 const struct argp_child CE_child = {&CE_argp, 0, "CE options", GID_CE};
751 
752 
753 //JESP options (JESP)
754 static const int GID_JESP=GID_SM;
755 const char *JESP_argp_version = "JESP options parser 0.1";
756 static const char *JESP_args_doc = 0;
757 static const char *JESP_doc =
758 "This is the documentation for the JESP (Joint Equilibrium-based \
759 Search for Policies) options parser.\
760 This parser should be included as a child argp parser in the \
761 main argp parser of your application. (and this message will\
762 not be shown)\
763 \v\
764 Options for using JESP (Joint Equilibrium-based \
765 Search for Policies) include: \
766 the type of JESP (exhaustive or Dynamic Programming), which can be:\n\
767 0 or Exh - exhaustive JESP\n\
768 1 or DP - Dynamic programming\n\n\
769 and the number of restarts (runs).";
770 
771 static const int JESP_RESTARTS = 1;
772 static const int JESP_TYPE = 2;
773 static struct argp_option JESP_options[] = {
774 {"JESP-restarts", JESP_RESTARTS, "JESPRESTARTS", 0, "Set the number of JESP restarts (runs)"},
775 {"JESP-type", JESP_TYPE, "JESPTYPE", 0, "Set the type of JESP (Exh or [DP])"},
776 { 0 }
777 };
778 error_t
779 JESP_parse_argument (int key, char *arg, struct argp_state *state)
780 {
781  /* Get the input argument from argp_parse, which we
782  know is a pointer to our arguments structure. */
783  struct Arguments *theArgumentsStruc = (struct Arguments*) state->input;
784 
785  switch (key)
786  {
787  case JESP_RESTARTS:
788  theArgumentsStruc->JESPnrRestarts = atoi(arg);
789  break;
790  case JESP_TYPE:
791  if(strlen(arg)==1)
792  theArgumentsStruc->jesp=static_cast<JESP_t>(atoi(arg));
793  else if(strcmp(arg,"Exh")==0)
794  theArgumentsStruc->jesp = JESPExhaustive;
795  else if(strcmp(arg,"DP")==0)
796  theArgumentsStruc->jesp = JESPDP;
797  else
798  return ARGP_ERR_UNKNOWN;
799  break;
800  default:
801  return ARGP_ERR_UNKNOWN;
802  }
803  return 0;
804 }
807 const struct argp_child JESP_child = {&JESP_argp, 0, "JESP options", GID_JESP};
808 
809 
810 
811 } // end namespace