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

# /Users/fpy/titan-1-5-MBARI/Mers/Estimation/Discrete/ModeEstimationPerformance/MEperformanceDriverUtils.h

    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 // Author:                      Oliver B. Martin
    00010 // Organization:        Model-based Embedded and Robotic Systems Group
    00011 //                                      Massachusetts Institute of Technology
    00012 //
    00013 // Mode Estimation Requirements Driver Utilities
    00014 //
    00015 //=============================================================================
    00016
    00017 #ifdef _MSC_VER
    00018 #pragma warning( disable : 4786 )
    00019 #endif
    00020
    00021 #include <iostream>
    00022 #include <fstream>
    00023 #include <vector>
    00024 #include <ctime>
    00025 #include <Mers/Utils/Lang/String.h>
    00026 #include <Mers/Utils/Containers/IntegerArray.h>
    00027
    00028 #include <Mers/Models/CCA/CCAModel.h>
    00029 #include <Mers/Models/CCA/Io/Mof/MOFReader.h>
    00030
    00031 #include <Mers/Models/Base/BaseModel.h>
    00032 #include <Mers/Models/Base/BaseModelVariable.h>
    00033 #include <Mers/Models/Base/BaseModelVariableArray.h>
    00034 #include <Mers/Models/Base/BaseModelAssignment.h>
    00035 #include <Mers/Models/Base/BaseModelAssignmentArray.h>
    00036 #include <Mers/Models/Base/Io/Mof/BaseModelReader.h>
    00037
    00038 #include <Mers/Estimation/Discrete/Dissent.h>
    00039 #include <Mers/Estimation/Discrete/CompiledTransition.h>
    00040 #include <Mers/Estimation/Discrete/Estimate.h>
    00041 #include <Mers/Estimation/Discrete/Trajectories.h>
    00042
    00043 //OM #define METYPE ModeEstimatorDebug
    00044 #define METYPE BFBSE
    00045 //OM #define METYPE StaticOCSPEstimateEnumerator
    00046 //OM #define METYPE DynamicModeEstimateGenerator
    00047
    00048 #include <Mers/Estimation/Discrete/ModeEstimationPerformance/Monitor/ModeEstimatorDebug.h>
    00049
    00050 // Uncompiled ME
    00051 #include <Mers/Estimation/Discrete/ApproximateBeliefState/BFBSE/BFBSE.h>
    00052 #include <Mers/Estimation/Discrete/ApproximateBeliefState/StaticOCSPEstimateEnumeration/StaticOCSPEstimateEnumerator.h>
    00053 #include <Mers/Estimation/Discrete/ApproximateBeliefState/DynamicModeEstimateGeneration/DynamicModeEstimateGenerator.h>
    00054
    00055 #define CMETYPE CompiledBFBSE
    00056
    00057 // Compiled ME
    00058 #include <Mers/Estimation/Discrete/ApproximateBeliefState/CompiledBFBSE/CompiledBFBSE.h>
    00059 #include <Mers/Estimation/Discrete/CompiledME/CCMEReader/CCMEReader.h>
    00060
    00061 // ME with Observation Probabilities
    00062 #include <Mers/Estimation/Discrete/ApproximateBeliefState/BFBSU/BFBSU.h>
    00063 #include <Mers/Estimation/Discrete/ProbabilityRules/RuleGenerator/ProbRuleGenerator.h>
    00064 #include <Mers/Estimation/Discrete/ProbabilityRules/ObsProbRule.h>
    00065
    00066 // ME with DNNFs (CCANNF)
    00067 #include <Mers/Estimation/Discrete/NNF/DME.h>
    00068 #include <Mers/Estimation/Discrete/NNF/DMEPerformanceMonitor.h>
    00069 #include <Mers/Models/Conversion/CCAToDimacs/CCANNF.h>
    00070 #include <Mers/Utils/Io/Xml/Dom/XMLSaveLoad.h>
    00071 #include <Mers/Utils/Io/Xml/Dom/XMLLoader.h>
    00072 #include <Mers/Utils/Io/Xml/XercesSetup.h>
    00073
    00074 #define DMETYPE DME
    00075 #define DMEPMTYPE DMEPerformanceMonitor
    00076
    00077
    00078 #include <Mers/Estimation/Discrete/MEdriverUtils.h>
    00079 #include <Mers/Estimation/Discrete/ModeEstimationPerformance/Monitor/MEPerformanceMonitor.h>
    00080 #include <Mers/Utils/Logging/logger.h>
    00081
    00082 using Mers::Estimation::Discrete::ApproximateBeliefState::BFBSE::BFBSE;
    00083 using namespace Mers::Estimation::Discrete::ModeEstimationPerformance;
    00084 using namespace Mers::Estimation::Discrete::ModeEstimation;
    00085 using namespace Mers::Estimation::Discrete;
    00086 using Mers::Estimation::Discrete::ApproximateBeliefState::CompiledBFBSE::CompiledBFBSE;
    00087
    00088 using Mers::Estimation::Discrete::NNF::DME;
    00089 using Mers::Estimation::Discrete::NNF::DMEPerformanceMonitor;
    00090 using Mers::Models::Conversion::CCAToDimacs::CCANNF;
    00091 using Mers::Utils::Io::Xml::Dom::XMLSaveLoad;
    00092 using Mers::Utils::Io::Xml::Dom::XMLLoader;
    00093 using Mers::Utils::Io::Xml::XercesSetup;
    00094 using Mers::Utils::Io::SaveLoad::ISaveLoad;
    00095 using XERCES_CPP_NAMESPACE::DOMDocument;
    00096
    00097 using Mers::Estimation::Discrete::ApproximateBeliefState::BFBSU::BFBSU;
    00098 using Mers::Estimation::Discrete::ProbabilityRules::RuleGenerator::ProbRuleGenerator;
    00099 using Mers::Estimation::Discrete::ProbabilityRules::ObsProbRule;
    00100
    00101 using Mers::Estimation::Discrete::CompiledME::CCMEReader::CCMEReader;
    00102 using Mers::Models::CCA::CCAModel;
    00103 using Mers::Models::CCA::Io::Mof::MOFReader;
    00104 using Mers::Models::Base::Io::Mof::BaseModelReader;
    00105 using std::ifstream;
    00106 using std::ofstream;
    00107 using std::istream;
    00108 using std::ostream;
    00109 using std::cin;
    00110 using std::cout;
    00111 using std::cerr;
    00112 using std::endl;
    00113 using std::flush;
    00114
    00115
    00116 // Common Function Prototypes
    00117 void    printUse(void);
    00118 void    run_ME_shell(ModeEstimatorBase * meb, MEPerformanceMonitor * mepm, BaseModel &model, istream &inputStream, ostream &outStream, ostream &timeOutStream);
    00119
    00120 // Function Prototypes for Leaks memory analysis
    00121 size_t currentStackSize(void);
    00122 void beginMonitoringStack(void);
    00123 size_t maxIncreaseSinceBeginMonitor(void);
    00124 size_t maxStackEver(void);
    00125
    00126 void
    00127 print_ME_shell_help(const char ch, ostream &outStream)
    00128 {
    00129         switch (ch)
    00130         {
    00131                 case 'a':
    00132                 case 'A':
    00133                         outStream << "NAME" << endl;
    00134                         outStream << "\ta - assert" << endl << endl;
    00135                         outStream <<    "SYNOPSIS" << endl;
    00136                         outStream << "\ta [OPTION] var val..." << endl << endl;
    00137                         outStream << "DESCRIPTION" << endl;
    00138                         outStream << "\tAssert (var = val) into ME" << endl << endl;
    00139                         outStream << "\t-s\tassert state variable assignment (trajectories truncated)" << endl;
    00140                         outStream << "\t-u\tassert command variable assignment" << endl;
    00141                         outStream << "\t-o\tassert observation variable assignment" << endl;
    00142                         outStream << "\t-b #\tassert trajectory with probability #" << endl;
    00143                         break;
    00144                 case 'e':
    00145                 case 'E':
    00146                         outStream << "NAME" << endl;
    00147                         outStream << "\te - estimate" << endl << endl;
    00148                         outStream <<    "SYNOPSIS" << endl;
    00149                         outStream << "\te [OPTION]" << endl << endl;
    00150                         outStream << "DESCRIPTION" << endl;
    00151                         outStream << "\tEstimates the next state of the system and displays the most" << endl;
    00152                         outStream << "\tlikely estimate to the screen." << endl << endl;
    00153                         outStream << "\t-e\tcalculates and displays the most likely estimate" << endl;
    00154                         outStream << "\t-p\tprogresses Titan into the most likely estimate" << endl;
    00155                         break;
    00156                 case 't':
    00157                 case 'T':
    00158                         outStream << "NAME" << endl;
    00159                         outStream << "\tt - timer" << endl << endl;
    00160                         outStream <<    "SYNOPSIS" << endl;
    00161                         outStream << "\tt [OPTION]" << endl << endl;
    00162                         outStream << "DESCRIPTION" << endl;
    00163                         outStream << "\tStarts and stops the timer. Results are recorded when timer stops. Default option" << endl;
    00164                         outStream << "\tstarts the timer." << endl << endl;
    00165                         outStream << "\t-b\tstarts/resets the timer" << endl;
    00166                         outStream << "\t-e\tstops the timer" << endl;
    00167                         break;
    00168                 case 'r':
    00169                 case 'R':
    00170                         outStream << "NAME" << endl;
    00171                         outStream << "\tr - reset" << endl << endl;
    00172                         outStream <<    "SYNOPSIS" << endl;
    00173                         outStream << "\tr " << endl << endl;
    00174                         outStream << "DESCRIPTION" << endl;
    00175                         outStream << "\tResets all commands and observations."
    00176                                  << endl;
    00177                         break;
    00178                 case 'h':
    00179                 case 'H':
    00180                         outStream << "  var val ...            : assert (var = val) using integer UIDs or string names" << endl;
    00181                         outStream << "  a [option] var val ... : assert (var = val) for specified types and trajectories" << endl;
    00182                         outStream << "  e [option]             : estimate the next state" << endl;
    00183                         outStream << "  k #                    : sets the maximum number of trajectories" << endl;
    00184                         outStream << "  r                      : resets commands and observations" << endl;
    00185                         outStream << "  v [option]             : displays variables" << endl;
    00186                         outStream << "  h [option]             : displays this help" << endl;
    00187                         outStream << "  t [option]             : starts/stops timer" << endl;
    00188                         outStream << "  d #                    : sets the debug level" << endl;
    00189                         outStream << "  #                      : toggle echo input" << endl;
    00190                         outStream << "  q                      : quit" << endl;
    00191                         outStream << endl;
    00192                         break;
    00193                 case 'd':
    00194                 case 'D':
    00195                         outStream << "NAME" << endl;
    00196                         outStream << "\td - Debug level" << endl << endl;
    00197                         outStream <<    "SYNOPSIS" << endl;
    00198                         outStream << "\td #" << endl << endl;
    00199                         outStream << "DESCRIPTION" << endl;
    00200                         outStream << "\tSets the debug level to #."
    00201                                  << endl;
    00202                         break;
    00203                 case 'k':
    00204                 case 'K':
    00205                         outStream << "NAME" << endl;
    00206                         outStream << "\tk - Maximum number of trajectories" << endl << endl;
    00207                         outStream <<    "SYNOPSIS" << endl;
    00208                         outStream << "\tk #" << endl << endl;
    00209                         outStream << "DESCRIPTION" << endl;
    00210                         outStream << "\tSets the maximum number of trajectories to #."
    00211                                  << endl;
    00212                         break;
    00213                 case 'q':
    00214                 case 'Q':
    00215                         outStream << "NAME" << endl;
    00216                         outStream << "\tq - quit Titan Interface test" << endl << endl;
    00217                         outStream <<    "SYNOPSIS" << endl;
    00218                         outStream << "\tq" << endl << endl;
    00219                         outStream << "DESCRIPTION" << endl;
    00220                         outStream << "\tQuits out of Titan Interface test."
    00221                                  << endl;
    00222                         break;
    00223                 case 'v':
    00224                 case 'V':
    00225                         outStream << "NAME" << endl;
    00226                         outStream << "\tv - displays the model variables and their corresponding indicies" << endl;
    00227                         outStream << "\t\t>: current assignment, +: enabled next mode" << endl << endl;
    00228                         outStream <<    "SYNOPSIS" << endl;
    00229                         outStream << "\tv [OPTION]" << endl << endl;
    00230                         outStream << "DESCRIPTION" << endl;
    00231                         outStream << "\tDisplays the model variables and the corresponding indicies" << endl;
    00232                         outStream << "\tand domain." << endl << endl;
    00233                         outStream << "\t-a\tdisplays all model variables." << endl;
    00234                         outStream << "\t-s\tdisplays only state variables." << endl;
    00235                         outStream << "\t-u\tdisplays only control variables." << endl;
    00236                         outStream << "\t-o\tdisplays only observable variables." << endl;
    00237                         outStream << "\t-t\tdisplays all compiled transitions." << endl;
    00238                         outStream << "\t-e\tdisplays all enabled compiled transitions." << endl;
    00239                         outStream << "\t-b\tdisplays the current trajectories (t)." << endl;
    00240                         break;
    00241         }
    00242 };
    00243
    00244
    00245 int
    00246 main(int argc, const char* argv[])
    00247 {
    00248         argc--;
    00249         argv++;
    00250
    00251         PropertyConfigurator::doConfigure("log4cplus.conf");
    00252
    00253         unsigned int i;
    00254
    00255         BaseModel * modelRef = NULL;
    00256         vector<const Dissent *> dissents;
    00257         vector<const CompiledTransition *> compiledTransitions;
    00258         vector<const ObsProbRule *> obsProbabilityRules;
    00259         CCANNF * ccannf( NULL );
    00260
    00261         CCAModel myCCAmodel;
    00262         ifstream beliefIn, inFile;
    00263         ofstream outFile, nullFile, timedOutFile;
    00264
    00265         bool ccannfLoaded = false;
    00266         bool modelLoaded = false;
    00267         bool compiled = false;
    00268         bool useObsProbabilities = false;
    00269         bool initLoaded = false;
    00270         bool inFileLoaded = false;
    00271         bool outFileLoaded = false;
    00272         bool timedOutputFileLoaded = false;
    00273
    00274         DMEPMTYPE * dmepm( NULL );
    00275         DMETYPE * dme( NULL );
    00276         METYPE * me = NULL;
    00277         CMETYPE * cme = NULL;
    00278         BFBSU * bse = NULL;
    00279
    00280         ModeEstimatorBase * meb = NULL;
    00281         MEPerformanceMonitor * mepm = NULL;
    00282
    00283         ProbRuleGenerator * myPRG = NULL;
    00284
    00285         cout << "Loading arguments" << endl;
    00286
    00287         for (i=0; ((int)i)<argc; i++)
    00288         {
    00289                 if(argv[i][0] == '-')
    00290                 {
    00291                         if (argv[i][1] == 'h' || argv[i][1] == 'H' || String(argv[i]).compare(String("-help")) == 0)
    00292                         {
    00293                                 printUse();
    00294                                 exit(0);
    00295                         // Every input argument below here should be in pairs of <option, file name>
    00296                         } else if(((int)i+1) >= argc)
    00297                         {
    00298                                 cout << "Expected file name following " << argv[i] << ". Ignoring option." << endl;
    00299                         } else if(argv[i+1][0] == '-')
    00300                         {
    00301                                 cout << "Expected file name following " << argv[i] << ". Ignoring option." << endl;
    00302                         } else if (argv[i][1] == 'm' || argv[i][1] == 'M')
    00303                         {
    00304                                 if(!modelLoaded)
    00305                                 {
    00306                                         cout << "Loading model '" << argv[i+1] << "'..." << endl;
    00307                                         if(MOFReader::loadMOF(argv[i+1], myCCAmodel))
    00308                                         {
    00309                                                 cerr << endl << "Could not load " << argv[i+1] << "." << endl;
    00310                                                 exit(-1);
    00311                                         }
    00312                                         cout << "Success!" << endl;
    00313                                         modelRef = (BaseModel *)(&myCCAmodel);
    00314                                         modelLoaded = true;
    00315                                 }
    00316                         } else if (argv[i][1] == 'b' || argv[i][1] == 'B')
    00317                         {       // This could actually be an initialization script
    00318                                 if(!initLoaded)
    00319                                 {
    00320                                         beliefIn.open(argv[i+1]);
    00321                                         if(!beliefIn)
    00322                                                 cout << "ERROR: Couldn't open ME initialization file. Ignoring." << endl;
    00323                                         else
    00324                                                 initLoaded = true;
    00325                                 }
    00326                         } else if (argv[i][1] == 'i' || argv[i][1] == 'I')
    00327                         {
    00328                                 if(!inFileLoaded)
    00329                                 {
    00330                                         inFile.open(argv[i+1]);
    00331                                         if(!inFile)
    00332                                                 cout << "ERROR: Couldn't open input script. Ignoring." << endl;
    00333                                         else
    00334                                                 inFileLoaded = true;
    00335                                 }
    00336                         } else if (argv[i][1] == 'o' || argv[i][1] == 'O')
    00337                         {
    00338                                 if(!outFileLoaded)
    00339                                 {
    00340                                         outFile.open(argv[i+1]);
    00341                                         if(!outFile)
    00342                                                 cout << "ERROR: Couldn't open output file. Ignoring." << endl;
    00343                                         else
    00344                                                 outFileLoaded = true;
    00345                                 }
    00346                         } else if (argv[i][1] == 't' || argv[i][1] == 'T')
    00347                         {
    00348                                 if(!timedOutputFileLoaded)
    00349                                 {
    00350                                         timedOutFile.open(argv[i+1]);
    00351                                         if(!timedOutFile)
    00352                                                 cout << "ERROR: Couldn't open matlab output file. Ignoring." << endl;
    00353                                         else
    00354                                                 timedOutputFileLoaded = true;
    00355                                 }
    00356                         } else if ( (argv[i][1] == 'c' || argv[i][1] == 'C') && ((int)i + 2) < argc ) {
    00357                                 // We have 2 arguments - BM file and CCME file
    00358                                 if(!modelLoaded)
    00359                                 {
    00360                                         // Load the BM file
    00361                                         cout << "Loading model '" << argv[i+1] << "'..." << endl;
    00362                                         if( BaseModelReader::loadBaseModel(argv[i+1], myCCAmodel) )
    00363                                         {
    00364                                                 cerr << endl << "Could not load " << argv[i+1] << "." << endl;
    00365                                                 exit(-1);
    00366                                         }
    00367                                         cout << "Success!" << endl;
    00368                                         modelRef = (BaseModel *)(&myCCAmodel);
    00369
    00370                                         // Load the CCME file
    00371                                         cout << "Loading CCME '" << argv[i+2] << "'..." << endl;
    00372                                         CCMEReader reader;
    00373                                         if( FAILED( reader.loadCCMEFile( argv[i + 2], myCCAmodel) ) ) {
    00374                                                 cerr << endl << "Could not load " << argv[i + 2] << "." << endl;
    00375                                                 exit(-1);
    00376                                         }
    00377                                         cout << "Success!" << endl;
    00378
    00379                                         // Get our dissents and transitions.
    00380                                         dissents = reader.getDissents();
    00381                                         compiledTransitions = reader.getTransitions();
    00382
    00383                                         // We loaded a compiled model now.
    00384                                         modelLoaded = true;
    00385                                         compiled = true;
    00386                                 }
    00387                         } else if ( (argv[i][1] == 'p' || argv[i][1] == 'P') && ((int)i + 2) < argc ) {
    00388                                 // We have 2 arguments - MOF file and CCME file
    00389                                 if(!modelLoaded)
    00390                                 {
    00391                                         // Load the MOF file
    00392                                         cout << "Loading model '" << argv[i+1] << "'..." << endl;
    00393                                         if(MOFReader::loadMOF(argv[i+1], myCCAmodel))
    00394                                         {
    00395                                                 cerr << endl << "Could not load " << argv[i+1] << "." << endl;
    00396                                                 exit(-1);
    00397                                         }
    00398                                         cout << "Success!" << endl;
    00399                                         modelRef = (BaseModel *)(&myCCAmodel);
    00400
    00401                                         // Load the CCME file
    00402                                         cout << "Loading CCME '" << argv[i+2] << "'..." << endl;
    00403                                         CCMEReader reader;
    00404                                         if( FAILED( reader.loadCCMEFile( argv[i + 2], myCCAmodel) ) ) {
    00405                                                 cerr << endl << "Could not load " << argv[i + 2] << "." << endl;
    00406                                                 exit(-1);
    00407                                         }
    00408                                         cout << "Success!" << endl;
    00409
    00410                                         // Get our dissents and transitions.
    00411                                         dissents = reader.getDissents();
    00412                                         compiledTransitions = reader.getTransitions();
    00413
    00414                                         // Get the probability rules
    00415                                         myPRG = new ProbRuleGenerator(&myCCAmodel, dissents, 1);
    00416                                         obsProbabilityRules = myPRG->getObservationRules();
    00417
    00418
    00419                                         // We loaded an MOF and the dissents for observation probabilities
    00420                                         modelLoaded = true;
    00421                                         useObsProbabilities = true;
    00422                                 }
    00423                         } else if (argv[i][1] == 'n' || argv[i][1] == 'N')
    00424                         {
    00425                                 cout << "Loading " << argv[i+1] << endl;
    00426                                 // Our argument is a ccannf.
    00427                                 if( !ccannfLoaded && !modelLoaded ) {
    00428                                         try {
    00429                                                 cout << "Loading Xerces" << endl;
    00430                                                 // Setup Xerces.
    00431                                                 XercesSetup scopedSetup;
    00432
    00433                                                 cout << "Loading the document." << endl;
    00434                                                 // Open the CCANNF document.
    00435                                                 XMLLoader loader;
    00436                                                 DOMDocument * document = loader.load( argv[i+1] );
    00437                                                 if( document == NULL ) {
    00438                                                         cout << "Load of " << argv[i+1] << " failed." <<
    00439                                                                 endl;
    00440                                                         return 1;
    00441                                                 }
    00442
    00443                                                 cout << "Save/Loading the CCANNF." << endl;
    00444                                                 // Load the CCANNF.
    00445                                                 XMLSaveLoad xSL( document, ISaveLoad::kLoad );
    00446                                                 xSL.saveLoad< CCANNF >( ccannf );
    00447
    00448                                                 cout << "Releasing the document." << endl;
    00449                                                 // All done.
    00450                                                 document->release();
    00451                                         } catch( std::exception &e ) {
    00452                                                 cout << "Exception: " << e.what() << endl;
    00453                                                 return 1;
    00454                                         } catch(...) {
    00455                                                 cout << "Unknown Exception" << endl;
    00456                                                 return 1;
    00457                                         }
    00458                                         ccannfLoaded = true;
    00459
    00460                                         // We also have a model
    00461                                         modelRef = ccannf->getModel();
    00462                                         modelLoaded = true;
    00463                                         cout << "Loaded " << argv[i+1] << endl;
    00464                                 }
    00465                         } else
    00466                         {
    00467                                 cerr << "Unrecognized option '" << argv[i] << "'." << endl;
    00468                                 printUse();
    00469                         }
    00470                 }
    00471         }
    00472
    00473         if(argc == 1)
    00474         {
    00475                 cout << "Loading CCA model '" << argv[0] << "'..." << endl;
    00476                 if(MOFReader::loadMOF(argv[0], myCCAmodel))
    00477                 {
    00478                         cerr << endl << "Could not load " << argv[0] << "." << endl;
    00479                         exit(-1);
    00480                 }
    00481                 cout << "Success!" << endl;
    00482                 modelRef = (BaseModel *)(&myCCAmodel);
    00483                 modelLoaded = true;
    00484         }
    00485
    00486         if(!modelLoaded)
    00487         {
    00488                 printUse();
    00489                 exit(-1);
    00490         }
    00491
    00492         cout << "Creating engine" << endl;
    00493
    00494         if( ccannfLoaded ) {
    00495                 cout << "Creating DME algorithm" << endl;
    00496                 Trajectories * traj( NULL );
    00497                 dme = new DMETYPE( ccannf, *traj );
    00498                 dmepm = new DMEPMTYPE( dme );
    00499                 meb = dme;
    00500                 mepm = dmepm;
    00501         } else if( compiled ) {
    00502                 cme = new CMETYPE( myCCAmodel, dissents, compiledTransitions);
    00503                 meb = cme;
    00504                 mepm = cme;
    00505         } else if( useObsProbabilities ) {
    00506                 bse = new BFBSU(myCCAmodel, obsProbabilityRules);
    00507                 meb = bse;
    00508                 mepm = bse;
    00509         } else {
    00510                 me = new METYPE(myCCAmodel);
    00511                 meb = me;
    00512                 mepm = me;
    00513         }
    00514
    00515         // Get ME "Warmed up"... not sure why the first couple data points are always bad
    00516         for(i=0; i<10; i++)
    00517         {
    00518                 meb->findModeEstimate();
    00519                 meb->resetCommandsAndObservations();
    00520         }
    00521
    00522
    00523         if(initLoaded)
    00524         {
    00525                 cout << "Loading initialization script... ";
    00526                 run_ME_shell(meb, mepm, *modelRef, beliefIn, nullFile, timedOutFile);
    00527                 beliefIn.close();
    00528                 cout << "done." << endl;
    00529         }
    00530         // Choose shell depending on inputs and outputs
    00531         if(inFileLoaded && outFileLoaded)
    00532         {
    00533                 run_ME_shell(meb, mepm, *modelRef, inFile, outFile, timedOutFile);
    00534                 inFile.close();
    00535                 outFile.close();
    00536         }
    00537         else if(inFileLoaded && !outFileLoaded)
    00538         {
    00539                 run_ME_shell(meb, mepm, *modelRef, inFile, cout, timedOutFile);
    00540                 inFile.close();
    00541         }
    00542         else if(!inFileLoaded && outFileLoaded)
    00543         {
    00544                 run_ME_shell(meb, mepm, *modelRef, cin, outFile, timedOutFile);
    00545                 outFile.close();
    00546         }
    00547         else
    00548                 run_ME_shell(meb, mepm, *modelRef, cin, cout, timedOutFile);
    00549
    00550         if(timedOutputFileLoaded)
    00551                 timedOutFile.close();
    00552
    00553         cout << "Cleaning up..." << endl;
    00554         if(myPRG != NULL)
    00555                 delete myPRG;
    00556
    00557         if( dme != NULL )
    00558                 delete dme;
    00559         if(me != NULL)
    00560                 delete me;
    00561         if(cme != NULL)
    00562                 delete cme;
    00563         if(bse != NULL)
    00564                 delete bse;
    00565         cout << "Done deleting ME." << endl;
    00566
    00567         return 0;
    00568 };
    00569