MultiAgentDecisionProcess  Release 0.2.1
DecPOMDPDiscrete.cpp
Go to the documentation of this file.
1 
28 #include "DecPOMDPDiscrete.h"
29 #include "RGet.h"
30 #include "RewardModelMapping.h"
32 
33 using namespace std;
34 
35 #define DEBUG_DPOMDPD 0
36 //Debug Fill DecPOMDP Discrete - functions to initialize the DecPOMDPDiscrete
37 //(typically from a file)
38 #define DEBUG_FILLDPD 0
39 
40 DecPOMDPDiscrete::DecPOMDPDiscrete(string name, string descr, string pf) :
41  MultiAgentDecisionProcessDiscrete(name, descr, pf)
42 {
43  _m_initialized = false;
44  _m_p_rModel = 0;
45 }
46 
48 {
49  if(DEBUG_DPOMDPD)
50  cout << "deleting DecPOMDPDiscrete (deleting rewards)"<<endl;
51  delete(_m_p_rModel);
52 }
53 
55 {
57  {
58  _m_initialized = b;
59  return(true);
60  }
61  else
62  return(false);
63 }
64 
66 {
67  if(_m_initialized)
68  delete(_m_p_rModel);
69 
70  if(GetSparse())
72  else
74 }
75 
77 {
78  return new RGet_RewardModelMapping(
80 }
81 
83 {
84  stringstream ss;
86  ss << DecPOMDP::SoftPrint();
87 
88  if(_m_initialized)
89  {
90  ss << "Reward model: " << endl;
91  ss << _m_p_rModel->SoftPrint();
92  }
93  else
94  throw E("DecPOMDPDiscrete components (reward model) not initialized");
95 
96  return(ss.str());
97 }
98 
99 void DecPOMDPDiscrete::SetReward(Index sI, Index jaI, Index sucSI, double r)
100 {
101  double rOld=GetReward(sI,jaI),
102  rExp=GetTransitionProbability(sI,jaI,sucSI)*r;
103  SetReward(sI,jaI,rOld+rExp);
104 }
105 
107  Index joI, double r)
108 {
109  throw(E("DecPOMDPDiscrete::SetReward(sI,jaI,sucSI,joI,r) not implemented"));
110 }
111 
112 void
114 {
115  madp->SetNrAgents(GetNrAgents());
116  madp->SetName(GetName());
118 
119  // transition model
120  madp->SetTransitionModelPtr(
121  const_cast<TransitionModelDiscrete*>(GetTransitionModelDiscretePtr()));
122 
123  // observation model
125  const_cast<ObservationModelDiscrete*>(GetObservationModelDiscretePtr()));
126 
127  // MADPComponentDiscreteStates
128  for(Index s=0;s!=GetNrStates();++s)
129  madp->AddState(GetState(s)->GetName());
130 
131  madp->SetISD(GetISD());
132 
133  // MADPComponentDiscreteObservations
134  for(Index id=0;id!=GetNrAgents();++id)
135  for(Index o=0;o!=GetNrObservations(id);++o)
136  madp->AddObservation(id,GetObservation(id,o)->GetName());
138 
139  // MADPComponentDiscreteActions
140  for(Index id=0;id!=GetNrAgents();++id)
141  for(Index o=0;o!=GetNrActions(id);++o)
142  madp->AddAction(id,GetAction(id,o)->GetName());
143  madp->ConstructJointActions();
144 
145  madp->Initialize();
146 }