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

# /Users/fpy/titan-1-5-MBARI/Mers/Generators/BFIG/unit-tests/BFIGHelper.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 //
    00010
    00011
    00012 #ifndef BFIG_HELPER_HEADER_FILE
    00013 #define BFIG_HELPER_HEADER_FILE
    00014
    00015 #include <tut.h>
    00016 #include <vector>
    00017 #include <Mers/Models/Base/unit-tests/BMHelper.h>
    00018 #include <Mers/Models/Base/BaseModelAssignmentArray.h>
    00019 #include <Mers/Models/Base/BaseModelVariableArray.h>
    00020 #include <Mers/Utils/Containers/IntegerArray.h>
    00021 #include <Mers/Generators/BFIG/BFIGVariable.h>
    00022
    00023 namespace tut {
    00024
    00030         class BFIGHelper : public BMHelper
    00031         {
    00032         public:
    00036                 BFIGHelper();
    00037
    00041                 virtual ~BFIGHelper();
    00042
    00043         protected:
    00047                 struct BFIGDomainEntry {
    00049                         struct BMDomainEntry bmData;
    00050                 };
    00051
    00055                 struct BFIGVariableEntry {
    00058                         bool registered;
    00060                         struct BMVariableEntry bmData;
    00067                         double const * probsOrCosts;
    00068                 };
    00069
    00083                 void initBFIGData(unsigned int numDomains,
    00084                         const struct BFIGDomainEntry * domains,
    00085                         unsigned int numVariables,
    00086                         const struct BFIGVariableEntry * variables) throw();
    00087
    00097                 void initBFIGVariables(bool isProbabilities) throw();
    00098
    00124                 template<int n>
    00125                 void loadAssignments(std::vector<Mers::Models::Base::BaseModelAssignmentArray *> &assignments,
    00126                         unsigned int numAssignments, const unsigned int assignmentsData[][n])
    00127                 {
    00128                         const unsigned int noVal = (unsigned int) -1;
    00129
    00130                         for(unsigned int a = 0; a < numAssignments; a++)
    00131                         {
    00132                                 Mers::Models::Base::BaseModelAssignmentArray * asgArray =
    00133                                         new Mers::Models::Base::BaseModelAssignmentArray(true);
    00134
    00135                                 for(unsigned int v = 0; v < n; v++)
    00136                                 {
    00137                                         unsigned int valIndex = assignmentsData[a][v];
    00138                                         if(valIndex != noVal) {
    00139                                                 ensure("BFIGHelper::loadAssignments: "
    00140                                                                          "Variable Index is within range",
    00141                                                         v < mBFIGVariables.getLength());
    00142                                                 ensure("BFIGHelper::loadAssignments: Value Index is within range",
    00143                                                         valIndex < mBFIGVariables[v]->getDomain()->getLength());
    00144
    00145                                                 Mers::Models::Base::BaseModelVariable const * var = mBFIGVariables[v];
    00146                                                 Mers::Models::Base::BaseModelValue const * val = var->getValue(valIndex);
    00147                                                 Mers::Models::Base::BaseModelAssignment * asg = new Mers::Models::Base::BaseModelAssignment(var, val);
    00148
    00149                                                 asgArray->pushBack(asg);
    00150                                         }
    00151                                 }
    00152                                 assignments.push_back(asgArray);
    00153                         }
    00154                 }
    00155
    00176                 void loadAssignments(std::vector<Mers::Generators::BFIG::BFIGAssignment *>
    00177                                 &assignments, const unsigned int assignmentsData[]);
    00178
    00199                 void loadAssignments(std::vector<Mers::Generators::BFIG::BFIGAssignment const *>
    00200                         &assignments, const unsigned int assignmentsData[]);
    00201
    00230                 void loadConstraints(std::vector<Mers::Generators::BFIG::BFIGConstraint *>
    00231                         &constraints, const unsigned int constraintValues[],
    00232                         const bool constraintParity[]);
    00233
    00262                 void loadConstraints(std::vector<Mers::Generators::BFIG::BFIGConstraint const *>
    00263                         &constraints, const unsigned int constraintValues[],
    00264                         const bool constraintParity[]);
    00265
    00275                 template<class T>
    00276                 void convertVector(std::vector<const T *> &constVect, const std::vector<T *> &vect)
    00277                 {
    00278                         unsigned int size = vect.size();
    00279                         constVect.resize(size);
    00280                         for(unsigned int v = 0; v < size; v++) {
    00281                                 constVect[v] = vect[v];
    00282                         }
    00283                 }
    00284
    00285         protected:
    00287                 Mers::Models::Base::BaseModelVariableArray mBFIGVariables;
    00289                 Mers::Models::Base::BaseModelVariableArray mAllVariables;
    00291                 Mers::Models::Base::BaseModelDomainArray mDomains;
    00294                 Mers::Utils::Containers::IntegerArray mValueMap;
    00296                 std::vector<double> mProbabilities;
    00299                 std::vector<Mers::Generators::BFIG::BFIGVariable *> mBFIGVarList;
    00300         };
    00301
    00302
    00303 }
    00304
    00305 #endif
    00306