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

heuristics/variables/Domain.h

00001 // Domain.h -- The `minimum/maximum domain' 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: heuristics_2variables_2Domain_8h-source.html,v 1.1 2005/05/25 12:37:18 tudor Exp $
00024 
00025 #ifndef _CSP_HEURISTICS_VARIABLE_Domain_H
00026 #define _CSP_HEURISTICS_VARIABLE_Domain_H
00027 
00028 
00029 #include "../../caches/DomainSizes.h"
00030 
00031 
00032 CSP_NAMESPACE_BEGIN(csp);
00033 CSP_NAMESPACE_BEGIN(heuristics);
00034 CSP_NAMESPACE_BEGIN(variables);
00035 
00036 
00037 class DomainSizeLT :
00038     public StrictWeakVariableOrdering
00039 {
00040   public:
00041     DomainSizeLT(caches::DomainSizes& domainSizes) :
00042         m_domainSizes(domainSizes) {}
00043 
00044     bool operator()(const Variable* variable0, const Variable* variable1)
00045     {
00046         return
00047             m_domainSizes.domainSize(*variable0) <
00048             m_domainSizes.domainSize(*variable1);
00049     }
00050 
00051   private:
00052     caches::DomainSizes& m_domainSizes;
00053 };
00054 
00055 
00056 class DomainSizeGT :
00057     public StrictWeakVariableOrdering
00058 {
00059   public:
00060     DomainSizeGT(caches::DomainSizes& domainSizes) :
00061         m_domainSizes(domainSizes) {}
00062 
00063     bool operator()(const Variable* variable0, const Variable* variable1)
00064     {
00065         return
00066             m_domainSizes.domainSize(*variable0) >
00067             m_domainSizes.domainSize(*variable1);
00068     }
00069 
00070   private:
00071     caches::DomainSizes& m_domainSizes;
00072 };
00073 
00074 
00075 class DomainSizeEQ :
00076     public StrictWeakVariableOrdering
00077 {
00078   public:
00079     DomainSizeEQ(caches::DomainSizes& domainSizes) :
00080         m_domainSizes(domainSizes),
00081         m_previousVariable0(0),
00082         m_previousVariable1(0),
00083         m_previousDomainSize0(0),
00084         m_previousDomainSize1(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_previousDomainSize0 = 0;
00093         m_previousDomainSize1 = 0;
00094     }
00095 
00096   private:
00097     caches::DomainSizes& m_domainSizes;
00098 
00099     const Variable* m_previousVariable0;
00100     const Variable* m_previousVariable1;
00101 
00102     size_t m_previousDomainSize0;
00103     size_t m_previousDomainSize1;
00104 };
00105 
00106 
00111 class CSP_API Domain :
00112     public VariableOH
00113 {
00114   public:
00115     enum Preference
00116     {
00118         Minimum,
00119 
00121         Maximum
00122     };
00123 
00133     Domain(
00134         Decomposition& decomposition,
00135         const vector<pair<double, double> >& intervals,
00136         double quality = 1,
00137         Preference preference = Minimum);
00138 
00146     virtual void select(vlist_type& selectable, vlist_type& selected);
00147 
00148   private:
00150     Domain(const Domain&);
00151 
00153     Domain& operator=(const Domain&);
00154 
00156     Preference m_preference;
00157 
00159     caches::DomainSizes m_domainSizes;
00160 
00163     DomainSizeLT m_compareLT;
00164 
00167     DomainSizeGT m_compareGT;
00168 
00170     DomainSizeEQ m_compareEQ;
00171 };
00172 
00173 
00174 CSP_NAMESPACE_END(variables);
00175 CSP_NAMESPACE_END(heuristics);
00176 CSP_NAMESPACE_END(csp);
00177 
00178 
00179 #endif // _CSP_HEURISTICS_VARIABLE_Domain_H
00180 
00181 // Local Variables:
00182 // mode: C++
00183 // End:

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