ParserSelector.cpp
Go to the documentation of this file.
00001 
00002 #include "ParserSelector.h"
00003 #include "Parser.h" //Cassandra's parser
00004 #include "POMDP.h"
00005 
00006 
00007 using namespace momdp;
00008 using namespace std;
00009 
00010 ParserSelector::ParserSelector(void)
00011 {
00012 }
00013 
00014 ParserSelector::~ParserSelector(void)
00015 {
00016 }
00017 
00018 SharedPointer<MOMDP> ParserSelector::loadProblem(string problemName, SolverParams& solverParam)
00019 {
00020         SharedPointer<MOMDP> problem;
00021         // added from png shaowei's code
00022         ifstream myfile;
00023 
00024         myfile.open(problemName.c_str());
00025         string line;
00026         bool xmlfile = false;
00027         if (myfile.is_open()) 
00028         {
00029                 getline(myfile, line);
00030 
00031                 string first4chars = line.substr(0, 5);
00032                 if (first4chars == "<?xml") 
00033                 {
00034                         xmlfile = true;
00035                 }
00036         }
00037         else
00038         {
00039                 cout << "Cannot open file: " << problemName << endl;
00040                 exit(-1);
00041         }
00042         myfile.close();
00043 
00044         //FactoredPomdp test;
00045         if (xmlfile) 
00046         {
00047                 FactoredPomdp* factoredP = new FactoredPomdp(problemName);
00048                 unsigned int probType = factoredP->start(); // read in the file
00049                 bool flag_copyOldPOMDP = false;
00050                 switch (probType) 
00051                 {
00052                         // MOMDP Lite
00053                 case MIXED :
00054                         DEBUG_LOG(cout << "MIXED without reparam" << endl;);
00055 
00056                         factoredP->convertFactored();
00057                         if(solverParam.doConvertPOMDP)
00058                         {
00059                                 factoredP->convertFast();
00060                                 flag_copyOldPOMDP = true;
00061                         }
00062 
00063                         break;
00064 
00065                         // MOMDP proper
00066                 case MIXED_REPARAM:
00067                         DEBUG_LOG(cout << "mixed reparam. calling convertfactoredreparam" << endl;);
00068                         factoredP->convertFactoredReparam();
00069                         if(solverParam.doConvertPOMDP)
00070                         {
00071                                 factoredP->convertFast();
00072                                 flag_copyOldPOMDP = true;
00073                         }
00074                         DEBUG_LOG(cout << "mixed reparam. solver part is under working." << endl;);
00075                         // exit(0);
00076                         break;
00077 
00078                         // POMDP in POMDPX file format
00079                 case FULLY_UNOBSERVED:
00080 
00081                         DEBUG_LOG(cout << "fully unobserved " << endl;);
00082                         factoredP->convertFast();
00083                         break;
00084 
00085                 case FULLY_OBSERVED:
00086                         // MDP in this case
00087                         solverParam.MDPSolution = true;         //enable MDP solution
00088                         factoredP->convertFast();
00089                 }
00090 
00091                 //problem = new POMDP(&(factoredP->layer), flag_copyOldPOMDP, probType);
00092                 problem = MOMDP::convertMOMDPFromPOMDPX(factoredP, flag_copyOldPOMDP, probType);
00093 
00094                 delete factoredP;
00095         } 
00096         else 
00097         { 
00098                 // parse the problem using cassandra's parser and write parameters into the POMDP object (problem)
00099                 Parser* parser = new Parser();
00100                 POMDP* pomdpProblem = parser->parse(problemName, solverParam.useFastParser);
00101                 problem = MOMDP::convertMOMDPFromPOMDP(pomdpProblem);
00102         }
00103         return problem;
00104 }


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