MultiAgentDecisionProcess  Release 0.2.1
ProblemDecTiger.cpp
Go to the documentation of this file.
1 
28 #include "ProblemDecTiger.h"
29 
30 using namespace std;
31 
32 #define DEBUG_PDT 0
33 #define DEBUG_TM 0
34 #define DEBUG_CJA 0
35 #define DEBUG_CJO 0
36 #define DEBUG_CA 0
37 #define DEBUG_CO 0
38 #define DEBUG_GETJA 0
39 
42  "The Dec-Tiger Problem",
43  "A toy problem, 2-agent Dec-POMDP. 2 agents have to select 1 out of 2 doors, behind one is a tiger, behind the other treasure.",
44  "DecTiger"),
45  NUMBER_OF_STATES(2),
46  NUMBER_OF_AGENTS(2),
47  NUMBER_OF_OBSERVATIONS(2),
48  NUMBER_OF_ACTIONS(3)
49 {
52 
53  SetUniformISD();
54  SetDiscount(1);
55 
56  // add actions:
58  if(DEBUG_CJA) cout << "\n>>>Creating joint actions and set...\n"<<endl;
59  // add joint actions
61  if(DEBUG_CA) cout << "testNRJA="<<testNRJA<<endl;
62 
64 
65  // add observations:
67  size_t testNRJO = ConstructJointObservations();
68  if(DEBUG_CO) cout << "testNRJO="<<testNRJO<<endl;
69 
71 
72  // add the transition model
73  if(DEBUG_PDT) cout << "\n>>>Adding Transition model...\n"<<endl;
76 
77  // add observation model
78  if(DEBUG_PDT) cout << "\n>>>Adding Observation model...\n"<<endl;
82 
83  // add rewards
86  if(DEBUG_PDT) cout << "Model created..."<<endl;
88 }
89 
91 {
92 }
93 
95 {
96  if(DEBUG_CA) cout << "Creating actions and action sets..."<<endl;
97  size_t nrJointActions = 1;
98  for(Index agentIndex=0; agentIndex < _m_nrAgents; agentIndex++)
99  {
100  if(DEBUG_CA) cout << "\nCreating agent "<<agentIndex<<"'s actions..."<<endl;
101  size_t nrActionsThisAgent = NUMBER_OF_ACTIONS;
102  nrJointActions *= nrActionsThisAgent;
103  if(DEBUG_CA) cout << "inserting this agent's nrActions...("<<nrActionsThisAgent<<")"<<endl;
104  _m_nrActions.push_back(nrActionsThisAgent);
105  if(DEBUG_CA) cout << "inserting this new(=empty) actionSet..."<<endl;
106  vector<ActionDiscrete> av_temp;
107  //is copied into back of _m_actionVecs, so no need for new...
108  _m_actionVecs.push_back( av_temp );
109  if(DEBUG_CA) cout << "inserted the new(=empty) actionSet"<<endl;
110  for(Index actionI=0; actionI < nrActionsThisAgent; actionI++)
111  {
112  if(DEBUG_CA) cout << "\nCreating action"<<actionI<<":";
113 
114  string name("a");
115  stringstream ss;
116  string strActionI, strAgentI;
117  ss << agentIndex;
118  ss >> strAgentI;
119  name += strAgentI;
120  ss.clear();
121  ss << actionI;
122  ss >> strActionI;
123  name += strActionI;
124  string whatAction;
125  switch(actionI){
126  case(LISTEN): whatAction = "Listen";
127  break;
128  case(OPENLEFT): whatAction = "OpenLeft";
129  break;
130  case(OPENRIGHT):whatAction = "OpenRight";
131  break;
132  }
133  name += ":" + whatAction;
134 
135  string descr("Action ");
136  descr += whatAction+" - #";
137  descr += strActionI + " of agent " + strAgentI;
138  ActionDiscrete ad_temp = ActionDiscrete(actionI,name,descr);
139  _m_actionVecs[agentIndex].push_back( ad_temp );
140  name.clear();
141  strActionI.clear();
142  strAgentI.clear();
143  whatAction.clear();
144  descr.clear();
145  }
146  }
147 }
148 
150 {
152  size_t nrJointObservations = 1;
153  for(Index agentIndex=0; agentIndex < _m_nrAgents; agentIndex++)
154  {
155  size_t nrObservationsThisAgent = NUMBER_OF_OBSERVATIONS;
156  nrJointObservations *= nrObservationsThisAgent;
157 
158  _m_nrObservations.push_back(nrObservationsThisAgent);
159  vector<ObservationDiscrete> ov_temp;
160  //Again, this is copied into _m_observationVecs, so no 'new' needed
161  _m_observationVecs.push_back( ov_temp );
162  for(Index obsI=0; obsI < nrObservationsThisAgent; obsI++)
163  {
164  string name("o");
165  stringstream ss;
166  string strObsI, strAgentI;
167  ss << agentIndex;
168  ss >> strAgentI;
169  name += strAgentI;
170  ss.clear();
171  ss << obsI;
172  ss >> strObsI;
173  name += strObsI;
174  string whatObs;
175  switch(obsI){
176  case(HEARLEFT): whatObs = "HearLeft";
177  break;
178  case(HEARRIGHT):whatObs = "HearRight";
179  break;
180  }
181  name += ":" + whatObs;
182 
183  string descr("Observation ");
184  descr += whatObs + " - #";
185  descr += strObsI + " of agent " + strAgentI;
186  ObservationDiscrete od_temp = ObservationDiscrete(obsI,name,descr);
187  _m_observationVecs[agentIndex].push_back( od_temp );
188  name.clear();
189  strObsI.clear();
190  strAgentI.clear();
191  whatObs.clear();
192  descr.clear();
193  }
194  }
195 }
196 
198 {
199  // add transitions:
200  for(Index s1=0; s1<NUMBER_OF_STATES;s1++)
201  for(Index s2=0; s2<NUMBER_OF_STATES;s2++)
202  for(Index ja=0; ja<GetNrJointActions(); ja++)
203  {
204  if(DEBUG_TM) cout << "ProblemDecTiger::FillTransitionModel() - calling SetTransitionProbability("<<s1<<", "<<ja<<", "<<s2<<", 0.5)"<<endl;
205  SetTransitionProbability(s1, ja, s2, 0.5);
206 
207  if(DEBUG_TM) cout << " - GetTransitionProb gives " << GetTransitionProbability(s1, ja, s2) << endl;
208  }
213 }
214 
216 {
217  for(Index ja=0; ja< GetNrJointActions(); ja++)
218  for(Index s1=0; s1<NUMBER_OF_STATES;s1++)
219  for(Index jo=0; jo<GetNrJointObservations();jo++)
220  {
221  double prob = 0;
222  if(ja != LISTEN_LISTEN)
223  {
224  prob = 0.25;
225  }
226  else if(jo == HEARLEFT_HEARLEFT)
227  {
228  if (s1 == SLEFT) prob = 0.85*0.85;
229  else if (s1 == SRIGHT) prob = 0.15*0.15;
230  }
231  else if(jo == HEARLEFT_HEARRIGHT)
232  {
233  if (s1 == SLEFT) prob = 0.85*0.15;
234  else if (s1 == SRIGHT) prob = 0.15*0.85;
235  }
236  else if(jo == HEARRIGHT_HEARLEFT)
237  {
238  if (s1 == SLEFT) prob = 0.85*0.15;
239  else if (s1 == SRIGHT) prob = 0.15*0.85;
240  }
241  else if(jo == HEARRIGHT_HEARRIGHT)
242  {
243  if (s1 == SLEFT) prob = 0.15*0.15;
244  else if (s1 == SRIGHT) prob = 0.85*0.85;
245  }
246  SetObservationProbability(ja, s1, jo, prob);
247  }
248 }
249 
251 {
270 }
271