MultiAgentDecisionProcess  Release 0.2.1
dpomdp.spirit
Go to the documentation of this file.
1 //we can't simply skip end of lines as they have semantics in the multi-agent
2 //case - this means we have to explicitly parse the eol's
3 EOLTOK
4  = eol_p;
5 
6 #if SUBGRAMMAR == 0
7 AGENTSTOK //new for DECENTRALIZED pomdp
8  = str_p("agents");
10  = str_p("discount");
11 VALUESTOK
12  = str_p("values");
13 STATESTOK
14  = str_p("states");
16  = str_p("actions");
18  = str_p("observations");
19 TTOK
20  = str_p("T");
21 OTOK
22  = str_p("O");
23 RTOK
24  = str_p("R");
26  = EOLTOK >> str_p("uniform")
27  [SetLastParsedType(self._m_parserObject, UNIFORM)];
28 INTTOK
29  = uint_p[StoreLastParsedElement(self._m_parserObject)];
30 #endif
32  = EOLTOK >> str_p("identity")
33  [SetLastParsedType(self._m_parserObject, IDENTITY)];
34 REWARDTOK
35  = str_p("reward");
36 COSTTOK
37  = str_p("cost");
39  = str_p("start");
41  = str_p("include");
43  = str_p("exclude");
44 RESETTOK
45  = str_p("reset");
46 COLONTOK
47  = str_p(":");
49  = str_p("*")[SetLastParsedType(self._m_parserObject, ASTERICK)];
50 PLUSTOK
51  = str_p("+");
53  = str_p("-");
55  = real_p[StoreLastParsedElement(self._m_parserObject)];
56  //([0-9]+ \. [0-9]* | \. [0-9]+ | [0-9]+ ) ([eE] [+-]? [0-9]+)?
57 STRINGTOK
58  = (lexeme_d[alpha_p >> *(alnum_p | ch_p('_') | ch_p('-') ) ]
59  - reserved_word)[StoreLastParsedElement(self._m_parserObject)];
60  ;
61 
64  | RTOK
65  ;
66 
68  = eps_p[Initialize(self._m_parserObject)]
69  >> dpomdp[InitializeDPOMDP(self._m_parserObject)]
70  ;
71 
72 dpomdp
73  = //NOTE start_state has been moved to a fixed place in the preamble
74  //cassandra's def: preamble start_state param_list
75  preamble[AddModels(self._m_parserObject)]
76  >> param_list
77  ;
78 
79 preamble
80  = //NOTE the order of the preamble is now fixed
81  //cassandra's def: preamble param_type | /* empty */
82  agents_param[DebugOutput("preamble_agents_param")] >>
83  discount_param[DebugOutput("preamble_discount_param")] >>
84  value_param[DebugOutput("preamble_value_param")] >>
85  state_param[DebugOutput("preamble_state_param")] >>
86  start_state[DebugOutput("preamble_start_state")]
87  [InitializeStates(self._m_parserObject)] >>
88  action_param[DebugOutput("preamble_action_param")]
89  [InitializeActions(self._m_parserObject)] >>
90  obs_param[DebugOutput("preamble_obs_param")]
91  [InitializeObservations(self._m_parserObject)]
92 ;
94  = AGENTSTOK[DebugOutput("ap_AGENTSTOK")] >> COLONTOK >> agents_tail >>
95  EOLTOK
96  ;
98  = INTTOK [SetNrAgents(self._m_parserObject)]
99  | (
100  +( STRINGTOK[DebugOutput("il_STRINGTOK_next")]
101  [NextStringOfIdentList(self._m_parserObject)]
102  )
103  )[AddAgents(self._m_parserObject)]
104  ;
106  = DISCOUNTTOK >> COLONTOK >> FLOATTOK[dp_SetDiscountParam(self.
107  _m_parserObject)] >> EOLTOK
108  ;
109 
111  = VALUESTOK >> COLONTOK >> value_tail[DebugOutput("vp_value_tail")] >> EOLTOK
112  ;
113 
114 value_tail
115  = REWARDTOK[vt_REWARDTOK(self._m_parserObject)]
116  | COSTTOK[vt_COSTTOK(self._m_parserObject)]
117  ;
118 
120  = STATESTOK[SetNrStates(self._m_parserObject,0)] >> COLONTOK >>
121  state_tail[DebugOutput("sp_state_tail")] >> EOLTOK
122  ;
123 
124 state_tail
125  = INTTOK[SetNrStates(self._m_parserObject)]
126  [DebugOutput("st_INTTOK")]
127  | state_list[DebugOutput("st_ident_list")]
128  ;
129 
130 state_list
131  = // ident_list >> STRINGTOK | STRINGTOK
132  +( STRINGTOK[AddState(self._m_parserObject)] )
133  ;
134 
135 
136 //new - each agent has its actions on its own line
138  = ACTIONSTOK[SetAgentIndex(self._m_parserObject, 0)] >> COLONTOK >>
139  +(EOLTOK >> action_param_line[DebugOutput("ap_action_param_line")])
140  >> EOLTOK
141  ;
143  = action_tail[DebugOutput("apl_action_tail")][SetNextAgentIndex(
144  self._m_parserObject)]
145  ;
147  = INTTOK[SetNrActions(self._m_parserObject)]
148  | action_list[DebugOutput("at_ident_list")]
149  ;
151  = +( STRINGTOK[AddAction(self._m_parserObject)] )
152  ;
153 
154 obs_param
155  = OBSERVATIONSTOK[SetAgentIndex(self._m_parserObject, 0)] >> COLONTOK >>
156  +(EOLTOK >> obs_param_line[DebugOutput("op_obs_param_line")]) >>
157  EOLTOK
158  ;
160  = obs_tail[DebugOutput("opl_obs_tail")][SetNextAgentIndex(
161  self._m_parserObject)]
162  ;
163 obs_tail
164  = INTTOK[SetNrObservations(self._m_parserObject)]
165  | obs_list[DebugOutput("ot_ident_list")]
166  ;
167 obs_list
168  = +( STRINGTOK[AddObservation(self._m_parserObject)] )
169  ;
171  =
172  (
173  STARTTOK[ResetCurMatrix(self._m_parserObject)] >>
174  (
175  ( COLONTOK >>
176  (
177  u_matrix[StartStateRowProbs(self._m_parserObject)]
178  |
179  STRINGTOK[AddStartState(self._m_parserObject)]
180  [ProcessStartStateList(self._m_parserObject)]
181  |
182  INTTOK[AddStartState(self._m_parserObject)]
183  [ProcessStartStateList(self._m_parserObject)]
184  )
185  )
187  [ProcessStartStateList(self._m_parserObject)])
188  | (EXCLUDETOK[StartStateExludes(self._m_parserObject)]
190  [ProcessStartStateList(self._m_parserObject)])
191  )
192  ) >> EOLTOK
193 ;
194 
195 /*changed to remove left recursion: */
197  = // cassandra's def: start_state_list state_or_indiv_act_or_obs | state_or_indiv_act_or_obs
198  // easy substitute: +(state_or_indiv_act_or_obs)
199  // NOTE - this allows '*' as states here...
200  // we don't want that, so :
201  +(STRINGTOK[AddStartState(self._m_parserObject)]
202  [DebugOutput("ssl_STRINGTOK")]
203  | INTTOK[AddStartState(self._m_parserObject)]
204  [DebugOutput("ssl_INTTOK")])
205  ;
206 
207 param_list
209  ;
210 
211 param_spec
213  | obs_prob_spec
214  | reward_spec
215 ;
216 
218  = TTOK[DebugOutput("tps_TTOK")][ResetCurMatrix(self._m_parserObject)] >> COLONTOK >> trans_spec_tail >> EOLTOK
219  ;
220 
222  = joint_action[DebugOutput("tst_joint_action")]
223  >>
224  COLONTOK[DebugOutput("tst_COLON")]
225  >>
226  (
227  (
228  from_state[DebugOutput("tst_statefrom")] >> COLONTOK >>
229  (
230  to_state[DebugOutput("tst_stateto")] >> COLONTOK >> prob
231  [DebugOutput("tst_prob")]
232  [ProcessTProb(self._m_parserObject)]
233  | u_matrix[DebugOutput("tst_u_matrix")]
234  [ProcessTRow(self._m_parserObject)]
235  )
236  )
237  | ui_matrix[DebugOutput("tst_ui_matrix")]
238  [ProcessTMatrix(self._m_parserObject)]
239  )
240 
241 ;
242 
244  = OTOK[DebugOutput("ops_OTOK")][ResetCurMatrix(self._m_parserObject)] >> COLONTOK >> obs_spec_tail >> EOLTOK
245  ;
246 
248  =
249  joint_action[DebugOutput("ost_joint_action")]
250  >>
251  COLONTOK
252  >>
253  (
254  (
255  to_state[DebugOutput("ost_stateto")] >> COLONTOK >>
256  (
257  joint_obs[DebugOutput("ost_joint_obs")] >> COLONTOK >> prob
258  [DebugOutput("ost_prob")]
259  [ProcessOProb(self._m_parserObject)]
260  |
261  u_matrix[DebugOutput("ost_u_matrix")]
262  [ProcessORow(self._m_parserObject)]
263  )
264  )
265  | u_matrix[DebugOutput("ost_u_matrix")]
266  [ProcessOMatrix(self._m_parserObject)]
267  )
268  ;
269 
271  = RTOK[DebugOutput("rs_rtok")][ResetCurMatrix(self._m_parserObject)] >> COLONTOK >> reward_spec_tail >> EOLTOK
272  ;
273 
275  = joint_action[DebugOutput("rst_joint_action")]
276  >> COLONTOK
277  >> from_state[DebugOutput("rst_statefrom")]
278  >> COLONTOK
279  >>
280  (
281  (
282  to_state[DebugOutput("rst_stateto")]
283  >> COLONTOK
284  >>
285  (
286  joint_obs[DebugOutput("rst_jointobs")] >> COLONTOK
287  >> FLOATTOK[DebugOutput("rst_FLOATTOK")]
288  [ProcessR(self._m_parserObject)]
289  |
291  [DebugOutput("rst_floats_matrix")]
292  [ProcessRRow(self._m_parserObject)]
293 
294  )
295  )
296  |
298  [DebugOutput("rst_floats_matrix")]
299  [ProcessRMatrix(self._m_parserObject)]
300  )
301  ;
302 
303 ui_matrix
304  =
305  (
306  UNIFORMTOK[DebugOutput("ui_matrix UNIFORMTOK ")]
307  | IDENTITYTOK
308  | floats_matrix
309  )
310  ;
311 
312 u_matrix
313  = UNIFORMTOK[DebugOutput("um_UNIFORMTOK")]
314 // | RESETTOK - NOTE:reset is not documented by cassandra, therefore
315 // omitted here
316  | floats_matrix[DebugOutput("um_floats_matrix")]
317  ;
318 
320  = //floats_matrix >> floats | floats
321  +(floats_row_vector[DebugOutput("pm_floats_row_vector")]
322  [NextRowOfMatrix(self._m_parserObject)])
323  ;
325  =
326  EOLTOK >> +(FLOATTOK[NextFloatOfRow(self._m_parserObject)])
327  ;
328 
329 
330 //difference between prob and num is deprecated - only parse doubles
331 // and do typechecking when putting data in model...(easier)
332 
333 /*
334 prob_matrix
335  = //prob_matrix >> prob | prob
336  +(prob_row_vector[DebugOutput("pm_prob_row_vector")][NextRowOfMatrix(
337  self._m_parserObject)])
338  ;
339 prob_row_vector
340  =
341  EOLTOK >> +(prob[DebugOutput("prv_prob")][NextProbOfRow(self._m_parserObject)])
342  ;
343 
344 num_matrix
345  = //num_matrix >> number | number
346  +(num_row_vector[DebugOutput("nm_num_row_vector")])
347  ;
348 
349 num_row_vector
350  = EOLTOK >> +(number[DebugOutput("nrv_number")])
351  ;
352 
353 */
354 
356  = state_or_indiv_act_or_obs[StoreLPFromState(self._m_parserObject)]
357  ;
358 to_state
359  = state_or_indiv_act_or_obs[StoreLPToState(self._m_parserObject)]
360  ;
361 /*
362 state_or_indiv_act_or_obs
363  = INTTOK
364  | STRINGTOK
365  | ASTERICKTOK
366  ;
367 */
368 /*in order to discriminate between a joint action specified by
369  * 1) a joint action index (or '*')
370  * and
371  * 2) multiple individual actions (indices, '*'s or action names)
372  *
373  * we have to require at least two individual indices in case (2).*/
375  = ( state_or_indiv_act_or_obs[StoreLPAction(self._m_parserObject)] >>
376  +(state_or_indiv_act_or_obs[StoreLPAction(self._m_parserObject)])
377  )[StoreLPJointAction(self._m_parserObject)]
378  | INTTOK[StoreLPJointAction(self._m_parserObject, true)]
379  | ASTERICKTOK
380  [WildCardJointAction(self._m_parserObject)]
381  [StoreLPJointAction(self._m_parserObject)]
382 
383  //NYI(" the * joint action ")]//to indicate any joint action...
384  ;
385 
386 /* the parsed sub-rules set the "_m_lp_type" variable, which is used by
387  * StoreLPAction above. Therefore, no functions need to be called here.*/
390  | STRINGTOK
391  | ASTERICKTOK //[NYI(" the * individual action ")]
392  ;
393 joint_obs
394  = //first try to catch joint actions specified as "* * ... *" which
395  //denote all joint observations
396  // (we don't want to expand these individual joint observations...)
397  ( ASTERICKTOK >> +ASTERICKTOK )
398  [WildCardJointObservation(self._m_parserObject)]
399  |
400  //the regular case of specifying individual observation(indice)s
401  ( state_or_indiv_act_or_obs[StoreLPObservation(self._m_parserObject)] >>
402  +(state_or_indiv_act_or_obs[StoreLPObservation(self._m_parserObject)])
403  )[StoreLPJointObservation(self._m_parserObject)]
404  |
405  //a joint observation index
406  INTTOK[StoreLPJointObservation(self._m_parserObject, true)]
407  |
408  //a single '*' denoting all joint observations:
410  [WildCardJointObservation(self._m_parserObject)]
411 
412  //NYI(" the * joint obs ")]//to indicate any joint obs...
413  ;
414 /*
415 state_or_indiv_act_or_obs
416  = INTTOK
417  | STRINGTOK
418  | ASTERICKTOK
419  ;
420 
421 */
422 /* old
423 joint_obs
424  = +(state_or_indiv_act_or_obs)
425  | ASTERICKTOK //to indicate any joint observation...
426  ;
427 
428 state_or_indiv_act_or_obs
429  = INTTOK
430  | STRINGTOK
431  | ASTERICKTOK
432  ;
433 
434 ident_list
435  = // ident_list >> STRINGTOK | STRINGTOK
436  +( STRINGTOK[DebugOutput("il_STRINGTOK_next")]
437  [NextStringOfIdentList(self._m_parserObject)] )
438  ;
439 */
440 
441 prob
442  = FLOATTOK // try float first -> don't want to be left with ".024"
443  | INTTOK
444  ;
445 
446 
447 
448 //XXX:
449 //
450 //this works:
451 //R: open-left open-left : tiger-right : * : * +20
452 //but this doesn't:
453 //R: open-right open-right : tiger-left : * : * 20
454 
455 /*
456 number
457  // try float first -> don't want to be left with ".024"
458  = float_r
459  | int_r
460  ;
461 
462 float_r
463  = FLOATTOK[n_SetLPNumberType(self._m_parserObject,DOUBLE)]
464  ;
465 
466 int_r
467  = (optional_sign[n_SetLPNumUsedOptSign(self._m_parserObject,true)]) >>
468  INTTOK[n_SetLPNumberType(self._m_parserObject,INT)]
469  [n_ProcessNegation(self._m_parserObject)]
470  | INTTOK[n_SetLPNumUsedOptSign(self._m_parserObject,false)]
471  [n_SetLPNumberType(self._m_parserObject,INT)]
472  ;
473 
474 optional_sign
475  = PLUSTOK[os_SetNegated(self._m_parserObject,false)]
476  | MINUSTOK[os_SetNegated(self._m_parserObject,true)]
477 // | eps_p[DebugOutput("optional_sign_epsmatch")]
478 ;
479 
480 */