AlphaPlane.cpp
Go to the documentation of this file.
00001 #include "AlphaPlane.h"
00002 #include "SARSOP.h"
00003 #include <exception>
00004 #include <stdexcept>
00005 
00006 using namespace std;
00007 
00008 
00009 AlphaPlane::AlphaPlane(void) : alpha (new alpha_vector())
00010 {
00011         
00012         solverData = new SARSOPAlphaPlaneTuple();
00013 }
00014 SharedPointer<AlphaPlane> AlphaPlane::duplicate()
00015 {
00016         SharedPointer<AlphaPlane> result ( new AlphaPlane());
00017         result->alpha = SharedPointer<alpha_vector> (new alpha_vector());
00018         copy(*result->alpha, *this->alpha);
00019         result->action = this->action;
00020         result->sval = this->sval;
00021         result->solverData = new SARSOPAlphaPlaneTuple();
00022         return result;
00023 }
00024 
00025 
00026 AlphaPlane::~AlphaPlane(void)
00027 {
00028 }
00029 
00030 void AlphaPlane::init(int _timeStamp, BeliefTreeNode* _birthBelief)
00031 {
00032         setTimeStamp(_timeStamp);
00033         SARSOPAlphaPlaneTuple *attachedData = (SARSOPAlphaPlaneTuple *)this->solverData;
00034         attachedData->certed = 0;//init certed number
00035         //add the current belief to dominated beliefs of the new plane
00036         attachedData->certifiedBeliefs.push_back(_birthBelief);
00037         //add the alpha plane's timestamp on this belief to its timestamp list
00038         attachedData->certifiedBeliefTimeStamps.push_back(_timeStamp);
00039 }
00040 
00041 void AlphaPlane::copyFrom(SharedPointer<alpha_vector> _alpha, int _action, state_val _sval)
00042 {
00043         this->alpha = _alpha;
00044         this->action = _action;
00045         this->sval = _sval;
00046 }
00047 void AlphaPlane::setTimeStamp(int _timeStamp)
00048 {
00049         timeStamp = _timeStamp;
00050 }
00051 
00052 // TODO: Migrate to prunning section
00053 //Functionality:
00054 //      add belief to its dominated list if it's not already in 
00055 void AlphaPlane::addDominatedBelief(int _timeStamp, BeliefTreeNode* _belief)
00056 {
00057         SARSOPAlphaPlaneTuple *planeTuple = (SARSOPAlphaPlaneTuple *)(this->solverData);
00058         if(!certDuplicated(_belief))
00059         {
00060                 //add the current belief to dominated beliefs of the new plane
00061                 planeTuple->certifiedBeliefs.push_back(_belief);
00062                 //add the alpha plane's timestamp on this belief to its timestamp list
00063                 planeTuple->certifiedBeliefTimeStamps.push_back(_timeStamp);
00064 
00065         }
00066 }
00067 
00068 bool AlphaPlane::certDuplicated(BeliefTreeNode* n)
00069 {
00070         SARSOPAlphaPlaneTuple *planeTuple = (SARSOPAlphaPlaneTuple *)(this->solverData);
00071         int size = (int)planeTuple->certifiedBeliefs.size();
00072         for(int i=0; i<size; i++){
00073                 BeliefTreeNode* ni = planeTuple->certifiedBeliefs.at(i);
00074                 if (ni==n)
00075                 {
00076                         return true;
00077                 }
00078         }
00079         return false;
00080 }
00081 
00082 //write this alpha plane to file
00083 void AlphaPlane::write(std::ofstream& out) const
00084 {
00085     out << "<Vector action=\"" << action <<"\" obsValue=\"" << sval << "\">";
00086     int n = alpha->size();
00087     FOR (i, n) 
00088     {
00089         out << (*alpha)(i) << " ";
00090     }
00091     out << "</Vector>" << endl;
00092 }
00093 
00094 void AlphaPlane::writeSparse(std::ofstream& out) const
00095 {
00096     out << "<SparseVector action=\"" << action <<"\" obsValue=\"" << sval << "\">";
00097     int n = alpha->size();
00098     FOR (i, n) 
00099     {
00100         if(abs((*alpha)(i))>1e-10){
00101             out << "<Entry>";
00102             out <<i <<" "<< (*alpha)(i);
00103             out << "</Entry>";
00104         }
00105     }
00106     out << "</SparseVector>" << endl;
00107 }
00108 
00109 //write this alpha plane to file in the old IV format
00110 /*void AlphaPlane::write(std::ostream& out) const
00111 {
00112         out << "    {" << endl;
00113         out << "      action => " << action << "," << endl;
00114         out << "      observed state val => " << sval << "," << endl;
00115         out << "      numEntries => " << alpha->size() << "," << endl;
00116         out << "      entries => [" << endl;
00117         int n = alpha->size();
00118         FOR (i, n-1) 
00119         {
00120                 out << "        " << i << ", " << (*alpha)(i) << "," << endl;
00121         }
00122         out << "        " << (n-1) << ", " << (*alpha)(n-1) << endl;
00123 
00124         out << "      ]" << endl;
00125         out << "    }";
00126 }
00127 */      


appl
Author(s): petercai
autogenerated on Tue Jan 7 2014 11:02:28