- Main Page
- Namespaces
- Classes
- Files
- Related Pages

# /Users/fpy/titan-1-5-MBARI/Mers/Executives/DeductiveController/Configs/DC_1_3-Standalone/DCTest.cpp

    00001
    00002 //
    00003 // Copyright (c) 2004           Model-based Embedded and Robotic Systems Group
    00004 // All Rights Reserved          Massachusetts Institute of Technology
    00005 //
    00006 // This software is provided as is. Model-based Embedded and Robotic Systems
    00007 // (MERS) group does not assume any responsibility.
    00008 //
    00009 // Organization:        Model-based Embedded and Robotic Systems Group
    00010 //                                      Massachusetts Institute of Technology
    00011 //
    00013
    00014 #include <Mers/Utils/Io/Xml/Sax/XMLLoader.h>
    00015
    00017
    00018 #ifdef FAILED
    00019 #undef FAILED
    00020 #endif
    00021
    00023
    00024 #include <Mers/Estimation/Discrete/ApproximateBeliefState/BFBSU/BFBSU.h>
    00025 #include <Mers/Estimation/Discrete/ProbabilityRules/RuleGenerator/ProbRuleGenerator.h>
    00026 #include <Mers/Estimation/Discrete/CompiledME/CCMEReader/CCMEReader.h>
    00027 #include <Mers/Estimation/Discrete/MEInterface.h>
    00028 #include <Mers/Solvers/Entailment/GI/GoalInterpreter.h>
    00029 #include <Mers/Models/CCA/CCAModel.h>
    00030 #include <Mers/Executives/DeductiveController/DCInterface.h>
    00031 #include <Mers/Estimation/Discrete/Trajectories.h>
    00032 #include <Mers/Estimation/Discrete/Io/Xml/Sax/TrajCH.h>
    00033 #include <Mers/Reconfiguration/Discrete/modeReconfiguration.h>
    00034 #include <Mers/Reconfiguration/Discrete/mrInterface.h>
    00035 #include <vector>
    00036
    00038
    00039 using Mers::Models::CCA::CCAModel;
    00040 using Mers::Models::Base::BaseModel;
    00041 using Mers::Estimation::Discrete::MEInterface;
    00042 using Mers::Estimation::Discrete::ApproximateBeliefState::BFBSU::BFBSU;
    00043 using Mers::Estimation::Discrete::ProbabilityRules::RuleGenerator::ProbRuleGenerator;
    00044 using Mers::Estimation::Discrete::ProbabilityRules::ObsProbRule;
    00045 using Mers::Estimation::Discrete::CompiledME::CCMEReader::CCMEReader;
    00046 using Mers::Estimation::Discrete::Dissent;
    00047 using Mers::Estimation::Discrete::ME_connection;
    00048 using Mers::Solvers::Entailment::GoalInterpreterInterface;
    00049 using Mers::Solvers::Entailment::GI::GoalInterpreter;
    00050 using Mers::Executives::DeductiveController::DCInterface;
    00051 using Mers::Estimation::Discrete::Trajectories;
    00052 using Mers::Estimation::Discrete::Io::Xml::Sax::TrajCH;
    00053 using Mers::Utils::Io::Xml::Sax::XMLLoader;
    00054 using Mers::Reconfiguration::Discrete::MR_connection;
    00055 // using Mers::Reconfiguration::Discrete::mrInterface;
    00056 // using Mers::Reconfiguration::Discrete::modeReconfiguration;
    00057 using std::vector;
    00058
    00060
    00061 void printUse( const char * progName )
    00062 {
    00063         printf("Use: %s <CCA file> <ME Init file> <CCME file> [<log4cplus file>]\n", progName);
    00064 }
    00065
    00067
    00068 bool requiredParameters(int argc, const char * progName) {
    00069         if(argc != 3 && argc != 4){
    00070                 printUse( (progName == NULL ? "DCTest" : progName) );
    00071                 return false;
    00072         } else {
    00073                 return true;
    00074         }
    00075 }
    00076
    00078
    00079 class Arguments
    00080 {
    00081 public:
    00082         CCAModel * ccaModel;
    00083         const char * modelFileName;
    00084         const char * trajFileName;
    00085         const char * obsProbsFileName;
    00086         const char * log4cplusFileName;
    00087 };
    00088
    00090
    00091 CCAModel *      load_MOF(char const * MOF_file_name);
    00092
    00094
    00095 Arguments * loadParameters(int argc, const char * argv[]) {
    00096         Arguments * args = new Arguments();
    00097         args->ccaModel = load_MOF(argv[0]);
    00098         args->modelFileName = argv[0];
    00099         args->trajFileName = argv[1];
    00100         args->obsProbsFileName = argv[2];
    00101         if(argc > 3)
    00102                 args->log4cplusFileName = argv[3];
    00103         else
    00104                 args->log4cplusFileName = NULL;
    00105         return args;
    00106 }
    00107
    00109
    00110 ME_connection * constructME(Arguments * args) {
    00111         Trajectories * trajs;
    00112         // Load the Trajectories.
    00113         if( FAILED(
    00114                 XMLLoader::load< Trajectories *, const BaseModel *, TrajCH >
    00115                 ( args->trajFileName, trajs, args->ccaModel ) ) )
    00116         {
    00117                 trajs = NULL;
    00118         }
    00119
    00120         // Load the CCME file
    00121         CCMEReader reader;
    00122         if( FAILED( reader.loadCCMEFile( args->obsProbsFileName, *args->ccaModel) ) )
    00123         {
    00124                 fprintf(stderr, "Could not load \"%s\".\n", args->obsProbsFileName);
    00125                 exit(-1);
    00126         }
    00127
    00128         // Get our dissents and transitions.
    00129         vector<const Dissent *> dissents = reader.getDissents();
    00130
    00131         // Get the probability rules
    00132         ProbRuleGenerator * myPRG =
    00133                 new ProbRuleGenerator(args->ccaModel, dissents, 1);
    00134         vector<const ObsProbRule *> obsProbabilityRules =
    00135                 myPRG->getObservationRules();
    00136
    00137         BFBSU * me = new BFBSU(*(args->ccaModel), obsProbabilityRules, trajs);
    00138
    00139         return new MEInterface( me );
    00140 }
    00141
    00143
    00144 GoalInterpreterInterface * constructGI(Arguments * args) {
    00145         return new GoalInterpreter(args->ccaModel);
    00146 }
    00147
    00149
    00150 MR_connection * constructMR(Arguments * args) {
    00151         modeReconfiguration * mr =
    00152                 new modeReconfiguration( *args->ccaModel, constructGI( args ) );
    00153         return new mrInterface( *mr );
    00154 }
    00155
    00157
    00158 void CreateChildren( Arguments * args, DCInterface * dc ) {
    00159         // Don't have any children to create.
    00160         (void) args;
    00161         (void) dc;
    00162 }
    00163
    00165
    00166 #include <Mers/Executives/DeductiveController/DeductiveController.cpp>
    00167
    00169