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

# /Users/fpy/titan-1-5-MBARI/Mers/Generators/BFIG/BFIGVariable.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 __VARIABLE_BFIG__
    00016 #define __VARIABLE_BFIG__
    00017
    00018 #include <cstdlib>
    00019 #include <iostream>
    00020 #include <vector>
    00021
    00022 #include <Mers/Utils/Lang/String.h>
    00023
    00024 #include "BFIGAssignment.h"
    00025 #include <Mers/Utils/Containers/IntegerArray.h>
    00026
    00027 #include <Mers/Utils/Containers/DynamicArray.h>
    00028
    00029         /*# assuming a NULL current assignment is better - but for now, we'll hack in a
    00030          *  default for testing: */
    00031 //#define VARIABLE_DEFAULT_CURRENT
    00032 //#define ASSIGNMENT_MARGINAL_PROBABILITY   0.0000000001
    00033
    00034 namespace Mers {
    00035         namespace Models {
    00036                 namespace Base {
    00037                         class BaseModelSentence;
    00038                         class BaseModelVariable;
    00039                 }
    00040         }
    00041 }
    00042
    00043 namespace Mers {
    00044         namespace Solvers {
    00045                 namespace SAT {
    00046                         class AssignmentTesterInterface;
    00047                 }
    00048         }
    00049 }
    00050
    00051 namespace Mers {
    00052         namespace Generators {
    00053                 namespace BFIG {
    00054
    00062                         class BFIGVariable
    00063                         {
    00064                         public:
    00065                                 friend std::ostream &  operator<<(std::ostream & os, BFIGVariable const & v);
    00066                                 friend class BFIGAssignment;
    00067
    00068                         public:
    00069                                 bool operator==(BFIGVariable const & v) const;
    00070                                 bool operator< (BFIGVariable const & v)  const;
    00071
    00072                                 //------------------------------------------------------
    00073                                 //      TYPE DEFINITIONS
    00074                                 //------------------------------------------------------
    00075                                 //typedef Mers::Utils::Lang::String /*const*/ Value;
    00076
    00077                                 //------------------------------------------------------
    00078                                 //      CONSTRUCTOR
    00079                                 //------------------------------------------------------
    00080
    00081                                 // Performs normalization of the domain. 'probabilityValues'
    00082                                 // turns on a special mode for probability - the cost values
    00083                                 // are transformed into their negative logs.  Otherwise,
    00084                                 // assumes additive cost function, lower is better...
    00085                                 // Costs can be specified either as a simple list or as a list
    00086                                 // of length equal to the square of the domain list length -
    00087                                 // which specifies a matrix of costs based on the 'current'
    00088                                 // value. A matrix of guards can also be supplied that
    00089                                 // condition the transitions.
    00090
    00091                                 BFIGVariable(unsigned int index,
    00092                                         Mers::Models::Base::BaseModelVariable const * bmVariable,
    00093                                         std::vector<double> const & costList,
    00094                                         bool probabilityValues = false);
    00095
    00096                                 BFIGVariable(BFIGVariable const & v);
    00097
    00098                                 ~BFIGVariable();
    00099
    00100                                 //------------------------------------------------------
    00101                                 //      PUBLIC FUNCTION MEMBERS
    00102                                 //------------------------------------------------------
    00103                                 unsigned int         getName()  const;
    00104                                 Mers::Utils::Lang::String               getNameString()  const;
    00105                                 unsigned int         getNameInt()  const;
    00106                                 BFIGAssignment const *   getAssignmentByValue(Mers::Utils::Lang::String val)  const;
    00107                                 BFIGAssignment const *   getAssignmentByValue(unsigned int val)  const;
    00113                                 BFIGAssignment *   getAssignmentByValue(unsigned int val);
    00114
    00115                                 Mers::Utils::Containers::IntegerArray   getDomain()  const;
    00116                                 std::vector<Mers::Utils::Lang::String>         getDomainStrings()  const;
    00117                                 unsigned int         getDomainSize()  const;
    00118                                 unsigned int         getDomainTotalSize()  const;
    00119                                 std::vector<BFIGAssignment const *>
    00120                                 getAssignments()  const;
    00121                                 std::vector<BFIGAssignment const *>
    00122                                 getAssignmentsSorted()  const;
    00123                                 Mers::Utils::Containers::IntegerArray   getDomainTotal()  const;
    00124                                 std::vector<BFIGAssignment const *> const &
    00125                                 getAssignmentsTotal()  const;
    00126                                 bool                 allReachable()  const;
    00127                                 bool                 nullDomain()  const;
    00128
    00133                                 void setBMVariable(Mers::Models::Base::BaseModelVariable const * newBMVar)
    00134                                 {
    00135                                         mBMVariable = newBMVar;
    00136                                 }
    00137
    00142                                 Mers::Models::Base::BaseModelVariable const * getBMVariable() const
    00143                                 {
    00144                                         return mBMVariable;
    00145                                 }
    00146
    00147                                 BFIGAssignment const *   getBestAssignment();  //  const;
    00148                                 double               getEntropy(bool logProbabilities = true)  const;
    00149                                 double               getEntropyTotal(bool logProbabilities = true)  const;
    00150
    00151                                 void                 setAllCosts(double cost);
    00152                                 void                 setAssignmentCostByValue(unsigned int val, double cost);
    00153                                 void                 setAssignmentCostByValue(Mers::Utils::Lang::String val, double cost);
    00154                                 void                 setAllTrueCosts(double cost);
    00155                                 void                 setAssignmentTrueCostByValue(unsigned int val, double cost);
    00156                                 void                 setAssignmentTrueCostByValue(Mers::Utils::Lang::String val, double cost);
    00157
    00163                                 double probToCost(double prob);
    00164
    00171                                 int setCost(unsigned int valUID, double cost);
    00172
    00179                                 int setCosts(double costs[]);
    00180
    00181                                 //void                 setAssignmentReachableByValue(Mers::Utils::Lang::String val, bool reachable);
    00182                                 //void                 setAssignmentReachableByValue(unsigned int val, bool reachable);
    00183                                 //void                 setReachableAll(bool reachable);
    00184                                 // returns 'false' if can't find val:
    00185                                 //BFIGAssignment const *   getCurrentAssignment()  const;
    00186                                 //bool                 setCurrent(unsigned int val);
    00187                                 //bool                 setCurrent(Mers::Utils::Lang::String val);
    00188                                 //bool                 setCurrent(BFIGAssignment const * a);
    00189                                 //bool                 clearCurrent();
    00190                                 //BFIGAssignment const *   getNextAssignment()  const;
    00191                                 //bool                 setNext(unsigned int val);
    00192                                 //bool                 setNext(Mers::Utils::Lang::String val);
    00193                                 //bool                 setNext(BFIGAssignment const * a);
    00194                                 //bool                 clearNext();
    00195                                 //void                 setTrueCostsByCurrent();
    00196                                 //void                 enableAssignmentsByGuards(AssignmentTesterInterface * currentSat);
    00197                                 //void                 enableAssignmentsByGuards();
    00198                                 //void                 reset();
    00199
    00200                                 void                 orderCosts();
    00201                                 void                 normalizeCosts();
    00202
    00203                                 BFIGAssignment const *   bestConsistentAssignment(std::vector<BFIGAssignment const *> const & others);
    00204                                 Mers::Utils::Lang::String               toString()  const;
    00205
    00206                                 // used to remove unwanted assignments:
    00207                                 //void                 eraseUnreachable();
    00208
    00209                                 // these are just for helping with random ordering:
    00210                                 void                 randomizeIndex();
    00211                                 int                  getRandomIndex();
    00212                                 //bool                 isAssigned() const;
    00213                                 //BFIGAssignment const *   getCurrentAssignment() const;
    00214                                 //void                 setCurrentAssignment(BFIGAssignment const * newCurrentAssignment_p);
    00215                                 //void                 setPreviousAssignment(BFIGAssignment const * newPreviousAssignment_p);
    00216
    00217                                 //BFIGAssignment const *   getCurrentImplicantAssignment() const;
    00218                                 //void                 setCurrentImplicantAssignment(BFIGAssignment const * newNode_p);
    00219
    00220                                 //void                             printValue() const;
    00221                                 //void                             printVariable() const;
    00222
    00223                         private:
    00224                                 // used for converting string names to integers - could also use a hash, possibly...
    00225                                 //static unsigned int       varCount;
    00226
    00227                                 // used for random number index only
    00228                                 //static bool               seeded;
    00229
    00230                                 //void                 init(IntegerArray const & domain, std::vector<double> costs,
    00231                                 //      DynamicArrayTemplate<Mers::Models::Base::BaseModelSentence const> const & guards, bool probability);
    00232                                 void init(std::vector<double> costs, bool probability);
    00233                                 unsigned int         valueStringToInt(Mers::Utils::Lang::String val)  const;
    00234                                 Mers::Utils::Lang::String               valueIntToString(unsigned int val)  const;
    00235                                 BFIGVariable();  // to dis-allow
    00236
    00238                                 //unsigned int              name;
    00239
    00241                                 std::vector<BFIGAssignment const *>  assignments;
    00242                                 std::vector<BFIGAssignment *>        assignmentsUnconst;
    00243                                 //std::vector<BFIGAssignment const *>  assignmentsReachable;
    00244
    00246                                 int randomIndex;
    00247
    00249                                 unsigned int mIndex;
    00250
    00252                                 BFIGAssignment const * bestAssignment;
    00253
    00254                                 bool isSorted;
    00255
    00257                                 Mers::Models::Base::BaseModelVariable const * mBMVariable;
    00258                         };
    00259                 }
    00260         }
    00261 }
    00262
    00263 #endif //ndef __VARIABLE_BFIG__
    00264
    00265
    00266