Main Page | Class Hierarchy | Class List | File List | Class Members

Conflicts.h

00001 // Conflicts.h -- The `minimum/maximum conflicts' value ordering
00002 // heuristic interface.
00003 
00004 /*
00005  * Copyright (C) 1998,2003,2004 Tudor Hulubei <tudor@hulubei.net>.
00006  *
00007  * This library is free software; you can redistribute it and/or modify
00008  * it under the terms of the GNU Lesser General Public License as
00009  * published by the Free Software Foundation; either version 2, or (at
00010  * your option) any later version.
00011  *
00012  * This library is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU Lesser General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with this library; if not, write to the Free Software
00019  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA,
00020  * 02111-1307, USA.
00021  */
00022 
00023 // $Id: Conflicts_8h-source.html,v 1.1 2005/05/25 12:37:18 tudor Exp $
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 // Local Variables:
00286 // mode: C++
00287 // End:

Generated on Wed May 25 12:21:13 2005 for csp.kdevelop by  doxygen 1.3.9.1