Generated on Tue May 22 09:39:45 2018 for Gecode by doxygen 1.6.3

val-sel.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, 2012
00008  *
00009  *  This file is part of Gecode, the generic constraint
00010  *  development environment:
00011  *     http://www.gecode.org
00012  *
00013  *  Permission is hereby granted, free of charge, to any person obtaining
00014  *  a copy of this software and associated documentation files (the
00015  *  "Software"), to deal in the Software without restriction, including
00016  *  without limitation the rights to use, copy, modify, merge, publish,
00017  *  distribute, sublicense, and/or sell copies of the Software, and to
00018  *  permit persons to whom the Software is furnished to do so, subject to
00019  *  the following conditions:
00020  *
00021  *  The above copyright notice and this permission notice shall be
00022  *  included in all copies or substantial portions of the Software.
00023  *
00024  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00025  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00026  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00027  *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00028  *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00029  *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00030  *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00031  *
00032  */
00033 
00034 namespace Gecode { namespace Int { namespace Branch {
00035 
00036   template<class View>
00037   forceinline
00038   ValSelMin<View>::ValSelMin(Space& home, const ValBranch<Var>& vb)
00039     : ValSel<View,int>(home,vb) {}
00040   template<class View>
00041   forceinline
00042   ValSelMin<View>::ValSelMin(Space& home, ValSelMin& vs)
00043     : ValSel<View,int>(home,vs) {}
00044   template<class View>
00045   forceinline int
00046   ValSelMin<View>::val(const Space&, View x, int) {
00047     return x.min();
00048   }
00049 
00050   template<class View>
00051   forceinline
00052   ValSelMax<View>::ValSelMax(Space& home, const ValBranch<Var>& vb)
00053     : ValSel<View,int>(home,vb) {}
00054   template<class View>
00055   forceinline
00056   ValSelMax<View>::ValSelMax(Space& home, ValSelMax& vs)
00057     : ValSel<View,int>(home,vs) {}
00058   template<class View>
00059   forceinline int
00060   ValSelMax<View>::val(const Space&, View x, int) {
00061     return x.max();
00062   }
00063 
00064   template<class View>
00065   forceinline
00066   ValSelMed<View>::ValSelMed(Space& home, const ValBranch<Var>& vb)
00067     : ValSel<View,int>(home,vb) {}
00068   template<class View>
00069   forceinline
00070   ValSelMed<View>::ValSelMed(Space& home, ValSelMed& vs)
00071     : ValSel<View,int>(home,vs) {}
00072   template<class View>
00073   forceinline int
00074   ValSelMed<View>::val(const Space&, View x, int) {
00075     return x.med();
00076   }
00077 
00078   template<class View>
00079   forceinline
00080   ValSelAvg<View>::ValSelAvg(Space& home, const ValBranch<Var>& vb)
00081     : ValSel<View,int>(home,vb) {}
00082   template<class View>
00083   forceinline
00084   ValSelAvg<View>::ValSelAvg(Space& home, ValSelAvg& vs)
00085     : ValSel<View,int>(home,vs) {}
00086   template<class View>
00087   forceinline int
00088   ValSelAvg<View>::val(const Space&, View x, int) {
00089     return (x.width() == 2U) ? x.min() : ((x.min()+x.max()) / 2);
00090   }
00091 
00092   template<class View>
00093   forceinline
00094   ValSelRnd<View>::ValSelRnd(Space& home, const ValBranch<Var>& vb)
00095     : ValSel<View,int>(home,vb), r(vb.rnd()) {}
00096   template<class View>
00097   forceinline
00098   ValSelRnd<View>::ValSelRnd(Space& home, ValSelRnd& vs)
00099     : ValSel<View,int>(home,vs), r(vs.r) {
00100   }
00101   template<class View>
00102   forceinline int
00103   ValSelRnd<View>::val(const Space&, View x, int) {
00104     unsigned int p = r(x.size());
00105     for (ViewRanges<View> i(x); i(); ++i) {
00106       if (i.width() > p)
00107         return i.min() + static_cast<int>(p);
00108       p -= i.width();
00109     }
00110     GECODE_NEVER;
00111     return 0;
00112   }
00113   template<class View>
00114   forceinline bool
00115   ValSelRnd<View>::notice(void) const {
00116     return true;
00117   }
00118   template<class View>
00119   forceinline void
00120   ValSelRnd<View>::dispose(Space&) {
00121     r.~Rnd();
00122   }
00123 
00124   forceinline
00125   ValSelRangeMin::ValSelRangeMin(Space& home, const ValBranch<IntVar>& vb)
00126     : ValSel<IntView,int>(home,vb) {}
00127   forceinline
00128   ValSelRangeMin::ValSelRangeMin(Space& home, ValSelRangeMin& vs)
00129     : ValSel<IntView,int>(home,vs) {}
00130   forceinline int
00131   ValSelRangeMin::val(const Space&, IntView x, int) {
00132     if (x.range()) {
00133       return (x.width() == 2) ? x.min() : (x.min() + (x.max()-x.min())/2);
00134     } else {
00135       ViewRanges<View> r(x);
00136       return r.max();
00137     }
00138   }
00139 
00140   forceinline
00141   ValSelRangeMax::ValSelRangeMax(Space& home, const ValBranch<IntVar>& vb)
00142     : ValSel<IntView,int>(home,vb) {}
00143   forceinline
00144   ValSelRangeMax::ValSelRangeMax(Space& home, ValSelRangeMax& vs)
00145     : ValSel<IntView,int>(home,vs) {}
00146   forceinline int
00147   ValSelRangeMax::val(const Space&, IntView x, int) {
00148     if (x.range()) {
00149       return (x.width() == 2) ? x.max() : (x.max() - (x.max()-x.min())/2);
00150     } else {
00151       int min;
00152       ViewRanges<IntView> r(x);
00153       do {
00154         min = r.min(); ++r;
00155       } while (r());
00156       return min;
00157     }
00158   }
00159 
00160 }}}
00161 
00162 // STATISTICS: int-branch
00163