00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066 #ifndef SAT_H_
00067 #define SAT_H_
00068
00069 #include "inference.h"
00070
00075 class SAT : public Inference
00076 {
00077 public:
00078
00079 SAT(VariableState* state, long int seed, const bool& trackClauseTrueCnts) :
00080 Inference(state, seed, trackClauseTrueCnts) {}
00081
00082 SAT(HVariableState* state, long int seed, const bool& trackClauseTrueCnts) :
00083 Inference(state, seed, trackClauseTrueCnts) {}
00084
00085 virtual ~SAT() {}
00086
00090 virtual void printNetwork(ostream& out)
00091 {
00092 }
00093
00094 const int getNumSolutions()
00095 {
00096 return numSolutions_;
00097 }
00098
00099 void setNumSolutions(const int& numSolutions)
00100 {
00101 numSolutions_ = numSolutions;
00102 }
00103
00104 const long double getTargetCost()
00105 {
00106 return targetCost_;
00107 }
00108
00109 void setTargetCost(const long double& targetCost)
00110 {
00111 targetCost_ = targetCost;
00112 }
00113
00117 void printProbabilities(ostream& out)
00118 {
00119 for (int i = 0; i < state_->getNumAtoms(); i++)
00120 {
00121 state_->printGndPred(i, out);
00122 out << " " << state_->getValueOfLowAtom(i + 1) << endl;
00123 }
00124 }
00125
00139 void getChangedPreds(vector<string>& changedPreds, vector<float>& probs,
00140 vector<float>& oldProbs, const float& probDelta)
00141 {
00142 changedPreds.clear();
00143 probs.clear();
00144 int numAtoms = state_->getNumAtoms();
00145
00146 oldProbs.resize(numAtoms, 0);
00147 for (int i = 0; i < numAtoms; i++)
00148 {
00149 int tv = state_->getValueOfLowAtom(i + 1);
00150 if (tv != oldProbs[i])
00151 {
00152
00153
00154 oldProbs[i] = tv;
00155 ostringstream oss(ostringstream::out);
00156 state_->printGndPred(i, oss);
00157 changedPreds.push_back(oss.str());
00158 probs.push_back(tv);
00159 }
00160 }
00161 }
00162
00166 double getProbability(GroundPredicate* const& gndPred)
00167 {
00168 int idx = state_->getGndPredIndex(gndPred);
00169 int truthValue = 0;
00170 if (idx >= 0) truthValue = state_->getValueOfLowAtom(idx + 1);
00171 return truthValue;
00172 }
00173
00174 double getProbabilityH(GroundPredicate* const& gndPred)
00175 {
00176 int idx = state_->getGndPredIndex(gndPred);
00177 int truthValue = 0;
00178 if (idx >= 0) truthValue = state_->getValueOfLowAtom(idx + 1);
00179 return truthValue;
00180 }
00181
00182
00186 void printTruePreds(ostream& out)
00187 {
00188 for (int i = 0; i < state_->getNumAtoms(); i++)
00189 {
00190 if (state_->getValueOfLowAtom(i + 1))
00191 {
00192 state_->printGndPred(i, out);
00193 out << endl;
00194 }
00195 }
00196 }
00197
00198 void printTruePredsH(ostream& out)
00199 {
00200 for (int i = 0; i < state_->getNumAtoms(); i++)
00201 {
00202 if (state_->getValueOfLowAtom(i + 1))
00203 {
00204 state_->printGndPred(i, out);
00205 out << endl;
00206 }
00207 }
00208 }
00209
00210 protected:
00211
00213
00214 int maxTries_;
00215
00216 int maxSteps_;
00217
00218 long double targetCost_;
00219
00220 int numSolutions_;
00222
00223
00224
00225 Array<int> changed_;
00226
00227 int numFlips_;
00228
00229 };
00230
00231 #endif