Go to the documentation of this file.00001 #include "SimulationEngine.h"
00002 #include "AlphaVectorPolicy.h"
00003 #include "solverUtils.h"
00004 #include "Controller.h"
00005
00006 using namespace std;
00007 using namespace momdp;
00008
00009 namespace momdp
00010 {
00011 Controller::Controller(SharedPointer<MOMDP> problem,
00012 SharedPointer<AlphaVectorPolicy> policy,
00013 SolverParams* solverParams,
00014 int initialBeliefStvalX):
00015 problem(problem),
00016 policy(policy),
00017 solverParams(solverParams),
00018 currBelSt(new BeliefWithState()),
00019 firstAction(true), initialBeliefStvalX(initialBeliefStvalX)
00020 {
00021 reset(initialBeliefStvalX);
00022 }
00023
00024 void Controller::reset(int xstate)
00025 {
00026 firstAction = true;
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 currBelSt->sval = xstate;
00038
00039 cout << "inital state: " << currBelSt->sval << endl;
00040
00041
00042 SharedPointer<SparseVector> startBeliefVec;
00043 if (problem->initialBeliefStval->bvec)
00044 startBeliefVec = problem->initialBeliefStval->bvec;
00045 else
00046 startBeliefVec = problem->initialBeliefYByX[currBelSt->sval];
00047
00048 copy(*currBelSt->bvec, *startBeliefVec);
00049
00050 }
00051
00052 const int Controller::nextAction(ObsDefine currObservation,
00053 int nextStateX)
00054 {
00055 if (firstAction) {
00056 firstAction = false;
00057 }
00058 else
00059 {
00060
00061
00062
00063
00064
00065 SharedPointer<BeliefWithState> nextBelSt;
00066
00067
00068 nextBelSt = problem->beliefTransition->nextBelief(currBelSt, lastAction, currObservation, nextStateX);
00069
00070
00071 copy(*currBelSt->bvec, *nextBelSt->bvec);
00072 currBelSt->sval = nextBelSt->sval;
00073 }
00074
00075
00076 DenseVector currBelX;
00077
00078 int currAction;
00079 if (solverParams->useLookahead)
00080 currAction = policy->getBestActionLookAhead(*currBelSt);
00081 else
00082 currAction = policy->getBestAction(*currBelSt);
00083
00084 if (currAction < 0)
00085 {
00086 cerr << "You are using a MDP Policy, please make sure you are using a MDP policy together with one-step look ahead option turned on" << endl;
00087 return -1;
00088 }
00089
00090 lastAction = currAction;
00091
00092 return currAction;
00093 }
00094
00095 SharedPointer<BeliefWithState> Controller::currBelief() const
00096 {
00097 return currBelSt;
00098 }
00099 }