Generated on Mon Jul 6 18:09:05 2009 for Gecode by doxygen 1.5.9

select-val.hpp

Go to the documentation of this file.
00001 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
00002 /*
00003  *  Main authors:
00004  *     Christian Schulte <schulte@gecode.org>
00005  *
00006  *  Copyright:
00007  *     Christian Schulte, 2002
00008  *
00009  *  Last modified:
00010  *     $Date: 2009-05-14 00:24:31 +0200 (Thu, 14 May 2009) $ by $Author: tack $
00011  *     $Revision: 9095 $
00012  *
00013  *  This file is part of Gecode, the generic constraint
00014  *  development environment:
00015  *     http://www.gecode.org
00016  *
00017  *  Permission is hereby granted, free of charge, to any person obtaining
00018  *  a copy of this software and associated documentation files (the
00019  *  "Software"), to deal in the Software without restriction, including
00020  *  without limitation the rights to use, copy, modify, merge, publish,
00021  *  distribute, sublicense, and/or sell copies of the Software, and to
00022  *  permit persons to whom the Software is furnished to do so, subject to
00023  *  the following conditions:
00024  *
00025  *  The above copyright notice and this permission notice shall be
00026  *  included in all copies or substantial portions of the Software.
00027  *
00028  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00029  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00030  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00031  *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00032  *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00033  *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00034  *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00035  *
00036  */
00037 
00038 namespace Gecode { namespace Int { namespace Branch {
00039 
00040   template<class View>
00041   forceinline
00042   ValMin<View>::ValMin(void) {}
00043   template<class View>
00044   forceinline
00045   ValMin<View>::ValMin(Space& home, const ValBranchOptions& vbo)
00046     : ValSelBase<View,int>(home,vbo) {}
00047   template<class View>
00048   forceinline int
00049   ValMin<View>::val(Space&, View x) const {
00050     return x.min();
00051   }
00052   template<class View>
00053   forceinline ModEvent
00054   ValMin<View>::tell(Space& home, unsigned int a, View x, int n) {
00055     return (a == 0) ? x.eq(home,n) : x.gr(home,n);
00056   }
00057 
00058   template<class View>
00059   forceinline
00060   ValMed<View>::ValMed(void) {}
00061   template<class View>
00062   forceinline
00063   ValMed<View>::ValMed(Space& home, const ValBranchOptions& vbo)
00064     : ValSelBase<View,int>(home,vbo) {}
00065   template<class View>
00066   forceinline int
00067   ValMed<View>::val(Space&, View x) const {
00068     return x.med();
00069   }
00070   template<class View>
00071   forceinline ModEvent
00072   ValMed<View>::tell(Space& home, unsigned int a, View x, int n) {
00073     return (a == 0) ? x.eq(home,n) : x.nq(home,n);
00074   }
00075 
00076 
00077   template<class View>
00078   forceinline
00079   ValRnd<View>::ValRnd(void) {}
00080   template<class View>
00081   forceinline
00082   ValRnd<View>::ValRnd(Space&, const ValBranchOptions& vbo)
00083     : r(vbo.seed) {}
00084   template<class View>
00085   forceinline int
00086   ValRnd<View>::val(Space&, View x) {
00087     unsigned int p = r(x.size());
00088     for (ViewRanges<View> i(x); i(); ++i) {
00089       if (i.width() > p)
00090         return i.min() + static_cast<int>(p);
00091       p -= i.width();
00092     }
00093     GECODE_NEVER;
00094     return 0;
00095   }
00096   template<class View>
00097   forceinline ModEvent
00098   ValRnd<View>::tell(Space& home, unsigned int a, View x, int n) {
00099     return (a == 0) ? x.eq(home,n) : x.nq(home,n);
00100   }
00101   template<class View>
00102   forceinline Support::RandomGenerator
00103   ValRnd<View>::description(Space&) {
00104     return r;
00105   }
00106   template<class View>
00107   forceinline void
00108   ValRnd<View>::commit(Space&, const Support::RandomGenerator& d,
00109                        unsigned int) {
00110     r = d;
00111   }
00112   template<class View>
00113   forceinline void
00114   ValRnd<View>::update(Space&, bool, ValRnd<View>& vr) {
00115     r = vr.r;
00116   }
00117   template<class View>
00118   forceinline void
00119   ValRnd<View>::dispose(Space&) {}
00120 
00121 
00122   template<class View>
00123   forceinline
00124   ValSplitMin<View>::ValSplitMin(void) {}
00125   template<class View>
00126   forceinline
00127   ValSplitMin<View>::ValSplitMin(Space& home,
00128     const ValBranchOptions& vbo)
00129     : ValSelBase<View,int>(home,vbo) {}
00130   template<class View>
00131   forceinline int
00132   ValSplitMin<View>::val(Space&, View x) const {
00133     return (x.width() == 2) ? x.min() : ((x.min()+x.max()) / 2);
00134   }
00135   template<class View>
00136   forceinline ModEvent
00137   ValSplitMin<View>::tell(Space& home, unsigned int a, View x, int n) {
00138     return (a == 0) ? x.lq(home,n) : x.gr(home,n);
00139   }
00140 
00141 
00142   template<class View>
00143   forceinline
00144   ValZeroOne<View>::ValZeroOne(void) {}
00145   template<class View>
00146   forceinline
00147   ValZeroOne<View>::ValZeroOne(Space& home, const ValBranchOptions& vbo)
00148     : ValSelBase<View,NoValue>(home,vbo) {}
00149   template<class View>
00150   forceinline NoValue
00151   ValZeroOne<View>::val(Space&, View) const {
00152     NoValue n; return n;
00153   }
00154   template<class View>
00155   forceinline ModEvent
00156   ValZeroOne<View>::tell(Space& home, unsigned int a, View x, NoValue) {
00157     return (a == 0) ? x.zero(home) : x.one(home);
00158   }
00159 
00160 
00161   template<class View>
00162   forceinline
00163   AssignValMin<View>::AssignValMin(void) {}
00164   template<class View>
00165   forceinline
00166   AssignValMin<View>::AssignValMin(Space& home, const ValBranchOptions& vbo)
00167     : ValMin<View>(home,vbo) {}
00168 
00169 
00170   template<class View>
00171   forceinline
00172   AssignValMed<View>::AssignValMed(void) {}
00173   template<class View>
00174   forceinline
00175   AssignValMed<View>::AssignValMed(Space& home, const ValBranchOptions& vbo)
00176     : ValMed<View>(home,vbo) {}
00177 
00178 
00179   template<class View>
00180   forceinline
00181   AssignValRnd<View>::AssignValRnd(void) {}
00182   template<class View>
00183   forceinline
00184   AssignValRnd<View>::AssignValRnd(Space& home, const ValBranchOptions& vbo)
00185     : ValRnd<View>(home,vbo) {}
00186 
00187 
00188   template<class View>
00189   forceinline
00190   AssignValZero<View>::AssignValZero(void) {}
00191   template<class View>
00192   forceinline
00193   AssignValZero<View>::AssignValZero(Space& home,
00194                                      const ValBranchOptions& vbo)
00195     : ValZeroOne<View>(home,vbo) {}
00196 
00197 }}}
00198 
00199 // STATISTICS: int-branch
00200