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 #ifndef _CSP_HEURISTICS_VALUE_Conflicts_H
00026 #define _CSP_HEURISTICS_VALUE_Conflicts_H
00027
00028
00029 #include "../../caches/ConflictCounts.h"
00030
00031
00032 CSP_NAMESPACE_BEGIN(csp);
00033 CSP_NAMESPACE_BEGIN(heuristics);
00034 CSP_NAMESPACE_BEGIN(values);
00035
00036
00037 class ConflictCountLT :
00038 public StrictWeakValueOrdering
00039 {
00040 public:
00041 ConflictCountLT(caches::ConflictCounts& conflictCounts) :
00042 m_conflictCounts(conflictCounts) {}
00043
00044 bool operator()(const Value* value0, const Value* value1)
00045 {
00046 return
00047 m_conflictCounts.conflictCount(*value0) <
00048 m_conflictCounts.conflictCount(*value1);
00049 }
00050
00051 private:
00052 caches::ConflictCounts& m_conflictCounts;
00053 };
00054
00055
00056 class ConflictCountGT :
00057 public StrictWeakValueOrdering
00058 {
00059 public:
00060 ConflictCountGT(caches::ConflictCounts& conflictCounts) :
00061 m_conflictCounts(conflictCounts) {}
00062
00063 bool operator()(const Value* value0, const Value* value1)
00064 {
00065 return
00066 m_conflictCounts.conflictCount(*value0) >
00067 m_conflictCounts.conflictCount(*value1);
00068 }
00069
00070 private:
00071 caches::ConflictCounts& m_conflictCounts;
00072 };
00073
00074
00075 class ConflictCountEQ :
00076 public StrictWeakValueOrdering
00077 {
00078 public:
00079 ConflictCountEQ(caches::ConflictCounts& conflictCounts) :
00080 m_conflictCounts(conflictCounts),
00081 m_previousValue0(0),
00082 m_previousValue1(0),
00083 m_previousConflictCount0(0),
00084 m_previousConflictCount1(0) {}
00085
00086 bool operator()(const Value* value0, const Value* value1);
00087
00088 void reset()
00089 {
00090 m_previousValue0 = 0;
00091 m_previousValue1 = 0;
00092 m_previousConflictCount0 = 0;
00093 m_previousConflictCount1 = 0;
00094 }
00095
00096 private:
00097 caches::ConflictCounts& m_conflictCounts;
00098
00099 const Value* m_previousValue0;
00100 const Value* m_previousValue1;
00101
00102 size_t m_previousConflictCount0;
00103 size_t m_previousConflictCount1;
00104 };
00105
00106
00115 class CSP_API Conflicts :
00116 public ValueOH
00117 {
00118 public:
00119 enum Preference
00120 {
00122 Minimum,
00123
00125 Maximum
00126 };
00127
00143 Conflicts(
00144 Decomposition& decomposition,
00145 const vector<pair<double, double> >& intervals,
00146 double quality = 1,
00147 Preference preference = Minimum,
00148 bool dynamic = false,
00149 bool analysis = false);
00150
00152 ~Conflicts();
00153
00161 virtual void init(const vlist_type& uninstantiatedVariables);
00162
00164 virtual void done();
00165
00173 virtual void dynamicInit(Variable& variable, Domain& selectable);
00174
00181 virtual void dynamicDone(Variable& variable);
00182
00190 virtual void select(
00191 Domain& selectable,
00192 Domain& selected,
00193 Variable& variable);
00194
00203 virtual bool better(const Value& value0, const Value& value1);
00204
00212 virtual bool equal(const Value& value0, const Value& value1);
00213
00218 virtual void sort(
00219 Domain& original,
00220 Domain& sorted,
00221 Variable& variable);
00222
00234 virtual long double score(Variable& variable, const Value& value);
00235
00236 private:
00238 Conflicts(const Conflicts&);
00239
00241 Conflicts& operator=(const Conflicts&);
00242
00250 void compute(const Constraint& c);
00251
00253 Preference m_preference;
00254
00259 bool m_dynamic;
00260
00262 caches::ConflictCounts m_conflictCounts;
00263
00266 ConflictCountLT m_compareLT;
00267
00270 ConflictCountGT m_compareGT;
00271
00274 ConflictCountEQ m_compareEQ;
00275 };
00276
00277
00278 CSP_NAMESPACE_END(values);
00279 CSP_NAMESPACE_END(heuristics);
00280 CSP_NAMESPACE_END(csp);
00281
00282
00283 #endif // _CSP_HEURISTICS_VALUE_Conflicts_H
00284
00285
00286
00287