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

# /Users/fpy/titan-1-5-MBARI/Mers/Generators/BFIG/BFIGGenerator.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 //# CHECKED MJP 08-07-2002
    00014
    00015 #ifndef __BFIGGenerator__
    00016 #define __BFIGGenerator__
    00017
    00018 #include <cstdlib>
    00019 #include <list>
    00020
    00021 #include <Mers/Generators/AssignmentGeneratorInterface.h>
    00022
    00023 #include "BFIG.h"
    00024 #include "BFIGFactory.h"
    00025
    00026 namespace Mers {
    00027         namespace Utils {
    00028                 namespace Containers {
    00029                         class IntegerArray;
    00030                 }
    00031         }
    00032 }
    00033 #include <Mers/Utils/Containers/DynamicArrayTemplate.h>
    00034
    00035 #include <Mers/Models/Base/BaseModelVariableArray.h>
    00036 #include <Mers/Models/Base/BaseModelAssignmentArray.h>
    00037
    00038 namespace Mers {
    00039         namespace Models {
    00040                 namespace Base {
    00041                         class BaseModelClause;
    00042                         class BaseModelSentence;
    00043                         class BaseModelClauseArray;
    00044                 }
    00045         }
    00046 }
    00047
    00048 #include <vector>
    00049
    00050 namespace Mers {
    00051         namespace Generators {
    00052                 namespace BFIG {
    00053
    00054                         class BFIGAssignment;
    00055                         class BFIGConstraint;
    00056                         class BFIGConstraintUnit;
    00057                         class BFIGImplicant;
    00058                         class BFIGVariable;
    00059                         class BFIGImplicantExpander;
    00060
    00069                         class BFIGGenerator : public AssignmentGeneratorInterface
    00070                         {
    00071                         public:
    00072                                 typedef Mers::Utils::Containers::DynamicArrayTemplate<Mers::Models::Base::BaseModelSentence const> GuardArray;
    00073
    00074                                 //--------------------------------------------
    00075                                 //      CONSTRUCTOR
    00076                                 //--------------------------------------------
    00077
    00105                                 BFIGGenerator(BFIGFactory &bfigFactory,
    00106                                         Mers::Models::Base::BaseModelVariableArray const & variableSet,
    00107                                         Mers::Generators::BFIG::BFIGObjectiveFunction const * ocspObjectiveFunction,
    00108                                         Mers::Models::Base::BaseModelVariableArray const &allVariables,
    00109                                         double cutoffCost);
    00110
    00152                                 BFIGGenerator(BFIGFactory &bfigFactory,
    00153                                         Mers::Models::Base::BaseModelVariableArray const & variableSet,
    00154                                         Mers::Models::Base::BaseModelVariableArray const &allVariables,
    00155                                         Mers::Utils::Containers::IntegerArray const &valueMap,
    00156                                         std::vector<double> const & probabilities,
    00157                                         double cutoffCost, bool useProb = true);
    00158
    00197                                 BFIGGenerator(BFIGFactory &bfigFactory,
    00198                                         Mers::Models::Base::BaseModelVariableArray const & variableSet,
    00199                                         Mers::Models::Base::BaseModelVariableArray const &allVariables,
    00200                                         Mers::Utils::Containers::IntegerArray const &valueMap,
    00201                                         std::vector<double> const & probabilities,
    00202                                         bool useProb = true);
    00203
    00207                                 virtual ~BFIGGenerator();
    00208
    00209                                 //--------------------------------------------
    00210                                 //      PUBLIC FUNCTION METHODS
    00211                                 //--------------------------------------------
    00212
    00219                                 virtual void addConflict(Mers::Models::Base::BaseModelAssignmentArray const * newConflict);
    00226                                 virtual void addConflict(Mers::Models::Base::BaseModelAssignmentArray const & newConflict);
    00233                                 virtual void addConflicts(Mers::Models::Base::BaseModelClauseArray const &
    00234                                                                                                                                         newConflicts);
    00235
    00236                                 void addConflict(BFIGConstraint const * newConflict);
    00237                                 void addConflict(BFIGConstraint const & newConflict);
    00238                                 void addConflicts(std::vector<BFIGConstraint const *>const & newConflicts);
    00239
    00258                                 Mers::Models::Base::BaseModelAssignmentArray const * generateBestImplicant(
    00259                                         long maximumVisitedStateCount, long maxSize, bool expand = true);
    00260
    00266                                 void markBestFeasible();
    00267
    00275                                 virtual void printStatistics(bool verbose = false) const;
    00276
    00281                                 virtual void restart();
    00288                                 virtual void reset();
    00289
    00295                                 virtual void setDebug(unsigned int state);
    00296
    00301                                 //void normalizeCosts();
    00302
    00316                                 int updateProbability(unsigned int variableUID, unsigned int valueUID,
    00317                                         double prob);
    00318
    00331                                 int updateProbabilities(unsigned int variableUID, double probs[]);
    00332
    00357                                 int updateAllProbabilities(Mers::Models::Base::BaseModelVariableArray const &decisionVars,
    00358                                         Mers::Utils::Containers::IntegerArray const &valueMap,
    00359                                         std::vector<double> const &allProbabilities);
    00360
    00361
    00376                                 int updateCost(unsigned int variableUID, unsigned int valueUID,
    00377                                         double cost);
    00378
    00394                                 int updateCosts(unsigned int variableUID, double costs[]);
    00395
    00403                                 virtual unsigned int getFullAssignmentSize();
    00404
    00410                                 unsigned int getNumberOfConflicts() {
    00411                                         return bfig->getNumberOfConflicts();
    00412                                 }
    00413
    00420                                 unsigned int getLargestQueueSinceReset() {
    00421                                         return bfig->getLargestQueueSinceReset();
    00422                                 }
    00423
    00430                                 unsigned int getTotalNumberNodesExpanded() {
    00431                                         return bfig->getNodesExpanded();
    00432                                 }
    00433
    00440                                 unsigned int getNumberCandidatesSinceReset() {
    00441                                         return bfig->getNumberCandidatesSinceReset();
    00442                                 }
    00443
    00448                                 virtual double getNumberOfSteps() const {
    00449                                         return bfig->getNodesExpanded();
    00450                                 }
    00451
    00452                         protected:
    00470                                 BFIGVariable * variableToVariable(unsigned int bfigVarIndex,
    00471                                         Mers::Models::Base::BaseModelVariable const * varIn,
    00472                                         std::vector<double> &costs, bool useProb) const;
    00473
    00482                                 void sortBMVariables(Mers::Models::Base::BaseModelVariableArray const &unsortedArray,
    00483                                         Mers::Models::Base::BaseModelVariableArray &sortedArray);
    00484
    00499                                 unsigned int bfindBMVariable(Mers::Models::Base::BaseModelVariableArray &sortedVars,
    00500                                         unsigned int uid);
    00501
    00515                                 unsigned int getBFIGVariable(unsigned int bmVarUID,
    00516                                         BFIGVariable * &bfigVar);
    00517
    00518                         private:
    00561                                 std::vector<double> extractVariableProbabilities(
    00562                                         Mers::Models::Base::BaseModelVariable const &myVariable,
    00563                                         unsigned int index, Mers::Utils::Containers::IntegerArray const &valueMap,
    00564                                         std::vector<double> const &allProbabilities) const;
    00565
    00566                                 //--------------------------------------------
    00567                                 //      PRIVATE DATA MEMBERS
    00568                                 //--------------------------------------------
    00569
    00572                                 //std::vector<BFIGVariable *> allBFIGVars;
    00573                                 // The set of all BFIG variables compactly stored so BFIG is happy.
    00574                                 std::vector<BFIGVariable *> compactBFIGVars;
    00575
    00578                                 Mers::Models::Base::BaseModelVariableArray mSearchBMVars;
    00579
    00581                                 Mers::Models::Base::BaseModelAssignmentArray bmImplicant;
    00582
    00584                                 BFIG * bfig;
    00585
    00586                                 //--------------------------------------------
    00587                                 //      PRIVATE FUNCTION METHODS
    00588                                 //--------------------------------------------
    00589
    00590                         };
    00591                 }
    00592         }
    00593 }
    00594
    00595 #endif //ndef __BFIGGenerator__
    00596