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

# /Users/fpy/titan-1-5-MBARI/Mers/Estimation/Discrete/CompiledME/CCMEReader/me_driver.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 // Author:                      Oliver B. Martin
    00010 // Organization:        Model-based Embedded and Robotic Systems Group
    00011 //                                      Massachusetts Institute of Technology
    00012 //
    00013 // Compiled Mode Estimation driver
    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 <Mers/Utils/Lang/String.h>
    00025 #include <Mers/Utils/Containers/IntegerArray.h>
    00026
    00027 #include <Mers/Models/Base/BaseModel.h>
    00028 #include <Mers/Models/Base/BaseModelDomain.h>
    00029 #include <Mers/Models/Base/BaseModelVariable.h>
    00030 #include <Mers/Models/Base/BaseModelVariableArray.h>
    00031 #include <Mers/Models/Base/BaseModelAssignment.h>
    00032 #include <Mers/Models/Base/BaseModelAssignmentArray.h>
    00033 #include <Mers/Models/Base/Io/Mof/BaseModelReader.h>
    00034
    00035 #include <Mers/Estimation/Discrete/Dissent.h>
    00036 #include <Mers/Estimation/Discrete/CompiledTransition.h>
    00037 #include <Mers/Estimation/Discrete/Estimate.h>
    00038 #include <Mers/Estimation/Discrete/Trajectories.h>
    00039 #include <Mers/Estimation/Discrete/CompiledME/CompiledModeEstimator.h>
    00040 #include <Mers/Estimation/Discrete/CompiledME/CompiledMEDebug/CBFTEDebug.h>
    00041 #include <Mers/Estimation/Discrete/ApproximateBeliefState/CompiledBFBSE/CompiledBFBSE.h>
    00042 #include <Mers/Estimation/Discrete/CompiledME/CCMEReader/CCMEReader.h>
    00043
    00044 #include <Mers/Estimation/Discrete/MEdriverUtils.h>
    00045
    00046 #include <Mers/Utils/Logging/logger.h>
    00047
    00048 #include <Mers/Estimation/Discrete/ProbabilityRules/RuleGenerator/ProbRuleGenerator.h>
    00049
    00050 using namespace Mers::Estimation::Discrete::CompiledME;
    00051 using namespace Mers::Estimation::Discrete;
    00052 using Mers::Estimation::Discrete::CompiledME::CompiledMEDebug::CBFTEDebug;
    00053 using Mers::Estimation::Discrete::ApproximateBeliefState::CompiledBFBSE::CompiledBFBSE;
    00054 using Mers::Estimation::Discrete::ProbabilityRules::RuleGenerator::ProbRuleGenerator;
    00055 using Mers::Models::Base::BaseModel;
    00056 using Mers::Models::Base::BaseModelDomain;
    00057 using Mers::Models::Base::BaseModelVariableArray;
    00058 using Mers::Models::Base::Io::Mof::BaseModelReader;
    00059 using Mers::Utils::Containers::IntegerArray;
    00060 using std::vector;
    00061 using std::ifstream;
    00062 using std::ofstream;
    00063 using std::cin;
    00064 using std::cout;
    00065 using std::cerr;
    00066 using std::endl;
    00067 using std::flush;
    00068
    00069 //OM #define CMETYPE CompiledModeEstimator
    00070 //OM #define CMETYPE BFTEDebug
    00071 #define CMETYPE CompiledBFBSE
    00072
    00073
    00074 // Function Prototypes
    00075 void    printUse(void);
    00076 void    run_CompiledME_shell(CompiledModeEstimator * cME, BaseModel &model, istream &inputStream, ostream &outStream);
    00077 void    print_CompiledME_shell_help(const char ch, ostream &outStream);
    00078
    00079 bool    create_TwoSwitches_BaseModel(BaseModel & bm);
    00080 bool    load_TwoSwitches_Model(CMETYPE *& cME, BaseModel & bm);
    00081
    00082
    00083
    00084
    00085 void
    00086 printUse(void)
    00087 {
    00088         cout << "Use:" << endl;
    00089         cout << "CompiledME_test.exe" << endl;
    00090         cout << "\t-m <BaseModel File (.bm)>" << endl;
    00091         cout << "\t-c <Compiled Transitions and Dissents File (.ccme)>" << endl;
    00092         cout << "\t[-b <Initialization Script File>]" << endl;
    00093         cout << "\t[-i <Input Script File>]" << endl;
    00094         cout << "\t[-o <Output File>]" << endl;
    00095         cout << "\t[-help]" << endl;
    00096         cout << "OR" << endl;
    00097         cout << "\t<BaseModel File> <Compiled Transitions and Dissents File> [<Initialization Script>]" << endl;
    00098         cout << endl;
    00099         return;
    00100 }
    00101
    00102
    00103 void
    00104 run_CompiledME_shell(CompiledModeEstimator * cME, BaseModel &model, istream &inputStream, ostream &outStream)
    00105 {
    00106         String          var_string, val_string;
    00107         String          inStr;
    00108         char            char_p[300];
    00109         bool            quit_shell = false;
    00110         bool            echoInput = false;
    00111         unsigned int    beliefEntryNum = 0;
    00112         bool            wasBeliefEntry = false;
    00113
    00114         outStream << endl << "COMPILED ME Shell: Enter 'h' for help.";
    00115         outStream << endl << endl;
    00116
    00117         for(unsigned int entryNumber=1; !quit_shell && !inputStream.eof(); entryNumber++)
    00118         {
    00119                 outStream << entryNumber << "> " << flush;
    00120                 eat_space_or_tab(inputStream);
    00121
    00122                 inputStream >> char_p;
    00123                 if(echoInput)
    00124                         outStream << char_p << " ";
    00125                 inStr = char_p;
    00126
    00127                 if(isNumeric(inStr) || (inStr.size() > 1 && inStr.find('/') != 0))
    00128                 {                                                       // Asserting command/observation/state
    00129                         var_string = inStr;
    00130                         eat_space_or_tab(inputStream);
    00131                         if(inputStream.peek() != '\n')
    00132                         {
    00133                                 inputStream >> char_p;
    00134                                 if(echoInput)
    00135                                         outStream << char_p << " ";
    00136                                 val_string = char_p;
    00137                                 eat_space_or_tab(inputStream);
    00138                                 assign(var_string, val_string, cME, model, outStream);
    00139                                 while(get_assignment_pairs(inputStream, outStream, var_string, val_string, echoInput))
    00140                                         assign(var_string, val_string, cME, model, outStream);
    00141                         }
    00142                         if(echoInput)
    00143                                 outStream << endl;
    00144                 }
    00145                 else if(inStr.find('/') != 0)   // Input is command since there are no 1 char variable names
    00146                 {
    00147
    00148                         switch (*inStr.c_str())
    00149                         {
    00150                                 case 'a':
    00151                                 case 'A':
    00152                                         // 'a' or 'A' corresponds to assert a sequence of (var=val)
    00153                                         eat_space_or_tab(inputStream);
    00154                                         if (inputStream.peek() != '\n')
    00155                                         {
    00156                                                 if (inputStream.peek() == '-')
    00157                                                 {
    00158                                                         inputStream >> char_p;
    00159                                                         if(echoInput)
    00160                                                                 outStream << char_p << endl;
    00161                                                         if(entryNumber - beliefEntryNum == 1 && wasBeliefEntry)         // If there has only been one loop and prev entry was a belief entry
    00162                                                         {
    00163                                                                 if(get_directed_assign(char_p[1], inputStream, outStream, cME, model, true, echoInput) && (char_p[1] == 'b' || char_p[1] == 'B'))
    00164                                                                         wasBeliefEntry = true;
    00165                                                         }
    00166                                                         else
    00167                                                         {
    00168                                                                 if(get_directed_assign(char_p[1], inputStream, outStream, cME, model, false, echoInput) && (char_p[1] == 'b' || char_p[1] == 'B'))
    00169                                                                         wasBeliefEntry = true;
    00170                                                         }
    00171                                                         if(wasBeliefEntry)              // Reset entry number on last belief input
    00172                                                                 beliefEntryNum = entryNumber;
    00173                                                 }
    00174                                                 else
    00175                                                 {
    00176                                                         while(get_assignment_pairs(inputStream, outStream, var_string, val_string, echoInput))
    00177                                                                 assign(var_string, val_string, cME, model, outStream);
    00178                                                 }
    00179                                         }
    00180                                         if(echoInput)
    00181                                                 outStream << endl;
    00182                                         break;
    00183                                 case 'e':
    00184                                 case 'E':
    00185                                         // 'e' or 'E' corresponds to estimate. '-p' progresses into the estimate
    00186                                         eat_space_or_tab(inputStream);
    00187                                         if (inputStream.peek() == '\n')
    00188                                         {
    00189                                                 if(echoInput)
    00190                                                         outStream << endl;
    00191                                                 outStream << "Calculating next trajectories..." << endl << endl;
    00192                                                 cME->findModeEstimate();
    00193                                                 outStream << endl;
    00194                                                 cME->showNextTrajectories(outStream);
    00195                                         }
    00196                                         else
    00197                                         {
    00198                                                 inputStream >> char_p;
    00199                                                 if(echoInput)
    00200                                                         outStream << char_p << endl;
    00201                                                 if (char_p[0] == '-' && char_p[1] == 'p')
    00202                                                 {
    00203                                                         outStream << "Calculating next trajectories..." << endl;
    00204                                                         cME->progressToEstimate();
    00205                                                         outStream << "Progressing into most likely estimate..." << endl << endl;
    00206                                                         cME->showCurrentTrajectories(outStream);
    00207                                                 }
    00208                                                 else
    00209                                                 {
    00210                                                         outStream << "Calculating next trajectories..." << endl;
    00211                                                         cME->findModeEstimate();
    00212                                                         outStream << endl;
    00213                                                         cME->showNextTrajectories(outStream);
    00214                                                 }
    00215                                         }
    00216                                         break;
    00217                                 case 'v':
    00218                                 case 'V':
    00219                                         // 'v' or 'V' corresponds to viewing data. Default is all variables
    00220                                         eat_space_or_tab(inputStream);
    00221                                         if (inputStream.peek() == '\n')
    00222                                         {
    00223                                                 if(echoInput)
    00224                                                         outStream << endl;
    00225                                                 print_estimator_variables('a', cME, outStream);
    00226                                         }
    00227                                         else
    00228                                         {
    00229                                                 inputStream >> char_p;
    00230                                                 if(echoInput)
    00231                                                         outStream << char_p << endl;
    00232                                                 if (char_p[0] == '-' && char_p[1] != '\0')
    00233                                                         print_estimator_variables(char_p[1], cME, outStream);
    00234                                                 else
    00235                                                         print_estimator_variables('a', cME, outStream);
    00236                                         }
    00237                                         break;
    00238                                 case 'd':
    00239                                 case 'D':
    00240                                         // 'd' or 'D' sets the debug level
    00241                                         eat_space_or_tab(inputStream);
    00242                                         if(inputStream.peek() != '\n')
    00243                                         {
    00244                                                 inputStream >> char_p;
    00245                                                 if(echoInput)
    00246                                                         outStream << char_p << endl;
    00247                                                 if(isNumeric(String(char_p)))
    00248                                                 {
    00249                                                         cME->setDebug(atoi(char_p));
    00250                                                         outStream << "Debug level set to " << char_p << endl;
    00251                                                 }
    00252                                                 else
    00253                                                         outStream << "Invalid debug level." << endl;
    00254                                         }
    00255                                         break;
    00256                                 case 'k':
    00257                                 case 'K':
    00258                                         // 'k' or 'K' sets the maximum number of trajectories
    00259                                         eat_space_or_tab(inputStream);
    00260                                         if(inputStream.peek() != '\n')
    00261                                         {
    00262                                                 inputStream >> char_p;
    00263                                                 if(echoInput)
    00264                                                         outStream << char_p << endl;
    00265                                                 if(isNumeric(String(char_p)))
    00266                                                 {
    00267                                                         outStream << "Setting maximum number of trajectories set to " << char_p << endl;
    00268                                                         cME->setNumberTrajectories(atoi(char_p));
    00269                                                 }
    00270                                                 else
    00271                                                         outStream << "Invalid maximum number of trajectories" << endl;
    00272                                         }
    00273                                         break;
    00274                                 case 'h':
    00275                                 case 'H':
    00276                                 case '?':
    00277                                         // 'h' or 'H' or '?' corresponds to display help.
    00278                                         eat_space_or_tab(inputStream);
    00279                                         if (inputStream.peek() == '\n')
    00280                                         {
    00281                                                 if(echoInput)
    00282                                                         outStream << endl;
    00283                                                 print_CompiledME_shell_help('h', outStream);
    00284                                         }
    00285                                         else
    00286                                         {
    00287                                                 inputStream >> char_p;
    00288                                                 if(echoInput)
    00289                                                         outStream << char_p << endl;
    00290                                                 if (char_p[0] == '-' && char_p[1] != '\0')
    00291                                                 {
    00292                                                         print_CompiledME_shell_help(char_p[1], outStream);
    00293                                                 }
    00294                                                 else
    00295                                                 {
    00296                                                         print_CompiledME_shell_help('h', outStream);
    00297                                                 }
    00298                                         }
    00299                                         break;
    00300                                 case 'r':
    00301                                 case 'R':
    00302                                         // 'r' or 'R' corresponds to reseting asserted variables
    00303                                         cME->resetCommandsAndObservations();
    00304                                         break;
    00305                                 case 'q':
    00306                                 case 'Q':
    00307                                         // 'q' or 'Q' corresponds to quit.
    00308                                         quit_shell = true;
    00309                                         break;
    00310                                 case '#':
    00311                                         echoInput = !echoInput;
    00312                                         outStream << "Echo input: " << (echoInput ? "ON" : "OFF") << endl << endl;
    00313                                         break;
    00314                                 case '\0':
    00315                                 case '\n':
    00316                                         // a blank line - skip.
    00317                                 case '/':
    00318                                         // assumed to be a comment
    00319                                         break;
    00320                                 default:
    00321                                         outStream << "WARNING: '" << inStr << "' is not a recognized command." << endl;
    00322                                         break;
    00323                         }
    00324                         if(*inStr.c_str() != 'a' && *inStr.c_str() != 'A') // assert functions' responsible for this
    00325                                 clear_stream(inputStream);
    00326                 }
    00327                 else
    00328                 {
    00329                         if(echoInput)
    00330                         {
    00331                                 inputStream.get(char_p, 300, '\n');
    00332                                 outStream << char_p;
    00333                         }
    00334                         clear_stream(inputStream);
    00335                 }
    00336                 if(echoInput)
    00337                         outStream << endl;
    00338         }
    00339         return;
    00340 }
    00341
    00342
    00343
    00344
    00345 void
    00346 print_CompiledME_shell_help(const char ch, ostream &outStream)
    00347 {
    00348         switch (ch)
    00349         {
    00350                 case 'a':
    00351                 case 'A':
    00352                         outStream << "NAME" << endl;
    00353                         outStream << "\ta - assert" << endl << endl;
    00354                         outStream <<    "SYNOPSIS" << endl;
    00355                         outStream << "\ta [OPTION] var val..." << endl << endl;
    00356                         outStream << "DESCRIPTION" << endl;
    00357                         outStream << "\tAssert (var = val) into ME" << endl << endl;
    00358                         outStream << "\t-s\tassert state variable assignment (trajectories truncated)" << endl;
    00359                         outStream << "\t-u\tassert command variable assignment" << endl;
    00360                         outStream << "\t-o\tassert observation variable assignment" << endl;
    00361                         outStream << "\t-b #\tassert trajectory with probability #" << endl;
    00362                         break;
    00363                 case 'e':
    00364                 case 'E':
    00365                         outStream << "NAME" << endl;
    00366                         outStream << "\te - estimate" << endl << endl;
    00367                         outStream <<    "SYNOPSIS" << endl;
    00368                         outStream << "\te [OPTION]" << endl << endl;
    00369                         outStream << "DESCRIPTION" << endl;
    00370                         outStream << "\tEstimates the next state of the system and displays the most" << endl;
    00371                         outStream << "\tlikely estimate to the screen." << endl << endl;
    00372                         outStream << "\t-e\tcalculates and displays the most likely estimate" << endl;
    00373                         outStream << "\t-p\tprogresses Titan into the most likely estimate" << endl;
    00374                         break;
    00375                 case 'r':
    00376                 case 'R':
    00377                         outStream << "NAME" << endl;
    00378                         outStream << "\tr - reset" << endl << endl;
    00379                         outStream <<    "SYNOPSIS" << endl;
    00380                         outStream << "\tr " << endl << endl;
    00381                         outStream << "DESCRIPTION" << endl;
    00382                         outStream << "\tResets all commands and observations."
    00383                                  << endl;
    00384                         break;
    00385                 case 'h':
    00386                 case 'H':
    00387                         outStream << "  var val ...            : assert (var = val) using integer UIDs or string names" << endl;
    00388                         outStream << "  a [option] var val ... : assert (var = val) for specified types and trajectories" << endl;
    00389                         outStream << "  e [option]             : estimate the next state" << endl;
    00390                         outStream << "  k #                    : sets the maximum number of trajectories" << endl;
    00391                         outStream << "  r                      : resets commands and observations" << endl;
    00392                         outStream << "  v [option]             : displays variables" << endl;
    00393                         outStream << "  h [option]             : displays this help" << endl;
    00394                         outStream << "  d #                    : sets the debug level" << endl;
    00395                         outStream << "  #                      : toggle echo input" << endl;
    00396                         outStream << "  q                      : quit" << endl;
    00397                         outStream << endl;
    00398                         break;
    00399                 case 'd':
    00400                 case 'D':
    00401                         outStream << "NAME" << endl;
    00402                         outStream << "\td - Debug level" << endl << endl;
    00403                         outStream <<    "SYNOPSIS" << endl;
    00404                         outStream << "\td #" << endl << endl;
    00405                         outStream << "DESCRIPTION" << endl;
    00406                         outStream << "\tSets the debug level to #."
    00407                                  << endl;
    00408                         break;
    00409                 case 'k':
    00410                 case 'K':
    00411                         outStream << "NAME" << endl;
    00412                         outStream << "\tk - Maximum number of trajectories" << endl << endl;
    00413                         outStream <<    "SYNOPSIS" << endl;
    00414                         outStream << "\tk #" << endl << endl;
    00415                         outStream << "DESCRIPTION" << endl;
    00416                         outStream << "\tSets the maximum number of trajectories to #."
    00417                                  << endl;
    00418                         break;
    00419                 case 'q':
    00420                 case 'Q':
    00421                         outStream << "NAME" << endl;
    00422                         outStream << "\tq - quit Titan Interface test" << endl << endl;
    00423                         outStream <<    "SYNOPSIS" << endl;
    00424                         outStream << "\tq" << endl << endl;
    00425                         outStream << "DESCRIPTION" << endl;
    00426                         outStream << "\tQuits out of Titan Interface test."
    00427                                  << endl;
    00428                         break;
    00429                 case 'v':
    00430                 case 'V':
    00431                         outStream << "NAME" << endl;
    00432                         outStream << "\tv - displays the model variables and their corresponding indicies" << endl;
    00433                         outStream << "\t\t>: current assignment, +: enabled next mode" << endl << endl;
    00434                         outStream <<    "SYNOPSIS" << endl;
    00435                         outStream << "\tv [OPTION]" << endl << endl;
    00436                         outStream << "DESCRIPTION" << endl;
    00437                         outStream << "\tDisplays the model variables and the corresponding indicies" << endl;
    00438                         outStream << "\tand domain." << endl << endl;
    00439                         outStream << "\t-a\tdisplays all model variables." << endl;
    00440                         outStream << "\t-s\tdisplays only state variables." << endl;
    00441                         outStream << "\t-u\tdisplays only control variables." << endl;
    00442                         outStream << "\t-o\tdisplays only observable variables." << endl;
    00443                         outStream << "\t-d\tdisplays all dissents." << endl;
    00444                         outStream << "\t-t\tdisplays all compiled transitions." << endl;
    00445                         outStream << "\t-e\tdisplays all enabled dissents and compiled transitions." << endl;
    00446                         outStream << "\t-c\tdisplays all conflicts." << endl;
    00447                         outStream << "\t-b\tdisplays the current trajectories (t)." << endl;
    00448                         break;
    00449         }
    00450 }
    00451
    00452
    00453 int
    00454 main(int argc, char** argv)
    00455 {
    00456         argc--;
    00457         argv++;
    00458
    00459         PropertyConfigurator::doConfigure("log4cplus.conf");
    00460
    00461         Mers::Estimation::Discrete::CompiledME::CCMEReader::CCMEReader ccmeReader;
    00462         BaseModel model;
    00463         ifstream beliefIn, inFile;
    00464         ofstream outFile, nullFile;
    00465
    00466         bool modelLoaded = false;
    00467         bool ccmeLoaded = false;
    00468         bool initLoaded = false;
    00469         bool inFileLoaded = false;
    00470         bool outFileLoaded = false;
    00471
    00472         Trajectories * initialTrajectory = NULL;
    00473         CMETYPE * cME = NULL;
    00474
    00475         for (int i=0; i<argc; i++)
    00476         {
    00477                 if(argv[i][0] == '-')
    00478                 {
    00479                         if (argv[i][1] == 'h' || argv[i][1] == 'H' || String(argv[i]).compare(String("-help")) == 0)
    00480                         {
    00481                                 printUse();
    00482                                 exit(0);
    00483                         // Every input argument below here should be in pairs of <option, file name>
    00484                         } else if(i+1 >= argc)
    00485                         {
    00486                                 cout << "Expected file name following " << argv[i] << ". Ignoring option." << endl;
    00487                         } else if(argv[i+1][0] == '-')
    00488                         {
    00489                                 cout << "Expected file name following " << argv[i] << ". Ignoring option." << endl;
    00490                         } else if (argv[i][1] == 'm' || argv[i][1] == 'M')
    00491                         {
    00492                                 if(!modelLoaded)
    00493                                 {
    00494                                         cout << "Loading model '" << argv[i+1] << "'..." << endl;
    00495                                         if(BaseModelReader::loadBaseModel(argv[i+1], model))
    00496                                                 exit(-1);       // Couldn't load base model file
    00497                                         cout << "Success!" << endl;
    00498                                         modelLoaded = true;
    00499                                 }
    00500                         } else if (argv[i][1] == 'c' || argv[i][1] == 'C')
    00501                         {
    00502                                 if(!ccmeLoaded)
    00503                                 {
    00504                                         if(!modelLoaded)
    00505                                         {
    00506                                                 cout << "ERROR: BaseModel file must be loaded before dissents and compiled transitions!" << endl;
    00507                                                 exit(-1);
    00508                                         }
    00509                                         cout << "Loading CCME '" << argv[i+1] << "'..." << endl;
    00510                                         if(ccmeReader.loadCCMEFile(argv[i+1], model))
    00511                                                 exit(-1);               // Couldn't load file
    00512                                         cout << "Success!" << endl;
    00513                                         ccmeLoaded = true;
    00514                                 }
    00515                         } else if (argv[i][1] == 'b' || argv[i][1] == 'B')
    00516                         {       // This could actually be an initialization script
    00517                                 if(!initLoaded)
    00518                                 {
    00519                                         beliefIn.open(argv[i+1]);
    00520                                         if(!beliefIn)
    00521                                                 cout << "ERROR: Couldn't open ME initialization file. Ignoring." << endl;
    00522                                         else
    00523                                                 initLoaded = true;
    00524                                 }
    00525                         } else if (argv[i][1] == 'i' || argv[i][1] == 'I')
    00526                         {
    00527                                 if(!inFileLoaded)
    00528                                 {
    00529                                         inFile.open(argv[i+1]);
    00530                                         if(!inFile)
    00531                                                 cout << "ERROR: Couldn't open input script. Ignoring." << endl;
    00532                                         else
    00533                                                 inFileLoaded = true;
    00534                                 }
    00535                         } else if (argv[i][1] == 'o' || argv[i][1] == 'O')
    00536                         {
    00537                                 if(!outFileLoaded)
    00538                                 {
    00539                                         outFile.open(argv[i+1]);
    00540                                         if(!outFile)
    00541                                                 cout << "ERROR: Couldn't open output file. Ignoring." << endl;
    00542                                         else
    00543                                                 outFileLoaded = true;
    00544                                 }
    00545                         } else
    00546                         {
    00547                                 cerr << "Unrecognized option '" << argv[i] << "'." << endl;
    00548                                 printUse();
    00549                         }
    00550                 }
    00551         }
    00552
    00553         if(argc > 1 && argc < 4)  // Input files given directly
    00554         {
    00555                 if(argv[0][0] == '-' || argv[1][0] == '-')
    00556                 {
    00557                         cout << "Invalid input sequence." << endl << endl;
    00558                         printUse();
    00559                         exit(-1);
    00560                 }
    00561                 // Load base model
    00562                 cout << "Loading model '" << argv[0] << "'..." << endl;
    00563                 if(BaseModelReader::loadBaseModel(argv[0], model))
    00564                         exit(-1);               // Couldn't load the base model
    00565                 cout << "Success!" << endl;
    00566                 modelLoaded = true;
    00567                 // Load compiled transitions and dissents
    00568                 cout << "Loading CCME '" << argv[1] << "'..." << endl;
    00569                 if(ccmeReader.loadCCMEFile(argv[1], model))
    00570                         exit(-1);
    00571                 cout << "Success!" << endl;
    00572                 ccmeLoaded = true;
    00573                 if(argc == 3) // Initialization script
    00574                 {
    00575                         if(argv[2][0] == '-')
    00576                         {
    00577                                 cout << "Invalid initialization script paramter." << endl << endl;
    00578                                 printUse();
    00579                                 exit(-1);
    00580                         }
    00581                         beliefIn.open(argv[2]);
    00582                         if(!beliefIn)
    00583                                 cout << "ERROR: Couldn't open ME initialization file. Ignoring." << endl;
    00584                         else
    00585                                 initLoaded = true;
    00586                 }
    00587         }
    00588
    00589         if(argc == 0)
    00590         {
    00591                 create_TwoSwitches_BaseModel(model);
    00592                 cout << "Attempting to create default twoSwitches model..." << endl;
    00593                 if(!load_TwoSwitches_Model(cME, model))
    00594                 {
    00595                         cerr << "ERROR: Couldn't load default twoSwitches model!" << endl;
    00596                         exit(-1);
    00597                 }
    00598         }
    00599         else if(!modelLoaded || !ccmeLoaded)
    00600         {
    00601                 printUse();
    00602                 exit(-1);
    00603         }
    00604
    00605
    00606         if(!cME)
    00607         {
    00608                 ProbRuleGenerator * myPRG = new ProbRuleGenerator(&model, ccmeReader.getDissents(), 1);
    00609                 myPRG->getObservationRules();
    00610                 delete myPRG;
    00611
    00612                 cME = new CMETYPE(model, ccmeReader.getDissents(),
    00613                                         ccmeReader.getTransitions(), initialTrajectory);
    00614         }
    00615
    00616         if(initLoaded)
    00617         {
    00618                 cout << "Loading initialization script... ";
    00619                 run_CompiledME_shell(cME, model, beliefIn, nullFile);
    00620                 beliefIn.close();
    00621                 cout << "done." << endl;
    00622         }
    00623         // Choose shell depending on inputs and outputs
    00624         if(inFileLoaded && outFileLoaded)
    00625         {
    00626                 run_CompiledME_shell(cME, model, inFile, outFile);
    00627                 inFile.close();
    00628                 outFile.close();
    00629         }
    00630         else if(inFileLoaded && !outFileLoaded)
    00631         {
    00632                 run_CompiledME_shell(cME, model, inFile, cout);
    00633                 inFile.close();
    00634         }
    00635         else if(!inFileLoaded && outFileLoaded)
    00636         {
    00637                 run_CompiledME_shell(cME, model, cin, outFile);
    00638                 outFile.close();
    00639         }
    00640         else
    00641                 run_CompiledME_shell(cME, model, cin, cout);
    00642
    00643
    00644         delete cME;
    00645         return 0;
    00646 }
    00647
    00648
    00649 bool
    00650 create_TwoSwitches_BaseModel(BaseModel & bm)
    00651 {
    00652         bm.setName("twoSwitches.bm");
    00653
    00654         BaseModelVariable * var;
    00655         BaseModelDomain * varDomain;
    00656         BaseModelValue * val;
    00657
    00658         // SWITCH2.MODE
    00659         var = new BaseModelVariable(BaseModelVariable::STATE);
    00660         var->setUID(0);
    00661         var->setName("SWITCH2.MODE");
    00662         varDomain = new BaseModelDomain(true);
    00663         varDomain->setName("switch-values");
    00664         val = new BaseModelValue("BROKEN");
    00665         varDomain->pushBack(val);
    00666         val = new BaseModelValue("ON");
    00667         varDomain->pushBack(val);
    00668         val = new BaseModelValue("OFF");
    00669         varDomain->pushBack(val);
    00670         var->setDomain(varDomain);
    00671         bm.addVariable(var);
    00672
    00673         // SWITCH2.OUTPUT
    00674         var = new BaseModelVariable(BaseModelVariable::OBSERVABLE);
    00675         var->setUID(1);
    00676         var->setName("SWITCH2.OUTPUT");
    00677         varDomain = new BaseModelDomain(true);
    00678         varDomain->setName("output-values");
    00679         val = new BaseModelValue("HIGH");
    00680         varDomain->pushBack(val);
    00681         val = new BaseModelValue("LOW");
    00682         varDomain->pushBack(val);
    00683         var->setDomain(varDomain);
    00684         bm.addVariable(var);
    00685
    00686         // SWITCH2.COMMAND_IN
    00687         var = new BaseModelVariable(BaseModelVariable::CONTROL);
    00688         var->setUID(2);
    00689         var->setName("SWITCH2.COMMAND_IN");
    00690         varDomain = new BaseModelDomain(true);
    00691         varDomain->setName("command-values");
    00692         val = new BaseModelValue("TURN_ON");
    00693         varDomain->pushBack(val);
    00694         val = new BaseModelValue("TURN_OFF");
    00695         varDomain->pushBack(val);
    00696         val = new BaseModelValue("NO-COMMAND");
    00697         varDomain->pushBack(val);
    00698         var->setDomain(varDomain);
    00699         bm.addVariable(var);
    00700
    00701
    00702         // SWITCH1.MODE
    00703         var = new BaseModelVariable(BaseModelVariable::STATE);
    00704         var->setUID(3);
    00705         var->setName("SWITCH1.MODE");
    00706         varDomain = new BaseModelDomain(true);
    00707         varDomain->setName("switch-values");
    00708         val = new BaseModelValue("BROKEN");
    00709         varDomain->pushBack(val);
    00710         val = new BaseModelValue("ON");
    00711         varDomain->pushBack(val);
    00712         val = new BaseModelValue("OFF");
    00713         varDomain->pushBack(val);
    00714         var->setDomain(varDomain);
    00715         bm.addVariable(var);
    00716
    00717         // SWITCH1.OUTPUT
    00718         var = new BaseModelVariable(BaseModelVariable::OBSERVABLE);
    00719         var->setUID(4);
    00720         var->setName("SWITCH1.OUTPUT");
    00721         varDomain = new BaseModelDomain(true);
    00722         varDomain->setName("output-values");
    00723         val = new BaseModelValue("HIGH");
    00724         varDomain->pushBack(val);
    00725         val = new BaseModelValue("LOW");
    00726         varDomain->pushBack(val);
    00727         var->setDomain(varDomain);
    00728         bm.addVariable(var);
    00729
    00730
    00731         // SWITCH1.COMMAND_IN
    00732         var = new BaseModelVariable(BaseModelVariable::CONTROL);
    00733         var->setUID(5);
    00734         var->setName("SWITCH1.COMMAND_IN");
    00735         varDomain = new BaseModelDomain(true);
    00736         varDomain->setName("command-values");
    00737         val = new BaseModelValue("TURN_ON");
    00738         varDomain->pushBack(val);
    00739         val = new BaseModelValue("TURN_OFF");
    00740         varDomain->pushBack(val);
    00741         val = new BaseModelValue("NO-COMMAND");
    00742         varDomain->pushBack(val);
    00743         var->setDomain(varDomain);
    00744         bm.addVariable(var);
    00745
    00746         return true;
    00747 }
    00748
    00749
    00750 bool
    00751 load_TwoSwitches_Model(CMETYPE *& cME, BaseModel & bm)
    00752 {
    00753         bool successFlag = true;
    00754
    00755         BaseModelVariableArray * decisionVars = new BaseModelVariableArray(true);
    00756         IntegerArray * probabilityMap = new IntegerArray();
    00757         unsigned int nextVarPos = 0;
    00758         // Determine the number of mode variables in model
    00759         BaseModelVariableArray * allBMVars = bm.getVariables();
    00760         for(unsigned int i=0; i<bm.getVariables()->getLength(); i++)
    00761         {
    00762                 if((*allBMVars)[i]->getVariableType() == BaseModelVariable::STATE)
    00763                 {
    00764                         decisionVars->pushBack((*allBMVars)[i]);
    00765                         probabilityMap->pushBack(nextVarPos);
    00766                         nextVarPos += (*allBMVars)[i]->getDomain()->getLength();
    00767                 }
    00768         }
    00769 //      cout << "Decision vars: " << endl << *decisionVars << endl;
    00770
    00771         const BaseModelVariable * switch1Mode = bm.getVariable("SWITCH1.MODE");
    00772     const BaseModelVariable * switch2Mode = bm.getVariable("SWITCH2.MODE");
    00773         const BaseModelVariable * switch1Output = bm.getVariable("SWITCH1.OUTPUT");
    00774         const BaseModelVariable * switch2Output = bm.getVariable("SWITCH2.OUTPUT");
    00775         const BaseModelVariable * switch1Command = bm.getVariable("SWITCH1.COMMAND_IN");
    00776         const BaseModelVariable * switch2Command = bm.getVariable("SWITCH2.COMMAND_IN");
    00777
    00778         // Set up dissents
    00779 //      cout << "Dissents: " << endl;
    00780         BaseModelAssignment * assign;
    00781         vector<const Dissent *> dissents;
    00782         BaseModelAssignmentArray * imps = new BaseModelAssignmentArray(true);
    00783         BaseModelAssignmentArray * cons = new BaseModelAssignmentArray(true);
    00784 /*      Dissents
    00785 {3 "SWITCH1.MODE" = 1 "ON", 4 "SWITCH1.OUTPUT" = 1 "LOW"}
    00786 {3 "SWITCH1.MODE" = 2 "OFF", 4 "SWITCH1.OUTPUT" = 0 "HIGH"}
    00787 {0 "SWITCH2.MODE" = 1 "ON", 1 "SWITCH2.OUTPUT" = 1 "LOW"}
    00788 {0 "SWITCH2.MODE" = 2 "OFF", 1 "SWITCH2.OUTPUT" = 0 "HIGH"}
    00789 */
    00790
    00791 // Dissent 1
    00792         assign = new BaseModelAssignment(switch1Mode, switch1Mode->getDomain()->find("ON"));
    00793         cons->pushBack(assign);
    00794         assign = new BaseModelAssignment(switch1Output, switch1Output->getDomain()->find("LOW"));
    00795         imps->pushBack(assign);
    00796
    00797         const Dissent * aDissent = new Dissent(imps, cons);
    00798         dissents.push_back(aDissent);
    00799 //      cout << *aDissent << endl;
    00800
    00801 // Dissent 2
    00802         cons = new BaseModelAssignmentArray(true);
    00803         imps = new BaseModelAssignmentArray(true);
    00804
    00805         assign = new BaseModelAssignment(switch1Mode, switch1Mode->getDomain()->find("OFF"));
    00806         cons->pushBack(assign);
    00807         assign = new BaseModelAssignment(switch1Output, switch1Output->getDomain()->find("HIGH"));
    00808         imps->pushBack(assign);
    00809
    00810         aDissent = new Dissent(imps, cons);
    00811         dissents.push_back(aDissent);
    00812 //      cout << *aDissent << endl;
    00813
    00814 // Dissent 3
    00815         cons = new BaseModelAssignmentArray(true);
    00816         imps = new BaseModelAssignmentArray(true);
    00817
    00818         assign = new BaseModelAssignment(switch2Mode, switch2Mode->getDomain()->find("ON"));
    00819         cons->pushBack(assign);
    00820         assign = new BaseModelAssignment(switch2Output, switch2Output->getDomain()->find("LOW"));
    00821         imps->pushBack(assign);
    00822
    00823         aDissent = new Dissent(imps, cons);
    00824         dissents.push_back(aDissent);
    00825 //      cout << *aDissent << endl;
    00826
    00827 // Dissent 4
    00828         cons = new BaseModelAssignmentArray(true);
    00829         imps = new BaseModelAssignmentArray(true);
    00830
    00831         assign = new BaseModelAssignment(switch2Mode, switch2Mode->getDomain()->find("OFF"));
    00832         cons->pushBack(assign);
    00833         assign = new BaseModelAssignment(switch2Output, switch2Output->getDomain()->find("HIGH"));
    00834         imps->pushBack(assign);
    00835
    00836         aDissent = new Dissent(imps, cons);
    00837         dissents.push_back(aDissent);
    00838
    00839 //      cout << *aDissent << endl;
    00840
    00841
    00842         // Set up compiled transitions
    00843 //      cout << endl << "Compiled Transitions: " << endl;
    00844         BaseModelAssignment * src;
    00845         BaseModelAssignment * targ;
    00846         double prob;
    00847         BaseModelAssignmentArray * guards = new BaseModelAssignmentArray(true);
    00848         vector<const CompiledTransition *> compTrans;
    00849 /*
    00850 Transitions
    00851 0 "SWITCH2.MODE" : 0 "BROKEN" -> 0 "BROKEN": Probability {0.010000}: True
    00852 0 "SWITCH2.MODE" : 1 "ON" -> 0 "BROKEN": Probability {0.010000}: True
    00853 0 "SWITCH2.MODE" : 2 "OFF" -> 0 "BROKEN": Probability {0.010000}: True
    00854 0 "SWITCH2.MODE" : 2 "OFF" -> 2 "OFF": Probability {1.000000}: {2 "SWITCH2.COMMAND_IN" = 1 "TURN_OFF"}
    00855 0 "SWITCH2.MODE" : 2 "OFF" -> 2 "OFF": Probability {1.000000}: {2 "SWITCH2.COMMAND_IN" = 2 "NO-COMMAND"}
    00856 0 "SWITCH2.MODE" : 1 "ON" -> 1 "ON": Probability {1.000000}: {2 "SWITCH2.COMMAND_IN" = 0 "TURN_ON"}
    00857 0 "SWITCH2.MODE" : 1 "ON" -> 1 "ON": Probability {1.000000}: {2 "SWITCH2.COMMAND_IN" = 2 "NO-COMMAND"}
    00858 0 "SWITCH2.MODE" : 2 "OFF" -> 1 "ON": Probability {1.000000}: {2 "SWITCH2.COMMAND_IN" = 0 "TURN_ON"}
    00859 0 "SWITCH2.MODE" : 1 "ON" -> 2 "OFF": Probability {1.000000}: {2 "SWITCH2.COMMAND_IN" = 1 "TURN_OFF"}
    00860 3 "SWITCH1.MODE" : 0 "BROKEN" -> 0 "BROKEN": Probability {0.010000}: True
    00861 3 "SWITCH1.MODE" : 1 "ON" -> 0 "BROKEN": Probability {0.010000}: True
    00862 3 "SWITCH1.MODE" : 2 "OFF" -> 0 "BROKEN": Probability {0.010000}: True
    00863 3 "SWITCH1.MODE" : 2 "OFF" -> 2 "OFF": Probability {1.000000}: {5 "SWITCH1.COMMAND_IN" = 1 "TURN_OFF"}
    00864 3 "SWITCH1.MODE" : 2 "OFF" -> 2 "OFF": Probability {1.000000}: {5 "SWITCH1.COMMAND_IN" = 2 "NO-COMMAND"}
    00865 3 "SWITCH1.MODE" : 1 "ON" -> 1 "ON": Probability {1.000000}: {5 "SWITCH1.COMMAND_IN" = 0 "TURN_ON"}
    00866 3 "SWITCH1.MODE" : 1 "ON" -> 1 "ON": Probability {1.000000}: {5 "SWITCH1.COMMAND_IN" = 2 "NO-COMMAND"}
    00867 3 "SWITCH1.MODE" : 2 "OFF" -> 1 "ON": Probability {1.000000}: {5 "SWITCH1.COMMAND_IN" = 0 "TURN_ON"}
    00868 3 "SWITCH1.MODE" : 1 "ON" -> 2 "OFF": Probability {1.000000}: {5 "SWITCH1.COMMAND_IN" = 1 "TURN_OFF"}
    00869 */
    00870
    00871         // Switch2 broken transitions
    00872         src = new BaseModelAssignment(switch2Mode, switch2Mode->getDomain()->find("BROKEN"));
    00873         targ = new BaseModelAssignment(switch2Mode, switch2Mode->getDomain()->find("BROKEN"));
    00874         prob = 1.0;
    00875         const CompiledTransition * aCompTrans = new CompiledTransition(src, guards, targ, prob);
    00876         compTrans.push_back(aCompTrans);
    00877 //      cout << *aCompTrans <<  endl;
    00878
    00879         src = new BaseModelAssignment(switch2Mode, switch2Mode->getDomain()->find("ON"));
    00880         targ = new BaseModelAssignment(switch2Mode, switch2Mode->getDomain()->find("BROKEN"));
    00881         guards = new BaseModelAssignmentArray(true);
    00882         prob = 0.1;
    00883         aCompTrans = new CompiledTransition(src, guards, targ, prob);
    00884 //      cout << *aCompTrans <<  endl;
    00885         compTrans.push_back(aCompTrans);
    00886
    00887         src = new BaseModelAssignment(switch2Mode, switch2Mode->getDomain()->find("OFF"));
    00888         targ = new BaseModelAssignment(switch2Mode, switch2Mode->getDomain()->find("BROKEN"));
    00889         guards = new BaseModelAssignmentArray(true);
    00890         prob = 0.1;
    00891         aCompTrans = new CompiledTransition(src, guards, targ, prob);
    00892 //      cout << *aCompTrans <<  endl;
    00893         compTrans.push_back(aCompTrans);
    00894
    00895
    00896         // Switch2 to Offs
    00897         src = new BaseModelAssignment(switch2Mode, switch2Mode->getDomain()->find("OFF"));
    00898         targ = new BaseModelAssignment(switch2Mode, switch2Mode->getDomain()->find("OFF"));
    00899         prob = 0.9;
    00900         guards = new BaseModelAssignmentArray(true);
    00901         guards->pushBack(new BaseModelAssignment(switch2Command, switch2Command->getDomain()->find("TURN_OFF")));
    00902         aCompTrans = new CompiledTransition(src, guards, targ, prob);
    00903         compTrans.push_back(aCompTrans);
    00904 //      cout << *aCompTrans <<  endl;
    00905
    00906         src = new BaseModelAssignment(switch2Mode, switch2Mode->getDomain()->find("OFF"));
    00907         targ = new BaseModelAssignment(switch2Mode, switch2Mode->getDomain()->find("OFF"));
    00908         guards = new BaseModelAssignmentArray(true);
    00909         guards->pushBack(new BaseModelAssignment(switch2Command, switch2Command->getDomain()->find("NO-COMMAND")));
    00910         prob = 0.9;
    00911         aCompTrans = new CompiledTransition(src, guards, targ, prob);
    00912 //      cout << *aCompTrans <<  endl;
    00913         compTrans.push_back(aCompTrans);
    00914
    00915         src = new BaseModelAssignment(switch2Mode, switch2Mode->getDomain()->find("ON"));
    00916         targ = new BaseModelAssignment(switch2Mode, switch2Mode->getDomain()->find("OFF"));
    00917         guards = new BaseModelAssignmentArray(true);
    00918         guards->pushBack(new BaseModelAssignment(switch2Command, switch2Command->getDomain()->find("TURN_OFF")));
    00919         prob = 0.9;
    00920         aCompTrans = new CompiledTransition(src, guards, targ, prob);
    00921 //      cout << *aCompTrans <<  endl;
    00922         compTrans.push_back(aCompTrans);
    00923
    00924
    00925         // Switch2 to Ons
    00926         src = new BaseModelAssignment(switch2Mode, switch2Mode->getDomain()->find("ON"));
    00927         targ = new BaseModelAssignment(switch2Mode, switch2Mode->getDomain()->find("ON"));
    00928         prob = 0.9;
    00929         guards = new BaseModelAssignmentArray(true);
    00930         guards->pushBack(new BaseModelAssignment(switch2Command, switch2Command->getDomain()->find("TURN_ON")));
    00931         aCompTrans = new CompiledTransition(src, guards, targ, prob);
    00932         compTrans.push_back(aCompTrans);
    00933 //      cout << *aCompTrans <<  endl;
    00934
    00935         src = new BaseModelAssignment(switch2Mode, switch2Mode->getDomain()->find("ON"));
    00936         targ = new BaseModelAssignment(switch2Mode, switch2Mode->getDomain()->find("ON"));
    00937         guards = new BaseModelAssignmentArray(true);
    00938         guards->pushBack(new BaseModelAssignment(switch2Command, switch2Command->getDomain()->find("NO-COMMAND")));
    00939         prob = 0.9;
    00940         aCompTrans = new CompiledTransition(src, guards, targ, prob);
    00941 //      cout << *aCompTrans <<  endl;
    00942         compTrans.push_back(aCompTrans);
    00943
    00944         src = new BaseModelAssignment(switch2Mode, switch2Mode->getDomain()->find("OFF"));
    00945         targ = new BaseModelAssignment(switch2Mode, switch2Mode->getDomain()->find("ON"));
    00946         guards = new BaseModelAssignmentArray(true);
    00947         guards->pushBack(new BaseModelAssignment(switch2Command, switch2Command->getDomain()->find("TURN_ON")));
    00948         prob = 0.9;
    00949         aCompTrans = new CompiledTransition(src, guards, targ, prob);
    00950 //      cout << *aCompTrans <<  endl;
    00951         compTrans.push_back(aCompTrans);
    00952
    00953
    00954         // Switch1 to Offs
    00955         src = new BaseModelAssignment(switch1Mode, switch1Mode->getDomain()->find("OFF"));
    00956         targ = new BaseModelAssignment(switch1Mode, switch1Mode->getDomain()->find("OFF"));
    00957         prob = 0.9;
    00958         guards = new BaseModelAssignmentArray(true);
    00959         guards->pushBack(new BaseModelAssignment(switch1Command, switch1Command->getDomain()->find("TURN_OFF")));
    00960         aCompTrans = new CompiledTransition(src, guards, targ, prob);
    00961         compTrans.push_back(aCompTrans);
    00962 //      cout << *aCompTrans <<  endl;
    00963
    00964         src = new BaseModelAssignment(switch1Mode, switch1Mode->getDomain()->find("OFF"));
    00965         targ = new BaseModelAssignment(switch1Mode, switch1Mode->getDomain()->find("OFF"));
    00966         guards = new BaseModelAssignmentArray(true);
    00967         guards->pushBack(new BaseModelAssignment(switch1Command, switch1Command->getDomain()->find("NO-COMMAND")));
    00968         prob = 0.9;
    00969         aCompTrans = new CompiledTransition(src, guards, targ, prob);
    00970 //      cout << *aCompTrans <<  endl;
    00971         compTrans.push_back(aCompTrans);
    00972
    00973         src = new BaseModelAssignment(switch1Mode, switch1Mode->getDomain()->find("ON"));
    00974         targ = new BaseModelAssignment(switch1Mode, switch1Mode->getDomain()->find("OFF"));
    00975         guards = new BaseModelAssignmentArray(true);
    00976         guards->pushBack(new BaseModelAssignment(switch1Command, switch1Command->getDomain()->find("TURN_OFF")));
    00977         prob = 0.9;
    00978         aCompTrans = new CompiledTransition(src, guards, targ, prob);
    00979 //      cout << *aCompTrans <<  endl;
    00980         compTrans.push_back(aCompTrans);
    00981
    00982
    00983         // Switch1 to Ons
    00984         src = new BaseModelAssignment(switch1Mode, switch1Mode->getDomain()->find("ON"));
    00985         targ = new BaseModelAssignment(switch1Mode, switch1Mode->getDomain()->find("ON"));
    00986         prob = 0.9;
    00987         guards = new BaseModelAssignmentArray(true);
    00988         guards->pushBack(new BaseModelAssignment(switch1Command, switch1Command->getDomain()->find("TURN_ON")));
    00989         aCompTrans = new CompiledTransition(src, guards, targ, prob);
    00990         compTrans.push_back(aCompTrans);
    00991 //      cout << *aCompTrans <<  endl;
    00992
    00993         src = new BaseModelAssignment(switch1Mode, switch1Mode->getDomain()->find("ON"));
    00994         targ = new BaseModelAssignment(switch1Mode, switch1Mode->getDomain()->find("ON"));
    00995         guards = new BaseModelAssignmentArray(true);
    00996         guards->pushBack(new BaseModelAssignment(switch1Command, switch1Command->getDomain()->find("NO-COMMAND")));
    00997         prob = 0.9;
    00998         aCompTrans = new CompiledTransition(src, guards, targ, prob);
    00999 //      cout << *aCompTrans <<  endl;
    01000         compTrans.push_back(aCompTrans);
    01001
    01002         src = new BaseModelAssignment(switch1Mode, switch1Mode->getDomain()->find("OFF"));
    01003         targ = new BaseModelAssignment(switch1Mode, switch1Mode->getDomain()->find("ON"));
    01004         guards = new BaseModelAssignmentArray(true);
    01005         guards->pushBack(new BaseModelAssignment(switch1Command, switch1Command->getDomain()->find("TURN_ON")));
    01006         prob = 0.9;
    01007         aCompTrans = new CompiledTransition(src, guards, targ, prob);
    01008 //      cout << *aCompTrans <<  endl;
    01009         compTrans.push_back(aCompTrans);
    01010
    01011
    01012
    01013         // Switch1 Broken transitions
    01014         src = new BaseModelAssignment(switch1Mode, switch1Mode->getDomain()->find("BROKEN"));
    01015         targ = new BaseModelAssignment(switch1Mode, switch1Mode->getDomain()->find("BROKEN"));
    01016         guards = new BaseModelAssignmentArray(true);
    01017         prob = 1.0;
    01018         aCompTrans = new CompiledTransition(src, guards, targ, prob);
    01019         compTrans.push_back(aCompTrans);
    01020 //      cout << *aCompTrans <<  endl;
    01021
    01022         src = new BaseModelAssignment(switch1Mode, switch1Mode->getDomain()->find("ON"));
    01023         targ = new BaseModelAssignment(switch1Mode, switch1Mode->getDomain()->find("BROKEN"));
    01024         guards = new BaseModelAssignmentArray(true);
    01025         prob = 0.1;
    01026         aCompTrans = new CompiledTransition(src, guards, targ, prob);
    01027 //      cout << *aCompTrans <<  endl;
    01028         compTrans.push_back(aCompTrans);
    01029
    01030         src = new BaseModelAssignment(switch1Mode, switch1Mode->getDomain()->find("OFF"));
    01031         targ = new BaseModelAssignment(switch1Mode, switch1Mode->getDomain()->find("BROKEN"));
    01032         guards = new BaseModelAssignmentArray(true);
    01033         prob = 0.1;
    01034         aCompTrans = new CompiledTransition(src, guards, targ, prob);
    01035 //      cout << *aCompTrans <<  endl;
    01036         compTrans.push_back(aCompTrans);
    01037
    01038
    01039         // Create initial trajectories
    01040 //      cout << endl << "Estimates: " << endl;
    01041         Trajectories * trajsPtr = new Trajectories(1.0);
    01042         BaseModelAssignmentArray * modeAssigns = new BaseModelAssignmentArray(true);
    01043         modeAssigns->pushBack(new BaseModelAssignment(switch1Mode, switch1Mode->getDomain()->find("OFF")));
    01044         modeAssigns->pushBack(new BaseModelAssignment(switch2Mode, switch2Mode->getDomain()->find("ON")));
    01045         Estimate * est = new Estimate(modeAssigns, 0.75);
    01046         if(!trajsPtr->addEstimate(est))
    01047                 successFlag = false;
    01048
    01049         modeAssigns = new BaseModelAssignmentArray(true);
    01050         modeAssigns->pushBack(new BaseModelAssignment(switch1Mode, switch1Mode->getDomain()->find("BROKEN")));
    01051         modeAssigns->pushBack(new BaseModelAssignment(switch2Mode, switch2Mode->getDomain()->find("BROKEN")));
    01052         est = new Estimate(modeAssigns, 0.15);
    01053         if(!trajsPtr->addEstimate(est))
    01054                 successFlag = false;
    01055
    01056         ProbRuleGenerator * myPRG = new ProbRuleGenerator(&bm, dissents, 1);
    01057         myPRG->getObservationRules();
    01058         delete myPRG;
    01059
    01060         cME = new CMETYPE(bm, dissents, compTrans, trajsPtr);
    01061         return successFlag;
    01062 }