MultiAgentDecisionProcess  Release 0.2.1
PolicyPoolPartialJPolValPair.cpp
Go to the documentation of this file.
1 
27 #include <float.h>
30 #define DEBUG_PPJPVP_ASSIGN 0
31 
32 using namespace std;
33 
34 //Default constructor
36 {
37  _m_jpvpQueue_p = new priority_queue<PartialJPDPValuePair*>(); //&JPolValPool;
38 }
39 
40 
41 //Copy constructor.
42 //PolicyPoolPartialJPolValPair::PolicyPoolPartialJPolValPair(const PolicyPoolPartialJPolValPair& o)
43 //{
44  //throw E("PolicyPoolPartialJPolValPair /Copy constructor. is not (and never will be?) defined.");
45 //}
46 //Destructor
48 {
49  while(_m_jpvpQueue_p->size() > 0)
50  {
51  delete _m_jpvpQueue_p->top();
52  _m_jpvpQueue_p->pop();
53  }
54  delete _m_jpvpQueue_p;
55 }
56 //Copy assignment operator
57 PolicyPoolPartialJPolValPair& PolicyPoolPartialJPolValPair::operator=
59 {
61  cout <<"PolicyPoolPartialJPolValPair& PolicyPoolPartialJPolValPair::operator= \
62 called"<<endl;
63 
64  if (this == &o) return *this; // Gracefully handle self assignment
65  // Put the normal assignment duties here...
66  //
67  // empty own queue
68  while(_m_jpvpQueue_p->size() > 0)
69  {
70  delete _m_jpvpQueue_p->top();
71  _m_jpvpQueue_p->pop();
72  }
73  *_m_jpvpQueue_p = *(o._m_jpvpQueue_p);
74 
75  return *this;
76 }
77 PartialPolicyPoolInterface& PolicyPoolPartialJPolValPair::operator=
79 {
81  cout <<"PartialPolicyPoolInterface& PolicyPoolPartialJPolValPair::operator= \
82 called."<<endl;
83  if (this == &o) return *this; // Gracefully handle self assignment
84  const PolicyPoolPartialJPolValPair& casted_o =
85  dynamic_cast<const PolicyPoolPartialJPolValPair&>(o);
86 
87  return(operator=(casted_o));
88 
89 }
90 
91 
93 {
94  //start with a horizon 0 joint policy - i.e. specifying 0 actions
95 #if 0 // old code, now we can specify the depth in the constructors,
96  // which prevents us from allocating huge vectors in case of
97  // high horizons
98  PartialJointPolicyPureVector* jpol_empty =
100  jpol_empty->SetDepth(0);
101 #else
102  PartialJointPolicyPureVector* jpol_empty =
103  new PartialJointPolicyPureVector(*pu, OHIST_INDEX, 0.0, 0);
104 #endif
105  PartialJPDPValuePair* jpv_empty = new PartialJPDPValuePair(*jpol_empty, DBL_MAX);
106  _m_jpvpQueue_p->push(jpv_empty);
107  //JPolValPool_p->push(jpv_empty);
108 }
109 
111 {
112  if(_m_jpvpQueue_p->size() > 0)
113  {
115  _m_jpvpQueue_p->top();
116  return(ppi);
117  }
118  else
119  throw E("Pool empty!");
120 
121 }
123 {
124  _m_jpvpQueue_p->pop();
125 }
126 
127 
129 {
130  PartialJPDPValuePair* jp = dynamic_cast<PartialJPDPValuePair*>(ppi);
131 
132  if(jp==0)
133  throw(E("PolicyPoolPartialJPolValPair::Insert could not cast input to PartialJPDPValuePair"));
134 
135  _m_jpvpQueue_p->push(jp);
136 
137 }
138 
140 {
141  PolicyPoolPartialJPolValPair * o = dynamic_cast<PolicyPoolPartialJPolValPair *>(o_ppi);
142 
143  if(o==0)
144  throw(E("PolicyPoolPartialJPolValPair::Union could not cast input to PolicyPoolPartialJPolValPair"));
145 
146  while(o->_m_jpvpQueue_p->size() > 0)
147  {
148  this->_m_jpvpQueue_p->push(o->_m_jpvpQueue_p->top());
149  o->_m_jpvpQueue_p->pop();
150  }
151 }
152 
154 {
155  priority_queue<PartialJPDPValuePair*> * new_jpvpQueue_p =
156  new priority_queue<PartialJPDPValuePair*>;
157 
158  while(_m_jpvpQueue_p->size() > 0)
159  {
160  PartialJPDPValuePair* jpvp = _m_jpvpQueue_p->top();
161  if(jpvp->GetValue() > v)
162  {
163  new_jpvpQueue_p->push(jpvp);
164  }
165  else
166  delete jpvp; // no longer necessary
167  _m_jpvpQueue_p->pop();
168  }
169 
170  delete _m_jpvpQueue_p; //delete old queue
171  _m_jpvpQueue_p = new_jpvpQueue_p; //point to new queue
172 
173 
174 }