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

# /Users/fpy/titan-1-5-MBARI/Mers/Models/Base/unit-tests/BMHelper.h

    00001
    00002 //
    00003 // Copyright (c) 2004           Model-based Embedded and Robotic Systems Group
    00004 // All Rights Reserved          Massachusetts Institute of Technology
    00005 //
    00006 // This software is provided as is. Model-based Embedded and Robotic Systems
    00007 // (MERS) group does not assume any responsibility.
    00008 //
    00009 // Organization:        Model-based Embedded and Robotic Systems Group
    00010 //                                      Massachusetts Institute of Technology
    00011 //
    00013
    00014 #ifndef BM_HELPER_HEADER_FILE
    00015 #define BM_HELPER_HEADER_FILE
    00016
    00017 #include <tut.h>
    00018 #include <Mers/Models/Base/BaseModelDomainArray.h>
    00019 #include <Mers/Models/Base/BaseModelVariable.h>
    00020 #include <Mers/Models/Base/BaseModelVariableArray.h>
    00021 #include <Mers/Models/Base/BaseModelSentence.h>
    00022 #include <Mers/Models/Base/BaseModelAssignmentArray.h>
    00023 #include <vector>
    00024
    00025 namespace Mers {
    00026 namespace Models {
    00027 namespace Base {
    00028         class BaseModel;
    00029 }
    00030 }
    00031 }
    00032
    00033 namespace tut {
    00034
    00040         class BMHelper
    00041         {
    00042         public:
    00046                 BMHelper();
    00047
    00051                 virtual ~BMHelper();
    00052
    00053         protected:
    00057                 struct BMDomainEntry {
    00059                         char const * name;
    00061                         char const ** values;
    00062                 };
    00063
    00067                 struct BMVariableEntry {
    00069                         char const * name;
    00071                         unsigned int domainIndex;
    00073                         Mers::Models::Base::BaseModelVariable::VariableType varType;
    00074                 };
    00075
    00081                 static Mers::Models::Base::BaseModelDomain *
    00082                         loadDomain(const struct BMDomainEntry * domainData, unsigned int index);
    00083
    00094                 static Mers::Models::Base::BaseModelVariable * loadVariable(
    00095                         Mers::Models::Base::BaseModelDomainArray &domains,
    00096                         const struct BMVariableEntry * variableData, unsigned int index);
    00097
    00107                 static void loadDomainData(unsigned int numDomains,
    00108                         const struct BMDomainEntry * domainData,
    00109                         Mers::Models::Base::BaseModelDomainArray &doms);
    00110
    00124                 static void loadVariableData(unsigned int numVariables,
    00125                         const struct BMVariableEntry * variables,
    00126                         Mers::Models::Base::BaseModelDomainArray &doms,
    00127                         Mers::Models::Base::BaseModelVariableArray &vars);
    00128
    00143                 static void loadModelData( unsigned int numDomains,
    00144                         const struct BMDomainEntry * domainData,
    00145                         unsigned int numVariables,
    00146                         const struct BMVariableEntry * variableData,
    00147                         Mers::Models::Base::BaseModel &model );
    00148
    00167                 static void getVariableSubset(unsigned int numSubsetVars,
    00168                         const unsigned int * subsetVarData,
    00169                         Mers::Models::Base::BaseModelVariableArray &allVars,
    00170                         Mers::Models::Base::BaseModelVariableArray &subsetVars);
    00171
    00191                 static void loadClause(unsigned int numAssignments,
    00192                         const int clauseData[],
    00193                         Mers::Models::Base::BaseModelVariableArray &variables,
    00194                         Mers::Models::Base::BaseModelClause &clause);
    00195
    00215                 template<int n>
    00216                 static void loadClauses(
    00217                         unsigned int numClauses,
    00218                         const int clauseData[][n],
    00219                         Mers::Models::Base::BaseModelVariableArray &vars,
    00220                         Mers::Models::Base::BaseModelClauseArray &clauses)
    00221                 {
    00222                         for(unsigned int i = 0; i < numClauses; ++i) {
    00223                                 Mers::Models::Base::BaseModelClause * clause =
    00224                                         new Mers::Models::Base::BaseModelClause(
    00225                                         Mers::Models::Base::BaseModelClause::DISJUNCTIVE, true);
    00226
    00227                                 loadClause(n, clauseData[i], vars, *clause);
    00228                                 clauses.pushBack(clause);
    00229                         }
    00230                 }
    00231
    00257                 template<int n>
    00258                 static void loadAssignments(std::vector<Mers::Models::Base::BaseModelAssignmentArray *> &assignments,
    00259                         unsigned int numAssignments, const unsigned int assignmentsData[][n],
    00260                         Mers::Models::Base::BaseModelVariableArray & variables)
    00261                 {
    00262                         const unsigned int noVal = (unsigned int) -1;
    00263
    00264                         for(unsigned int a = 0; a < numAssignments; a++)
    00265                         {
    00266                                 Mers::Models::Base::BaseModelAssignmentArray * asgArray =
    00267                                         new Mers::Models::Base::BaseModelAssignmentArray(true);
    00268
    00269                                 for(unsigned int v = 0; v < n; v++)
    00270                                 {
    00271                                         unsigned int valIndex = assignmentsData[a][v];
    00272                                         if(valIndex != noVal) {
    00273                                                 //std::cout << std::endl << "LoadAssignment[" << a << "][" << v << "] = " << valIndex << "; DomLength=" << variables[v]->getDomain()->getLength() << std::endl;
    00274                                                 //std::cout << *(variables[v]) << std::endl;
    00275                                                 //std::cout << *(variables[v]->getDomain()) << std::endl;
    00276                                                 ensure("BMHelper::loadAssignments: "
    00277                                                                          "Variable Index is within range",
    00278                                                         v < variables.getLength());
    00279                                                 ensure("BMHelper::loadAssignments: Value Index is within range",
    00280                                                         valIndex < variables[v]->getDomain()->getLength());
    00281
    00282                                                 Mers::Models::Base::BaseModelVariable const * var = variables[v];
    00283                                                 Mers::Models::Base::BaseModelValue const * val = var->getValue(valIndex);
    00284                                                 Mers::Models::Base::BaseModelAssignment * asg = new Mers::Models::Base::BaseModelAssignment(var, val);
    00285
    00286                                                 asgArray->pushBack(asg);
    00287                                         }
    00288                                 }
    00289                                 assignments.push_back(asgArray);
    00290                         }
    00291                 }
    00292         };
    00293
    00294 }
    00295
    00296 #endif
    00297