Go to the documentation of this file.00001 #include <stdexcept>
00002 #include "MOMDP.h"
00003 #include "Sample.h"
00004 #include "BeliefCache.h"
00005 #include "BeliefForest.h"
00006 #include "BeliefTreeNode.h"
00007 #include "PointBasedAlgorithm.h"
00008 #include "MObject.h"
00009
00010
00011 #include "vector"
00012 using namespace std;
00013
00014
00015 BeliefForest::BeliefForest()
00016 {
00017 sampleEngine == NULL;
00018 }
00019
00020
00021 BeliefForest::~BeliefForest(void)
00022 {
00023
00024 if(sampleEngine != NULL)
00025 {
00026 delete sampleEngine;
00027 }
00028
00029
00030 }
00031 void BeliefForest::print()
00032 {
00033 for(vector<SampleRootEdge*>::iterator iter1= sampleRootEdges.begin() ; iter1!= sampleRootEdges.end() ; iter1++)
00034 {
00035 SampleRootEdge* edge = *iter1;
00036 if(edge == NULL)
00037 {
00038 cout << "NULL" << endl;
00039 }
00040 else
00041 {
00042 edge->sampleRoot->print();
00043 }
00044
00045 }
00046 }
00047
00048
00049 void BeliefForest::globalRootPrepare(void)
00050 {
00051 DEBUG_TRACE( cout << "Sample::globalRootPrepare" << endl; );
00052 belief_vector rootpv;
00053
00054 rootpv = obsVar_bvec;
00055
00056 sampleRootEdges.resize(rootpv.size());
00057 DEBUG_TRACE( cout << "rootpv" << endl; );
00058 DEBUG_TRACE( rootpv.write(cout) << endl; );
00059
00060 FOR(r, rootpv.size())
00061 {
00062 double rprob = rootpv(r);
00063 if (rprob > OBS_IS_ZERO_EPS)
00064 {
00065 SharedPointer<BeliefWithState> thisRootb_s (new BeliefWithState());
00066 copy(*thisRootb_s->bvec, *problem->getInitialBeliefY(r));
00067 thisRootb_s->bvec->finalize();
00068
00069 SampleRootEdge* rE = new SampleRootEdge();
00070 sampleRootEdges[r] = rE;
00071 rE->sampleRootProb = rprob;
00072 thisRootb_s->sval = r;
00073 rE->sampleRoot = sampleEngine->getNode(thisRootb_s);
00074
00075 double lb = (*beliefCacheSet)[rE->sampleRoot->cacheIndex.sval]->getRow(rE->sampleRoot->cacheIndex.row)->LB;
00076
00077
00078 rE->sampleRoot->count = 1;
00079
00080 }
00081 else
00082 {
00083 sampleRootEdges[r] = NULL;
00084 }
00085
00086 }
00087
00088
00089
00090 double lbSum =0, ubSum = 0;
00091
00092 FOR(r, sampleRootEdges.size())
00093 {
00094 SampleRootEdge* eR = sampleRootEdges[r];
00095
00096 if (NULL != eR)
00097 {
00098 BeliefTreeNode & sn = *eR->sampleRoot;
00099 lbSum =+ (eR->sampleRootProb) * (*beliefCacheSet)[sn.cacheIndex.sval]->getRow(sn.cacheIndex.row)->LB;
00100
00101 ubSum =+ (eR->sampleRootProb) * (*beliefCacheSet)[sn.cacheIndex.sval]->getRow(sn.cacheIndex.row)->UB;
00102
00103
00104
00105
00106
00107
00108 }
00109 }
00110 lbVal = lbSum;
00111 ubVal = ubSum;
00112 }
00113
00114 void BeliefForest::forcedDelete(SharedPointer<Belief> pointer)
00115 {
00116 throw runtime_error("not implemented");
00117 }
00118
00119 void BeliefForest::setup(SharedPointer<MOMDP> problem, Sample* _sampleEngine, vector <BeliefCache *> *_beliefCacheSet)
00120 {
00121 this->sampleEngine = _sampleEngine;
00122 this->beliefCacheSet = _beliefCacheSet;
00123 this->problem = problem;
00124
00125
00126 copy(obsVar_bvec, *(problem->initialBeliefX));
00127
00128
00129
00130 lbVal = -1;
00131 ubVal = -1;
00132
00133 }