MultiAgentDecisionProcess  Release 0.2.1
PolicyPoolJPolValPair.cpp
Go to the documentation of this file.
1 
27 #include <float.h>
28 #include "PolicyPoolJPolValPair.h"
29 #include "JPPVValuePair.h"
30 #include "JointPolicyPureVector.h"
31 #define DEBUG_PPJPVP_ASSIGN 0
32 
33 using namespace std;
34 
35 //Default constructor
37 {
38  _m_jpvpQueue_p = new priority_queue<JointPolicyValuePair*>(); //&JPolValPool;
39 }
40 
41 //Destructor
43 {
44  while(_m_jpvpQueue_p->size() > 0)
45  {
46  delete _m_jpvpQueue_p->top();
47  _m_jpvpQueue_p->pop();
48  }
49  delete _m_jpvpQueue_p;
50 }
51 //Copy assignment operator
52 PolicyPoolJPolValPair& PolicyPoolJPolValPair::operator=
54 {
56  cout <<"PolicyPoolJPolValPair& PolicyPoolJPolValPair::operator= \
57 called"<<endl;
58 
59  if (this == &o) return *this; // Gracefully handle self assignment
60  // Put the normal assignment duties here...
61  //
62  // empty own queue
63  while(_m_jpvpQueue_p->size() > 0)
64  {
65  delete _m_jpvpQueue_p->top();
66  _m_jpvpQueue_p->pop();
67  }
68  *_m_jpvpQueue_p = *(o._m_jpvpQueue_p);
69 
70  return *this;
71 }
72 PolicyPoolInterface& PolicyPoolJPolValPair::operator=
74 {
76  cout <<"PolicyPoolInterface& PolicyPoolJPolValPair::operator= \
77 called."<<endl;
78  if (this == &o) return *this; // Gracefully handle self assignment
79  const PolicyPoolJPolValPair& casted_o =
80  dynamic_cast<const PolicyPoolJPolValPair&>(o);
81 
82  return(operator=(casted_o));
83 
84 }
85 
86 
88 {
89  //start with a horizon 0 joint policy - i.e. specifying 0 actions
90  JointPolicyPureVector* jpol_empty =
92  jpol_empty->SetDepth(0);
93  JointPolicyValuePair* jpv_empty = new JPPVValuePair(*jpol_empty, DBL_MAX);
94  _m_jpvpQueue_p->push(jpv_empty);
95  //JPolValPool_p->push(jpv_empty);
96 }
97 
99 {
100  if(_m_jpvpQueue_p->size() > 0)
101  {
103  _m_jpvpQueue_p->top();
104  return(ppi);
105  }
106  else
107  throw E("Pool empty!");
108 
109 }
111 {
112  _m_jpvpQueue_p->pop();
113 }
114 
115 
117 {
118  JointPolicyValuePair* jp = dynamic_cast<JointPolicyValuePair*>(ppi);
119 
120  if(jp==0)
121  throw(E("PolicyPoolJPolValPair::Insert could not cast input to JointPolicyValuePair"));
122 
123  _m_jpvpQueue_p->push(jp);
124 
125 }
126 
128 {
129  PolicyPoolJPolValPair * o = dynamic_cast<PolicyPoolJPolValPair *>(o_ppi);
130 
131  if(o==0)
132  throw(E("PolicyPoolJPolValPair::Union could not cast input to PolicyPoolJPolValPair"));
133 
134  while(o->_m_jpvpQueue_p->size() > 0)
135  {
136  this->_m_jpvpQueue_p->push(o->_m_jpvpQueue_p->top());
137  o->_m_jpvpQueue_p->pop();
138  }
139 }
140 
142 {
143  priority_queue<JointPolicyValuePair*> * new_jpvpQueue_p =
144  new priority_queue<JointPolicyValuePair*>;
145 
146  while(_m_jpvpQueue_p->size() > 0)
147  {
148  JointPolicyValuePair* jpvp = _m_jpvpQueue_p->top();
149  if(jpvp->GetValue() > v)
150  {
151  new_jpvpQueue_p->push(jpvp);
152  }
153  else
154  delete jpvp; // no longer necessary
155  _m_jpvpQueue_p->pop();
156  }
157 
158  delete _m_jpvpQueue_p; //delete old queue
159  _m_jpvpQueue_p = new_jpvpQueue_p; //point to new queue
160 
161 
162 }