00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00013
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
00030
00031
00032
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
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
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
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();
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
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
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
00207
00208
00209
00210 void randomizeIndex();
00211 int getRandomIndex();
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223 private:
00224
00225
00226
00227
00228
00229
00230
00231
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();
00236
00238
00239
00241 std::vector<BFIGAssignment const *> assignments;
00242 std::vector<BFIGAssignment *> assignmentsUnconst;
00243
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