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

# /Users/fpy/titan-1-5-MBARI/Mers/Generators/BFIG/BFIGObjectiveFunction.h

    00001
    00002 //
    00003 // Copyright (c) 2005           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 __BFIGObjectiveFunction__
    00015 #define __BFIGObjectiveFunction__
    00016
    00017 #include <vector>
    00018 #include <math.h>
    00019
    00020 #include <Mers/Models/Base/BaseModelAssignmentArray.h>
    00021
    00022 namespace Mers {
    00023         namespace Models {
    00024                 namespace Base {
    00025                         class BaseModelAssignment;
    00026                         class BaseModelAssignmentArray;
    00027                 }
    00028         }
    00029         namespace Generators {
    00030                 namespace BFIG {
    00031
    00032                         class BFIGAssignment;
    00033
    00045                         class BFIGObjectiveFunction
    00046                         {
    00047
    00048                         public:
    00049                                 //--------------------------------------------
    00050                                 //      CONSTRUCTOR
    00051                                 //--------------------------------------------
    00052
    00056                                 BFIGObjectiveFunction(const bool mpi = true) : objectiveFunctionIsMPI(mpi) {};
    00057
    00061                                 virtual ~BFIGObjectiveFunction() {};
    00062
    00063                                 //--------------------------------------------
    00064                                 //      PUBLIC FUNCTION METHODS
    00065                                 //--------------------------------------------
    00066
    00077                                 double getUtility(std::vector<Mers::Generators::BFIG::BFIGAssignment const *> & implicantAssignments,
    00078                                                                         int sourceStateIndex = -1) const
    00079                                 {
    00080                                         double utility;
    00081                                         std::vector<Mers::Models::Base::BaseModelAssignment const *> bmAssignments;
    00082                                         for(unsigned int i=0; i<implicantAssignments.size(); i++)
    00083                                                         bmAssignments.push_back((Mers::Models::Base::BaseModelAssignment const *)
    00084                                                                 (implicantAssignments[i]));
    00085                                         utility = calculateUtility(bmAssignments, sourceStateIndex);
    00086                                         bmAssignments.clear();
    00087                                         return utility;
    00088                                 };
    00099                                 double getUtility(Mers::Models::Base::BaseModelAssignmentArray const * bmAssignments,
    00100                                                                         int sourceStateIndex = -1) const
    00101                                 {
    00102                                         double utility;
    00103                                         std::vector<Mers::Models::Base::BaseModelAssignment const *> bmAssignmentVector;
    00104                                         for(unsigned int i=0; i<bmAssignments->getLength(); i++)
    00105                                                         bmAssignmentVector.push_back((*bmAssignments)[i]);
    00106                                         utility = calculateUtility(bmAssignmentVector, sourceStateIndex);
    00107                                         bmAssignmentVector.clear();
    00108                                         return utility;
    00109                                 };
    00120                                 double getCost(std::vector<Mers::Generators::BFIG::BFIGAssignment const *> & implicantAssignments,
    00121                                                                 int sourceStateIndex = -1) const
    00122                                 {
    00123                                         double cost;
    00124                                         std::vector<Mers::Models::Base::BaseModelAssignment const *> bmAssignments;
    00125                                         for(unsigned int i=0; i<implicantAssignments.size(); i++)
    00126                                                         bmAssignments.push_back((Mers::Models::Base::BaseModelAssignment const *)
    00127                                                                 (implicantAssignments[i]));
    00128                                         cost = (-1.0) * log(calculateUtility(bmAssignments, sourceStateIndex));
    00129                                         bmAssignments.clear();
    00130                                         return cost;
    00131                                 };
    00132
    00139                                 bool isMPI(void) const
    00140                                 {
    00141                                         return objectiveFunctionIsMPI;
    00142                                 };
    00143
    00144
    00145                         protected:
    00146                                 //--------------------------------------------
    00147                                 //      PROTECTED FUNCTION METHODS
    00148                                 //--------------------------------------------
    00149
    00161                                  virtual double calculateUtility(std::vector<Mers::Models::Base::BaseModelAssignment const *> & bmAssignments,
    00162                                                                                                         int sourceStateIndex = -1) const = 0;
    00163
    00164                         private:
    00165                                 //--------------------------------------------
    00166                                 //      PRIVATE FUNCTION METHODS
    00167                                 //--------------------------------------------
    00168
    00169                                 //--------------------------------------------
    00170                                 //      PRIVATE DATA MEMBERS
    00171                                 //--------------------------------------------
    00172
    00173                                 // States whether the objective function is MPI or not
    00174                                 const bool objectiveFunctionIsMPI;
    00175                         };
    00176                 }
    00177         }
    00178 }
    00179
    00180 #endif //ndef __BFIGObjectiveFunction__
    00181