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

Degree.h

00001 // Degree.h -- The `maximum/minimum degree' variable 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: Degree_8h-source.html,v 1.1 2005/05/25 12:37:18 tudor Exp $
00024 
00025 #ifndef _CSP_HEURISTICS_VARIABLE_Degree_H
00026 #define _CSP_HEURISTICS_VARIABLE_Degree_H
00027 
00028 
00029 #include "../../caches/Degrees.h"
00030 
00031 
00032 CSP_NAMESPACE_BEGIN(csp);
00033 CSP_NAMESPACE_BEGIN(heuristics);
00034 CSP_NAMESPACE_BEGIN(variables);
00035 
00036 
00037 class DegreeLT :
00038     public StrictWeakVariableOrdering
00039 {
00040   public:
00041     DegreeLT(caches::Degrees& degrees) : m_degrees(degrees) {}
00042 
00043     bool operator()(const Variable* variable0, const Variable* variable1)
00044     {
00045         return
00046             m_degrees.degree(*variable0) <
00047             m_degrees.degree(*variable1);
00048     }
00049 
00050   private:
00051     caches::Degrees& m_degrees;
00052 };
00053 
00054 
00055 class DegreeGT :
00056     public StrictWeakVariableOrdering
00057 {
00058   public:
00059     DegreeGT(caches::Degrees& degrees) : m_degrees(degrees) {}
00060 
00061     bool operator()(const Variable* variable0, const Variable* variable1)
00062     {
00063         return
00064             m_degrees.degree(*variable0) >
00065             m_degrees.degree(*variable1);
00066     }
00067 
00068   private:
00069     caches::Degrees& m_degrees;
00070 };
00071 
00072 
00073 class DegreeEQ :
00074     public StrictWeakVariableOrdering
00075 {
00076   public:
00077     DegreeEQ(caches::Degrees& degrees) :
00078         m_degrees(degrees),
00079         m_previousVariable0(0),
00080         m_previousVariable1(0),
00081         m_previousDegree0(0),
00082         m_previousDegree1(0) {}
00083 
00084     bool operator()(const Variable* variable0, const Variable* variable1);
00085 
00086     void reset()
00087     {
00088         m_previousVariable0 = 0;
00089         m_previousVariable1 = 0;
00090         m_previousDegree0 = 0;
00091         m_previousDegree1 = 0;
00092     }
00093 
00094   private:
00095     caches::Degrees& m_degrees;
00096 
00097     const Variable* m_previousVariable0;
00098     const Variable* m_previousVariable1;
00099 
00100     size_t m_previousDegree0;
00101     size_t m_previousDegree1;
00102 };
00103 
00104 
00109 class CSP_API Degree :
00110     public VariableOH
00111 {
00112   public:
00113     enum Preference
00114     {
00116         Minimum,
00117 
00119         Maximum
00120     };
00121 
00131     Degree(
00132         Decomposition& decomposition,
00133         const vector<pair<double, double> >& intervals,
00134         double quality = 1,
00135         Preference preference = Maximum);
00136 
00144     virtual void select(vlist_type& selectable, vlist_type& selected);
00145 
00146   private:
00148     Degree(const Degree&);
00149 
00151     Degree& operator=(const Degree&);
00152 
00154     Preference m_preference;
00155 
00157     caches::Degrees m_degrees;
00158 
00161     DegreeLT m_compareLT;
00162 
00165     DegreeGT m_compareGT;
00166 
00168     DegreeEQ m_compareEQ;
00169 };
00170 
00171 
00172 CSP_NAMESPACE_END(variables);
00173 CSP_NAMESPACE_END(heuristics);
00174 CSP_NAMESPACE_END(csp);
00175 
00176 
00177 #endif // _CSP_HEURISTICS_VARIABLE_Degree_H
00178 
00179 // Local Variables:
00180 // mode: C++
00181 // End:

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