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

WeightedDegree.h

00001 // WeightedDegree.h -- The `maximum/minimum weighted degree' variable
00002 // ordering heuristic interface.
00003 
00004 /*
00005  * Copyright (C) 2005 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: WeightedDegree_8h-source.html,v 1.1 2005/05/25 12:37:18 tudor Exp $
00024 
00025 #ifndef _CSP_HEURISTICS_VARIABLE_WeightedDegree_H
00026 #define _CSP_HEURISTICS_VARIABLE_WeightedDegree_H
00027 
00028 
00029 #include "../../caches/WeightedDegrees.h"
00030 
00031 
00032 CSP_NAMESPACE_BEGIN(csp);
00033 CSP_NAMESPACE_BEGIN(heuristics);
00034 CSP_NAMESPACE_BEGIN(variables);
00035 
00036 
00037 class WeightedDegreeLT :
00038     public StrictWeakVariableOrdering
00039 {
00040   public:
00041     WeightedDegreeLT(caches::WeightedDegrees& weightedDegrees) :
00042         m_weightedDegrees(weightedDegrees) {}
00043 
00044     bool operator()(const Variable* variable0, const Variable* variable1)
00045     {
00046         return
00047             m_weightedDegrees.weightedDegree(*variable0) <
00048             m_weightedDegrees.weightedDegree(*variable1);
00049     }
00050 
00051   private:
00052     caches::WeightedDegrees& m_weightedDegrees;
00053 };
00054 
00055 
00056 class WeightedDegreeGT :
00057     public StrictWeakVariableOrdering
00058 {
00059   public:
00060     WeightedDegreeGT(caches::WeightedDegrees& weightedDegrees) :
00061         m_weightedDegrees(weightedDegrees) {}
00062 
00063     bool operator()(const Variable* variable0, const Variable* variable1)
00064     {
00065         return
00066             m_weightedDegrees.weightedDegree(*variable0) >
00067             m_weightedDegrees.weightedDegree(*variable1);
00068     }
00069 
00070   private:
00071     caches::WeightedDegrees& m_weightedDegrees;
00072 };
00073 
00074 
00075 class WeightedDegreeEQ :
00076     public StrictWeakVariableOrdering
00077 {
00078   public:
00079     WeightedDegreeEQ(caches::WeightedDegrees& weightedDegrees) :
00080         m_weightedDegrees(weightedDegrees),
00081         m_previousVariable0(0),
00082         m_previousVariable1(0),
00083         m_previousWeightedDegree0(0),
00084         m_previousWeightedDegree1(0) {}
00085 
00086     bool operator()(const Variable* variable0, const Variable* variable1);
00087 
00088     void reset()
00089     {
00090         m_previousVariable0 = 0;
00091         m_previousVariable1 = 0;
00092         m_previousWeightedDegree0 = 0;
00093         m_previousWeightedDegree1 = 0;
00094     }
00095 
00096   private:
00097     caches::WeightedDegrees& m_weightedDegrees;
00098 
00099     const Variable* m_previousVariable0;
00100     const Variable* m_previousVariable1;
00101 
00102     ulonglong m_previousWeightedDegree0;
00103     ulonglong m_previousWeightedDegree1;
00104 };
00105 
00106 
00116 class CSP_API WeightedDegree :
00117     public VariableOH
00118 {
00119   public:
00120     enum Preference
00121     {
00123         Minimum,
00124 
00126         Maximum
00127     };
00128 
00138     WeightedDegree(
00139         Decomposition& decomposition,
00140         const vector<pair<double, double> >& intervals,
00141         double quality = 1,
00142         Preference preference = Maximum);
00143 
00151     virtual void select(vlist_type& selectable, vlist_type& selected);
00152 
00153   private:
00155     WeightedDegree(const WeightedDegree&);
00156 
00158     WeightedDegree& operator=(const WeightedDegree&);
00159 
00161     Preference m_preference;
00162 
00164     caches::WeightedDegrees m_weightedDegrees;
00165 
00168     WeightedDegreeLT m_compareLT;
00169 
00172     WeightedDegreeGT m_compareGT;
00173 
00175     WeightedDegreeEQ m_compareEQ;
00176 };
00177 
00178 
00179 CSP_NAMESPACE_END(variables);
00180 CSP_NAMESPACE_END(heuristics);
00181 CSP_NAMESPACE_END(csp);
00182 
00183 
00184 #endif // _CSP_HEURISTICS_VARIABLE_WeightedDegree_H
00185 
00186 // Local Variables:
00187 // mode: C++
00188 // End:

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