00001 #include "BeliefTransitionMOMDP.h"
00002 #include "MOMDP.h"
00003 #include "BeliefWithState.h"
00004 #include "Observations.h"
00005 #include "exception"
00006
00007 using namespace std;
00008
00009 BeliefTransitionMOMDP::BeliefTransitionMOMDP(void)
00010 {
00011 }
00012
00013 BeliefTransitionMOMDP::~BeliefTransitionMOMDP(void)
00014 {
00015 }
00016
00017
00018
00019 SharedPointer<BeliefWithState> BeliefTransitionMOMDP::nextBelief(SharedPointer<belief_vector>& belY, DenseVector& belX, int a, int o, int obsX)
00020 {
00021 SharedPointer<MOMDP> momdpProblem = dynamic_pointer_cast<MOMDP> (problem);
00022 SharedPointer<BeliefWithState> result (new BeliefWithState());
00023
00024 DenseVector Bc;
00025 copy(Bc, *belY);
00026
00027 unsigned int xn = obsX;
00028
00029
00030
00031 if (!((momdpProblem->obsProb->getMatrix(a, xn))->isColumnEmpty(o)))
00032 {
00033 SparseVector jspv_sum;
00034 jspv_sum.resize(momdpProblem->YStates->size());
00035
00036
00037 FOR (xc, momdpProblem->XStates->size())
00038 {
00039 if (!(belX(xc) == 0))
00040 {
00041
00042
00043 if (!((momdpProblem->XTrans->getMatrix(a, xc))->isColumnEmpty(xn)))
00044 {
00045 DenseVector tmp, tmp1;
00046 SparseVector jspv;
00047
00048 emult_column( tmp, *(momdpProblem->XTrans->getMatrix(a, xc)), xn, Bc );
00049
00050 mult( tmp1, *(momdpProblem->YTrans->getMatrixTr(a, xc, xn)), tmp );
00051 copy(jspv, tmp1);
00052
00053
00054 jspv *= belX(xc);
00055 jspv_sum += jspv;
00056 }
00057 }
00058 }
00059
00060 emult_column( *result->bvec, *(momdpProblem->obsProb->getMatrix(a, xn)), o, jspv_sum);
00061
00062
00063 if (!(result->bvec->data.size() == 0)) {
00064
00065
00066 (*result->bvec) *= (1.0/result->bvec->norm_1());
00067 } else throw runtime_error("In nextBelief(), the combination of b, a, o and x' is not possible.");
00068
00069 } else throw runtime_error("In nextBelief(), the combination of b, a, o and x' is not possible.");
00070 result->bvec->finalize();
00071 result->sval = obsX;
00072 return result;
00073
00074 }
00075
00076
00077
00078
00079 SharedPointer<BeliefWithState> BeliefTransitionMOMDP::nextBelief(SharedPointer<BeliefWithState> bp, int a, int o, int obsX )
00080 {
00081 SparseVector jspv;
00082 SharedPointer<MOMDP> momdpProblem = dynamic_pointer_cast<MOMDP> (problem);
00083
00084 momdpProblem->getJointUnobsStateProbVector(jspv, bp , a, obsX);
00085
00086
00087
00088
00089
00090 SharedPointer<BeliefWithState> result (new BeliefWithState());
00091 emult_column( *result->bvec, *(momdpProblem->obsProb->getMatrix(a, obsX)), o, jspv);
00092 (*result->bvec) *= (1.0/result->bvec->norm_1());
00093
00094 result->sval = obsX;
00095 return result;
00096
00097 }
00098
00099
00100
00101 SharedPointer<BeliefWithState> BeliefTransitionMOMDP::nextBelief2(SharedPointer<BeliefWithState> bp, int a, int o, int obsX, SharedPointer<SparseVector>& jspv )
00102 {
00103 SharedPointer<MOMDP> momdpProblem = dynamic_pointer_cast<MOMDP> (problem);
00104
00105
00106
00107 SharedPointer<BeliefWithState> result (new BeliefWithState());
00108 emult_column( *result->bvec, *(momdpProblem->obsProb->getMatrix(a, obsX)), o, *jspv);
00109 (*result->bvec) *= (1.0/result->bvec->norm_1());
00110
00111 result->sval = obsX;
00112 return result;
00113
00114 }