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

src/heuristics/values/Random.h

00001 // Random.h -- The `random' value ordering heuristic interface.
00002 
00003 /*
00004  * Copyright (C) 1998,2003,2004 Tudor Hulubei <tudor@hulubei.net>.
00005  *
00006  * This library is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU Lesser General Public License as
00008  * published by the Free Software Foundation; either version 2, or (at
00009  * your option) any later version.
00010  *
00011  * This library is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU Lesser General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public
00017  * License along with this library; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA,
00019  * 02111-1307, USA.
00020  */
00021 
00022 // $Id: src_2heuristics_2values_2Random_8h-source.html,v 1.1 2005/05/25 12:37:18 tudor Exp $
00023 
00024 #ifndef _CSP_HEURISTICS_VALUE_Random_H
00025 #define _CSP_HEURISTICS_VALUE_Random_H
00026 
00027 
00028 #include "../../caches/RandomIndexes.h"
00029 
00030 
00031 CSP_NAMESPACE_BEGIN(csp);
00032 CSP_NAMESPACE_BEGIN(heuristics);
00033 CSP_NAMESPACE_BEGIN(values);
00034 
00035 
00036 class RandomIndexLT :
00037     public StrictWeakValueOrdering
00038 {
00039   public:
00040     RandomIndexLT(caches::RandomIndexes& randomIndexes) :
00041         m_randomIndexes(randomIndexes) {}
00042 
00043     bool operator()(const Value* value0, const Value* value1)
00044     {
00045         return
00046             m_randomIndexes.randomIndex(*value0) <
00047             m_randomIndexes.randomIndex(*value1);
00048     }
00049 
00050   private:
00051     caches::RandomIndexes& m_randomIndexes;
00052 };
00053 
00054 
00055 class RandomIndexGT :
00056     public StrictWeakValueOrdering
00057 {
00058   public:
00059     RandomIndexGT(caches::RandomIndexes& randomIndexes) :
00060         m_randomIndexes(randomIndexes) {}
00061 
00062     bool operator()(const Value* value0, const Value* value1)
00063     {
00064         return
00065             m_randomIndexes.randomIndex(*value0) >
00066             m_randomIndexes.randomIndex(*value1);
00067     }
00068 
00069   private:
00070     caches::RandomIndexes& m_randomIndexes;
00071 };
00072 
00073 
00074 class RandomIndexEQ :
00075     public StrictWeakValueOrdering
00076 {
00077   public:
00078     RandomIndexEQ(caches::RandomIndexes& randomIndexes) :
00079         m_randomIndexes(randomIndexes),
00080         m_previousValue0(0),
00081         m_previousValue1(0),
00082         m_previousRandomIndex0(0),
00083         m_previousRandomIndex1(0) {}
00084 
00085     bool operator()(const Value* value0, const Value* value1);
00086 
00087     void reset()
00088     {
00089         m_previousValue0 = 0;
00090         m_previousValue1 = 0;
00091         m_previousRandomIndex0 = 0;
00092         m_previousRandomIndex1 = 0;
00093     }
00094 
00095   private:
00096     caches::RandomIndexes& m_randomIndexes;
00097 
00098     const Value* m_previousValue0;
00099     const Value* m_previousValue1;
00100 
00101     size_t m_previousRandomIndex0;
00102     size_t m_previousRandomIndex1;
00103 };
00104 
00105 
00110 class CSP_API Random :
00111     public ValueOH
00112 {
00113   public:
00126     Random(
00127         Decomposition& decomposition,
00128         Randomizer& randomizer,
00129         const vector<pair<double, double> >& intervals,
00130         double quality = 1,
00131         bool analysis = false);
00132 
00140     virtual void dynamicInit(Variable& variable, Domain& selectable);
00141 
00148     virtual void dynamicDone(Variable& variable);
00149 
00157     virtual void select(
00158         Domain& selectable,
00159         Domain& selected,
00160         Variable& variable);
00161 
00170     virtual bool better(const Value& value0, const Value& value1);
00171 
00179     virtual bool equal(const Value& value0, const Value& value1);
00180 
00185     virtual void sort(
00186         Domain& original,
00187         Domain& sorted,
00188         Variable& variable);
00189 
00201     virtual long double score(Variable& variable, const Value& value);
00202 
00203   private:
00205     Random(const Random&);
00206 
00208     Random& operator=(const Random&);
00209 
00212     RandomIndexLT m_compareLT;
00213 
00216     RandomIndexGT m_compareGT;
00217 
00219     RandomIndexEQ m_compareEQ;
00220 
00222     Randomizer& m_randomizer;
00223 
00225     caches::RandomIndexes m_randomIndexes;
00226 };
00227 
00228 
00229 CSP_NAMESPACE_END(values);
00230 CSP_NAMESPACE_END(heuristics);
00231 CSP_NAMESPACE_END(csp);
00232 
00233 
00234 #endif // _CSP_HEURISTICS_VALUE_Random_H
00235 
00236 // Local Variables:
00237 // mode: C++
00238 // End:

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