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

values/Branching.h

00001 // Branching.h -- The `maximum/minimum branching' value ordering
00002 // heuristic interface.
00003 
00004 /*
00005  * Copyright (C) 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: values_2Branching_8h-source.html,v 1.1 2005/05/25 12:37:18 tudor Exp $
00024 
00025 #ifndef _CSP_HEURISTICS_VALUE_Branching_H
00026 #define _CSP_HEURISTICS_VALUE_Branching_H
00027 
00028 
00029 #include "../../caches/BranchingFactors.h"
00030 
00031 
00032 CSP_NAMESPACE_BEGIN(csp);
00033 CSP_NAMESPACE_BEGIN(heuristics);
00034 CSP_NAMESPACE_BEGIN(values);
00035 
00036 
00037 class BranchingFactorLT :
00038     public StrictWeakValueOrdering
00039 {
00040   public:
00041     BranchingFactorLT(caches::BranchingFactors& branchingFactors) :
00042         m_branchingFactors(branchingFactors) {}
00043 
00044     bool operator()(const Value* value0, const Value* value1)
00045     {
00046         return
00047             m_branchingFactors.branchingFactor(*value0) <
00048             m_branchingFactors.branchingFactor(*value1);
00049     }
00050 
00051   private:
00052     caches::BranchingFactors& m_branchingFactors;
00053 };
00054 
00055 
00056 class BranchingFactorGT :
00057     public StrictWeakValueOrdering
00058 {
00059   public:
00060     BranchingFactorGT(caches::BranchingFactors& branchingFactors) :
00061         m_branchingFactors(branchingFactors) {}
00062 
00063     bool operator()(const Value* value0, const Value* value1)
00064     {
00065         return
00066             m_branchingFactors.branchingFactor(*value0) >
00067             m_branchingFactors.branchingFactor(*value1);
00068     }
00069 
00070   private:
00071     caches::BranchingFactors& m_branchingFactors;
00072 };
00073 
00074 
00075 class BranchingFactorEQ :
00076     public StrictWeakValueOrdering
00077 {
00078   public:
00079     BranchingFactorEQ(caches::BranchingFactors& branchingFactors) :
00080         m_branchingFactors(branchingFactors),
00081         m_previousValue0(0),
00082         m_previousValue1(0),
00083         m_previousBranchingFactor0(0),
00084         m_previousBranchingFactor1(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_previousBranchingFactor0 = 0;
00093         m_previousBranchingFactor1 = 0;
00094     }
00095 
00096   private:
00097     caches::BranchingFactors& m_branchingFactors;
00098 
00099     const Value* m_previousValue0;
00100     const Value* m_previousValue1;
00101 
00102     size_t m_previousBranchingFactor0;
00103     size_t m_previousBranchingFactor1;
00104 };
00105 
00106 
00112 class CSP_API Branching :
00113     public ValueOH
00114 {
00115   public:
00116     enum Preference
00117     {
00119         Minimum,
00120 
00122         Maximum
00123     };
00124 
00138     Branching(
00139         Decomposition& decomposition,
00140         const vector<pair<double, double> >& intervals,
00141         double quality = 1,
00142         Preference preference = Maximum,
00143         bool analysis = false);
00144 
00152     virtual void dynamicInit(Variable& variable, Domain& selectable);
00153 
00160     virtual void dynamicDone(Variable& variable);
00161 
00170     virtual void select(
00171         Domain& selectable,
00172         Domain& selected,
00173         Variable& variable);
00174 
00183     virtual bool better(const Value& value0, const Value& value1);
00184 
00192     virtual bool equal(const Value& value0, const Value& value1);
00193 
00198     virtual void sort(
00199         Domain& original,
00200         Domain& sorted,
00201         Variable& variable);
00202 
00214     virtual long double score(Variable& variable, const Value& value);
00215 
00216   private:
00218     Branching(const Branching&);
00219 
00221     Branching& operator=(const Branching&);
00222 
00224     Preference m_preference;
00225 
00227     caches::BranchingFactors m_branchingFactors;
00228 
00231     BranchingFactorLT m_compareLT;
00232 
00235     BranchingFactorGT m_compareGT;
00236 
00239     BranchingFactorEQ m_compareEQ;
00240 };
00241 
00242 
00243 CSP_NAMESPACE_END(values);
00244 CSP_NAMESPACE_END(heuristics);
00245 CSP_NAMESPACE_END(csp);
00246 
00247 
00248 #endif // _CSP_HEURISTICS_VALUE_Branching_H
00249 
00250 // Local Variables:
00251 // mode: C++
00252 // End:

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