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

# /Users/fpy/titan-1-5-MBARI/Mers/Executives/DeductiveController/Configs/ATRV/Rover_test.cpp

    00001 //=============================================================================
    00002 //
    00003 // Copyright (c) 2001           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 (MERS) group
    00007 // does not assume any responsibility.
    00008 //
    00009 // AUTHOR:                      Seung H. Chung
    00010 // Modified by Adam Kraft to test the functionality of the RobotListener
    00011 //
    00012 // ORGANIZATION:        Model-based Embedded and Robotic Systems Group
    00013 //                                      Massachusetts Institute of Technology
    00014 //
    00015 // FILE:                        Rover_test.cpp (modification of Titan_test.cpp)
    00016 //
    00017 // DESCRIPTION:
    00018 //
    00019 //
    00020 //
    00021 //# CHECKED PHE 08/07/2002
    00022 //=============================================================================
    00023
    00024 #ifdef _MSC_VER
    00025 #pragma warning( disable : 4786 )
    00026 #include "win32/unistd.h"
    00027 #else
    00028 #include <unistd.h>
    00029 #endif
    00030
    00031 #include <stdio.h>
    00032 #include <sys/time.h>
    00033 #include <sys/types.h>
    00034 #include <cstdio>
    00035 #include <cassert>
    00036 #include <iostream>
    00037 #include <string>
    00038
    00039 #include <Mers/Utils/Containers/intList.h>
    00040 #include <Mers/Models/CCA/CCAVariable.h>
    00041 #include <Mers/Models/CCA/CCAVariables.h>
    00042 #include <Mers/Models/CCA/CCAModel.h>
    00043 #include <Mers/Models/CCA/Io/Mof/MOFReader.h>
    00044 #include <Mers/Estimation/Discrete/ModeEstimation/ModeEstimator.h>
    00045 #include <Mers/Estimation/Discrete/MEInterface.h>
    00046 #include <Mers/Testbeds/ATRV/Robot/RobotListener.h>
    00047 #include <Mers/Executives/DeductiveController/Observation/DiscreteObservationConverter.h>
    00048 #include <Mers/Reconfiguration/Discrete/modeReconfiguration.h>
    00049 #include <Mers/Reconfiguration/Discrete/mrInterface.h>
    00050 #include <Mers/Executives/DeductiveController/DCInterface.h>
    00051 #include <Mers/Executives/DeductiveController/Stub/DCCallbackStub.h>
    00052
    00053 #include "RL_list_nodes.h"
    00054
    00055 #ifdef USE_CGI
    00056 #include <Mers/Solvers/Entailment/CompiledGI/CompiledGoalInterpreter.h>
    00057 #include <Mers/Models/Base/BaseModel.h>
    00058 #else
    00059 #include <Mers/Solvers/Entailment/GI/GoalInterpreter.h>
    00060 #endif
    00061
    00062 using namespace std;
    00063 using namespace Mers::Models::CCA;                           // For CCAModel
    00064 using namespace Mers::Executives::DeductiveController;       // For DCInterface
    00065 using namespace Mers::Executives::DeductiveController::Stub; // For DCCallbackStub
    00066 using namespace Mers::Estimation::Discrete::ModeEstimation;  // For ModeEstimator
    00067 using namespace Mers::Models::CCA::Io::Mof;                  // For MOFReader
    00068 #ifdef USE_CGI
    00069 using namespace Mers::Solvers::Entailment::CompiledGI;       // For GoalInterpreter (Compiled version)
    00070 #else
    00071 using namespace Mers::Solvers::Entailment::GI;               // For GoalInterpreter
    00072 #endif
    00073 using namespace Mers::Testbeds::ATRV::Robot;                 // For Simple_Robot / RobotListener
    00074 using namespace Mers::Estimation::Discrete;                  // For MEInterface
    00075
    00076 CCAModel *      load_MOF(char const * MOF_file_name);
    00077 void    run_Titan_shell(DCInterface *Titan_interface_p, CCAModel const *model_p);
    00078 void    print_Titan_shell_help(char ch);
    00079 void    print_variables(CCAVariables const * variable_p, char ch);
    00080 void    eat_space_or_tab(istream &stream);
    00081 void    clear_stream(istream &stream);
    00082 bool    read_pair_of_int(istream &stream, int &int_1, int &int_2);
    00083
    00084 //note: add switches for Linux/Windows compiling
    00085 bool dataReady(long wait_millsec) {
    00086   long microsec = wait_millsec*1000;
    00087   fd_set rfds;
    00088   struct timeval tv;
    00089   int retval;
    00090
    00091   FD_ZERO(&rfds);
    00092   FD_SET(0, &rfds); /* incantations to get at stdin */
    00093   tv.tv_sec = 0;
    00094   tv.tv_usec = microsec;
    00095   retval = select(1, &rfds, NULL, NULL, &tv);
    00096
    00097   if (retval)
    00098     {
    00099       /* cout << retval << endl;*/
    00100       return true;
    00101     }
    00102   else
    00103     return false;
    00104 }
    00105
    00106
    00107 int
    00108 main(int argc, char** argv)
    00109 {
    00110         argc--;
    00111         argv++;
    00112
    00113         CCAModel *model_p;
    00114         char const * MOF_file_name;
    00115 #ifdef USE_CGI
    00116         // until model is a BaseModel...
    00117         // BaseModel * baseModel;
    00118         GITable * giTable;
    00119         char const * CCGIT_file_name;
    00120 #endif
    00121
    00122 #ifdef USE_CGI
    00123         if(argc != 2){
    00124                 if(argc == -1)
    00125                         printf("Use: DCCGI <CCA file> <CCGIT file>\n");
    00126                 else
    00127                         printf("Use: %s <CCA file> <CCGIT file>\n", argv[-1]);
    00128                 return 1;
    00129         }else{
    00130                 MOF_file_name = argv[0];
    00131                 CCGIT_file_name = argv[1];
    00132                 model_p = load_MOF(argv[0]);
    00133                 /*
    00134                 {
    00135                         // until model is a BaseModel...
    00136                         baseModel = new BaseModel(MOF_file_name);
    00137                         domains const * doms = model_p->get_domains_p();
    00138                         domains::const_iterator cid;
    00139                         for(cid = doms->begin(); cid != doms->end(); cid++){
    00140                                 BaseModelDomain * bmDomain =
    00141                                         new BaseModelDomain((*cid).name().c_str(), true);
    00142                                 values const * vals = (*cid).values_p();
    00143                                 values::const_iterator civ;
    00144                                 for(civ = vals->begin(); civ != vals->end(); civ++){
    00145                                         BaseModelValue * bmValue =
    00146                                                 new BaseModelValue((*civ).name().c_str());
    00147                                         bmDomain->pushBack(bmValue);
    00148                                 }
    00149                                 baseModel->addDomain(bmDomain);
    00150                         }
    00151
    00152                         variables const * vars = model_p->get_variables_p();
    00153                         variables::const_iterator civ;
    00154                         for(civ = vars->begin(); civ != vars->end(); civ++){
    00155                                 BaseModelDomain * bmDomain =
    00156                                         baseModel->getDomain((*civ).domain_p()->name().c_str());
    00157                                 BaseModelVariable::VariableType varType;
    00158                                 switch((*civ).type()){
    00159                                 case variable::CONTROL:
    00160                                         varType = BaseModelVariable::Control;
    00161                                         break;
    00162                                 case variable::DEPENDENT:
    00163                                         varType = BaseModelVariable::Dependent;
    00164                                         break;
    00165                                 case variable::OBSERVABLE:
    00166                                         varType = BaseModelVariable::Observable;
    00167                                         break;
    00168                                 case variable::STATE:
    00169                                         varType = BaseModelVariable::State;
    00170                                         break;
    00171                                 default:
    00172                                         varType = BaseModelVariable::Unknown;
    00173                                         break;
    00174                                 }
    00175                                 baseModel->addVariable((*civ).name().c_str(), varType, bmDomain);
    00176                         }
    00177                 }
    00178                 giTable = new GITable(baseModel);
    00179                 */
    00180                 giTable = new GITable(model_p);
    00181                 if(FAILED(giTable->loadGITable(CCGIT_file_name)))
    00182                 {
    00183                         printf("Error loading file: %s\n", CCGIT_file_name);
    00184                         return 1;
    00185                 }
    00186         }
    00187 #else
    00188         if (argc == 1)  // mof test file given...
    00189         {
    00190                 model_p = load_MOF(argv[0]);
    00191                 MOF_file_name = argv[0];
    00192         }else{
    00193                 if(argc == -1)
    00194                         printf("Use: Titan_test <CCA file>\n");
    00195                 else
    00196                         printf("Use: %s <CCA file>\n", argv[-1]);
    00197                 return 1;
    00198         }
    00199 #endif
    00200         cout << "Using " << MOF_file_name << " model..." << endl << endl;
    00201
    00202         ModeEstimator           mode_estimator(*model_p);
    00203
    00204 /*#
    00205         // Hack
    00206 //      mode_estimator.update_current_state(0, 4);
    00207 //      mode_estimator.update_current_state(4, 2);
    00208 //      mode_estimator.update_current_state(6, 2);
    00209 //      mode_estimator.update_current_state(10, 2);
    00210 //      mode_estimator.update_current_state(18, 4);
    00211 */
    00212
    00213 #ifdef USE_CGI
    00214         //CompiledGoalInterpreter * gi =
    00215         //      new CompiledGoalInterpreter(giTable, baseModel);
    00216         CompiledGoalInterpreter * gi =
    00217                 new CompiledGoalInterpreter(giTable, model_p);
    00218 #else
    00219         GoalInterpreter * gi = new GoalInterpreter(model_p);
    00220 #endif
    00221
    00222         modeReconfiguration mode_reconfiguration(*model_p, gi);
    00223         MEInterface *           me_interface_p = new MEInterface(&mode_estimator);
    00224         mrInterface *           mr_interface_p = new mrInterface(mode_reconfiguration);
    00225         //mr_interface_p->setDebug(true);
    00226         DCCallbackStub *        Titan_callback_p = new DCCallbackStub();
    00227         DCInterface *   Titan_interface_p =
    00228                 new DCInterface(Titan_callback_p, me_interface_p, mr_interface_p);
    00229
    00230         cout << endl << "Running demo..." << endl << endl;
    00231         run_Titan_shell(Titan_interface_p, model_p);
    00232         cout << endl << MOF_file_name << "... demo done." << endl;
    00233
    00234         sleep( (unsigned int) 1 ); // Give dispatchers time to finish all threads.
    00235         delete Titan_interface_p;
    00236
    00237         delete Titan_callback_p;
    00238
    00239         assert(model_p != NULL);
    00240         delete model_p;
    00241
    00242 #ifdef USE_CGI
    00243         //delete baseModel;
    00244 #endif
    00245
    00246         return 0;
    00247 }
    00248
    00249 CCAModel *
    00250 load_MOF(char const * MOF_file_name)
    00251 {
    00252         if (MOF_file_name == "")
    00253         {
    00254                 cerr << endl << "No MOF file specified." << endl;
    00255                 exit(-1);
    00256         }
    00257
    00258         CCAModel *model_p = new CCAModel();
    00259
    00260         if(MOFReader::loadMOF(MOF_file_name, *model_p))
    00261         {
    00262                 delete model_p;
    00263                 cerr << endl << "Could not load " << MOF_file_name << "." << endl;
    00264                 exit(-1);
    00265         }
    00266         return model_p;
    00267 }
    00268
    00269
    00270 void
    00271 run_Titan_shell(DCInterface *Titan_interface_p, CCAModel const *model_p)
    00272 {
    00273         int             var_index, val_index;
    00274         char    char_p[300];
    00275         bool    quit_shell = false;
    00276         bool    poll_rover = false;
    00277
    00278         cout << endl << "TITAN Shell: Enter 'h' for help.";
    00279         cout << endl << endl;
    00280         /*MODIFY HERE********************************************************************************/
    00281
    00282         DiscreteObservationConverter *doc = new DiscreteObservationConverter(Titan_interface_p,
    00283                                                                              (char*)("config.txt"),
    00284                                                                              model_p);
    00285         int argc = 2;
    00286         char *argp = (char*)("-robot1");
    00287         char robotName[256];
    00288         char* argv[2];
    00289         argv[0] = argp;
    00290         argv[1] = robotName;
    00291         cout << "Enter the rover name: " ;
    00292         cin >> robotName;
    00293         cerr << "making Simple_Robot" << endl;
    00294         Simple_Robot *rover = new Simple_Robot(argc,argv, (char*)("-robot1"), 1);
    00295         cerr << "making RobotListener" << endl;
    00296         RobotListener *robot = new RobotListener(doc,rover);
    00297
    00298
    00299         cout << "> " << flush;
    00300
    00301         while (!quit_shell)
    00302         {
    00303
    00304                 if(!poll_rover || (poll_rover && dataReady(500))) {
    00305                   eat_space_or_tab(cin);
    00306                   cin.get(char_p, 2);
    00307
    00308                   //'p' or 'P'  toggle rover polling
    00309                   if (char_p[0] == 'p' || char_p[0] == 'P')
    00310                     {
    00311                       if (poll_rover) poll_rover = false;
    00312                       else poll_rover = true;
    00313                     }
    00314
    00315                   // 'c' or 'C' corresponds to queue command.
    00316                   if (char_p[0] == 'c' || char_p[0] == 'C')
    00317                     {
    00318                       if (read_pair_of_int(cin, var_index, val_index) == false)
    00319                         {
    00320                           cout << "Error: 'c' must be followed by pair of integers." << endl;
    00321                         }
    00322                       else
    00323                         {
    00324                           Titan_interface_p->queue_command(var_index, val_index);
    00325                           cout << endl;
    00326                         }
    00327                     }
    00328                   // 'e' or 'E' corresponds to queue find mode estimate.
    00329                   else if (char_p[0] == 'e' || char_p[0] == 'E')
    00330                     {
    00331                       eat_space_or_tab(cin);
    00332                       if (cin.peek() == '\n')
    00333                         {
    00334                           Titan_interface_p->queue_find_mode_estimate();
    00335                           sleep( (unsigned int) 1 );
    00336                           cout << endl;
    00337                         }
    00338                       else
    00339                         {
    00340                           cin >> char_p;
    00341                           if (char_p[0] == '-' && char_p[1] == 'f')
    00342                             {
    00343                               Titan_interface_p->queue_report_full_state();
    00344                               sleep( (unsigned int) 1 );
    00345                               cout << endl;
    00346                             }
    00347                           else
    00348                             {
    00349                               Titan_interface_p->queue_find_mode_estimate();
    00350                               sleep( (unsigned int) 1 );
    00351                               cout << endl;
    00352                             }
    00353                         }
    00354                     }
    00355                   // 'g' or 'G' corresponds to queue goal.
    00356                   else if (char_p[0] == 'g' || char_p[0] == 'G')
    00357                     {
    00358                       if (read_pair_of_int(cin, var_index, val_index) == false)
    00359                         {
    00360                           cout << "Error: 'g' must be followed by pair of integers." << endl;
    00361                         }
    00362                       else
    00363                         {
    00364                           do{
    00365                             Titan_interface_p->queue_goal(var_index, val_index);
    00366                           }while(read_pair_of_int(cin, var_index, val_index));
    00367                           cout << endl;
    00368                         }
    00369                     }
    00370                   // 'h' or 'H' or '?' corresponds to display help.
    00371                   else if (char_p[0] == 'h' || char_p[0] == 'H' || char_p[0] == '?')
    00372                     {
    00373                       eat_space_or_tab(cin);
    00374                       if (cin.peek() == '\n')
    00375                         {
    00376                           print_Titan_shell_help('h');
    00377                           cout << endl;
    00378                         }
    00379                       else
    00380                         {
    00381                           cin >> char_p;
    00382                           if (char_p[0] != '\0')
    00383                             {
    00384                               print_Titan_shell_help(char_p[0]);
    00385                               cout << endl;
    00386                             }
    00387                           else
    00388                             {
    00389                               print_Titan_shell_help('h');
    00390                               cout << endl;
    00391                             }
    00392                         }
    00393                     }
    00394                   // 'o' or 'O' corresponds to queue observation.
    00395                   else if (char_p[0] == 'o' || char_p[0] == 'O')
    00396                     {
    00397                       if (read_pair_of_int(cin, var_index, val_index) == false)
    00398                         {
    00399                           cout << "Error: 'o' must be followed by pair of integers." << endl;
    00400                         }
    00401                       else
    00402                         {
    00403                           do{
    00404                             Titan_interface_p->queue_observation(var_index, val_index);
    00405                           }while(read_pair_of_int(cin, var_index, val_index));
    00406                           cout << endl;
    00407                         }
    00408                     }
    00409                   // 'q' or 'Q' corresponds to display quit.
    00410                   else if (char_p[0] == 'q' || char_p[0] == 'Q') // quit
    00411                     {
    00412                       quit_shell = true;
    00413                     }
    00414                   // 'r' or 'R' corresponds to queue observation.
    00415                   else if (char_p[0] == 'r' || char_p[0] == 'R')
    00416                     {
    00417                       Titan_interface_p->queue_request_MR();
    00418                       sleep( (unsigned int) 1 );
    00419                       cout << endl;
    00420                     }
    00421                   // 'v' or 'V' corresponds to display all variables.
    00422                   else if (char_p[0] == 'v' || char_p[0] == 'V')
    00423                     {
    00424                       eat_space_or_tab(cin);
    00425                       if (cin.peek() == '\n')
    00426                         {
    00427                           print_variables(model_p->variables_p(), 'a');
    00428                           cout << endl;
    00429                         }
    00430                       else
    00431                         {
    00432                           cin >> char_p;
    00433                           if (char_p[0] == '-' && char_p[1] != '\0')
    00434                             {
    00435                               print_variables(model_p->variables_p(), char_p[1]);
    00436                               cout << endl;
    00437                             }
    00438                           else
    00439                             {
    00440                               print_variables(model_p->variables_p(), 'a');
    00441                               cout << endl;
    00442                             }
    00443                         }
    00444                     }
    00445                   // Take an individual measurement
    00446                   else if (char_p[0]=='m' || char_p[0]=='M')
    00447                     {
    00448                       robot->update();
    00449                     }
    00450                   clear_stream(cin);
    00451                   cout << "> " << flush;
    00452                 }
    00453                 else { //not kbhit()
    00454                   robot->update();
    00455                   /*cout << "." << flush;*/
    00456                 }
    00457
    00458         }
    00459
    00460 }
    00461
    00462 void
    00463 print_Titan_shell_help(char ch)
    00464 {
    00465         if (ch == 'c')
    00466         {
    00467                 cout << "NAME" << endl;
    00468                 cout << "\tc - queues a command to Mode Estimation" << endl << endl;
    00469                 cout << "SYNOPSIS" << endl;
    00470                 cout << "\tc (VARIABLE_INDEX = VALUE_INDEX)" << endl << endl;
    00471                 cout << "DESCRIPTION" << endl;
    00472                 cout << "\tQueues the command VARIABLE_INDEX = VALUE_INDEX to Mode Estimation."
    00473                          << endl;
    00474         }
    00475         else if (ch == 'e')
    00476         {
    00477                 cout << "NAME" << endl;
    00478                 cout << "\te - queues find_mode_estimate to Mode Estimation" << endl << endl;
    00479                 cout << "SYNOPSIS" << endl;
    00480                 cout << "\te [OPTION]" << endl << endl;
    00481                 cout << "DESCRIPTION" << endl;
    00482                 cout << "\tQueues find_mode_estimate() to Mode Estimation." << endl << endl;
    00483                 cout << "\t-f\tQueues reprot_full_mode_estimate() to Mode Estimation." << endl;
    00484         }
    00485         else if (ch == 'g')
    00486         {
    00487                 cout << "NAME" << endl;
    00488                 cout << "\tg - queues goals to Mode Reconfiguration" << endl << endl;
    00489                 cout << "SYNOPSIS" << endl;
    00490                 cout << "\tg (VARIABLE_INDEX = VALUE_INDEX)" << endl << endl;
    00491                 cout << "DESCRIPTION" << endl;
    00492                 cout << "\tQueues the goal VARIABLE_INDEX = VALUE_INDEX to Mode Reconfiguration."
    00493                          << endl;
    00494         }
    00495         else if (ch == 'h')
    00496         {
    00497                 cout << "  c : queues a command to ME" << endl;
    00498                 cout << "  e : queues find_mode_estimate to ME" << endl;
    00499                 cout << "  g : queues a goal to MR" << endl;
    00500                 cout << "  h : displays this help" << endl;
    00501                 cout << "  o : queues an observation to ME" << endl;
    00502                 cout << "  p : toggle the state of rover polling (on/off)" << endl;
    00503                 cout << "  q : quit" << endl;
    00504                 cout << "  r : queues a reconfiguration request to MR" << endl;
    00505                 cout << "  v : displays variables" << endl;
    00506                 cout << endl;
    00507         }
    00508         else if (ch == 'o')
    00509         {
    00510                 cout << "NAME" << endl;
    00511                 cout << "\to - queues an observation to Mode Estimation" << endl << endl;
    00512                 cout << "SYNOPSIS" << endl;
    00513                 cout << "\to (VARIABLE_INDEX = VALUE_INDEX)" << endl << endl;
    00514                 cout << "DESCRIPTION" << endl;
    00515                 cout << "\tQueues the observation VARIABLE_INDEX = VALUE_INDEX to Mode Estimation."
    00516                          << endl;
    00517         }
    00518         else if (ch == 'p')
    00519         {
    00520                 cout << "NAME" << endl;
    00521                 cout << "\tp - toggles teh state of rover polling" << endl << endl;
    00522                 cout << "SYNOPSIS" << endl;
    00523                 cout << "\tp " << endl << endl;
    00524                 cout << "DESCRIPTION" << endl;
    00525                 cout << "\tturns rover polling on if it is off; off if it is on."
    00526                          << endl;
    00527         }
    00528         else if (ch == 'q')
    00529         {
    00530                 cout << "NAME" << endl;
    00531                 cout << "\tq - quit Titan Interface test" << endl << endl;
    00532                 cout << "SYNOPSIS" << endl;
    00533                 cout << "\tq" << endl << endl;
    00534                 cout << "DESCRIPTION" << endl;
    00535                 cout << "\tQuits out of Titan Interface test."
    00536                          << endl;
    00537         }
    00538         else if (ch == 'r')
    00539         {
    00540                 cout << "NAME" << endl;
    00541                 cout << "\tr - queues a reconfiguration request to Mode Reconfiguration" << endl << endl;
    00542                 cout << "SYNOPSIS" << endl;
    00543                 cout << "\tr" << endl << endl;
    00544                 cout << "DESCRIPTION" << endl;
    00545                 cout << "\tQueues a reconfiguration request to Mode Reconfiguration."
    00546                          << endl;
    00547         }
    00548         else if (ch == 'v')
    00549         {
    00550                 cout << "NAME" << endl;
    00551                 cout << "\tv - displays the model variables and the corresponding indicies"
    00552                          << endl << endl;
    00553                 cout << "SYNOPSIS" << endl;
    00554                 cout << "\tv [OPTION]" << endl << endl;
    00555                 cout << "DESCRIPTION" << endl;
    00556                 cout << "\tDisplays the model variables and the corresponding indicies" << endl;
    00557                 cout << "\tand domain." << endl << endl;
    00558                 cout << "\t-c\tdisplays only control variables." << endl;
    00559                 cout << "\t-d\tdisplays only dependent variables." << endl;
    00560                 cout << "\t-o\tdisplays only observable variables." << endl;
    00561                 cout << "\t-s\tdisplays only state variables." << endl;
    00562         }
    00563 }
    00564
    00565 void print_variable(CCAVariable const * var)
    00566 {
    00567         cout << var->getName() << '[' << var->getUID() << "]: {";
    00568         CCADomain const &dom = *(var->getDomain());
    00569         for(unsigned int x = 0; x < dom.getLength(); x++){
    00570                 if(x != 0)
    00571                         cout << ", ";
    00572                 cout << dom[x]->getName() << '[' << dom[x]->getUID() << ']';
    00573         }
    00574         cout << "}" << endl;
    00575 }
    00576
    00577 void
    00578 print_variables(CCAVariables const *variables_p, char ch)
    00579 {
    00580         CCAVariables::const_iterator const_it;
    00581
    00582         if (ch == 'c')
    00583         {
    00584                 for (const_it = variables_p->begin(); const_it != variables_p->end(); const_it++)
    00585                 {
    00586                         if (const_it->getVariableType() == CCAVariable::CONTROL)
    00587                         {
    00588                                 print_variable(&(*const_it));
    00589                         }
    00590                 }
    00591         }
    00592         else if (ch == 'd')
    00593         {
    00594                 for (const_it = variables_p->begin(); const_it != variables_p->end(); const_it++)
    00595                 {
    00596                         if (const_it->getVariableType() == CCAVariable::DEPENDENT)
    00597                         {
    00598                                 print_variable(&(*const_it));
    00599                         }
    00600                 }
    00601         }
    00602         else if (ch == 'o')
    00603         {
    00604                 for (const_it = variables_p->begin(); const_it != variables_p->end(); const_it++)
    00605                 {
    00606                         if (const_it->getVariableType() == CCAVariable::OBSERVABLE)
    00607                         {
    00608                                 print_variable(&(*const_it));
    00609                         }
    00610                 }
    00611         }
    00612         else if (ch == 's')
    00613         {
    00614                 for (const_it = variables_p->begin(); const_it != variables_p->end(); const_it++)
    00615                 {
    00616                         if (const_it->getVariableType() == CCAVariable::STATE)
    00617                         {
    00618                                 print_variable(&(*const_it));
    00619                         }
    00620                 }
    00621         }
    00622         else
    00623         {
    00624                 for (const_it = variables_p->begin(); const_it != variables_p->end(); const_it++)
    00625                 {
    00626                         print_variable(&(*const_it));
    00627                 }
    00628         }
    00629 }
    00630
    00631 void
    00632 eat_space_or_tab(istream &stream)
    00633 {
    00634         while(stream.peek() == ' ' || stream.peek() == '\t')
    00635         {
    00636                 stream.ignore(1);
    00637         }
    00638 }
    00639
    00640 void
    00641 clear_stream(istream &stream)
    00642 {
    00643         while(stream.peek() != '\n')
    00644         {
    00645                 stream.ignore(1);
    00646         }
    00647         stream.ignore(1);
    00648 }
    00649
    00650 bool
    00651 read_pair_of_int(istream &stream, int &int_1, int &int_2)
    00652 {
    00653         while((stream.peek() < '0' || stream.peek() > '9') && stream.peek() != '\n')
    00654         {
    00655                 stream.ignore(1);
    00656         }
    00657         if (stream.peek() == '\n')
    00658         {
    00659                 return false;
    00660         }
    00661         stream >> int_1;
    00662         while((stream.peek() < '0' || stream.peek() > '9') && stream.peek() != '\n')
    00663         {
    00664                 stream.ignore(1);
    00665         }
    00666         if (stream.peek() == '\n')
    00667         {
    00668                 return false;
    00669         }
    00670         stream >> int_2;
    00671         return true;
    00672 }
    00673
    00674