00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef _CSP_FILTERS_AC2001_H
00025 #define _CSP_FILTERS_AC2001_H
00026
00027
00028 CSP_NAMESPACE_BEGIN(csp);
00029 CSP_NAMESPACE_BEGIN(filters);
00030
00031
00038 class CSP_API AC2001 :
00039 public Filter
00040 {
00041 public:
00042 AC2001(Problem& problem, Retraction& retraction) :
00043 Filter(L"Arc Consistency 2001", L"AC-2001", problem, retraction) {}
00044 ~AC2001() {}
00045
00046 virtual bool init(
00047 const vlist_type& uninstantiatedVariables,
00048 bool propagate = true);
00049 virtual void done() { Filter::done(); }
00050
00051 virtual bool restoresArcConsistency() const { return true; }
00052
00053 virtual bool propagate(
00054 const vlist_type& uninstantiatedVariables,
00055 const vlist_type& modifiedVariables,
00056 const bool keepChanges = true);
00057
00058 private:
00060 AC2001(const AC2001&);
00061
00063 AC2001& operator=(const AC2001&);
00064
00070 void insertInQueue(Variable& variable);
00071
00077 void removeFromQueue(Variable& variable);
00078
00085 bool isInQueue(const Variable& variable);
00086
00095 void prune(
00096 Variable& variable,
00097 const Constraint& constraint,
00098 Domain& diffs);
00099
00115 Value* findSupport(
00116 Variable& variable,
00117 Value& value,
00118 const Constraint& constraint,
00119 Variable& pair);
00120
00133 Value* findSupportInDomain(
00134 Variable& variable,
00135 Value& value,
00136 const Constraint& constraint,
00137 Variable& pair,
00138 Domain& subDomain);
00139
00141 void clearSupports();
00142
00144 void clearDomains();
00145
00147 Domain m_diffs;
00148
00150 deque<Variable*> m_queue;
00151
00153 hash_set<const Variable*> m_inQueue;
00154
00155 typedef hash_map<const Value*, Value*> shash_type;
00156 typedef hash_map<const Constraint*, shash_type*> phash_type;
00157 typedef hash_map<const Variable*, phash_type*> thash_type;
00158 typedef hash_map<const Variable*, Domain*> dhash_type;
00159
00173 thash_type m_supports;
00174
00179 dhash_type m_domains;
00180 };
00181
00182
00183 CSP_NAMESPACE_END(filters);
00184 CSP_NAMESPACE_END(csp);
00185
00186
00187 #endif // _CSP_FILTERS_AC2001_H
00188
00189
00190
00191