Generated on Tue Apr 18 10:21:37 2017 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  *  Last modified:
00010  *     $Date: 2017-03-10 16:52:37 +0100 (Fri, 10 Mar 2017) $ by $Author: schulte $
00011  *     $Revision: 15569 $
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   ValSelMin<View>::ValSelMin(Space& home, const ValBranch<Var>& vb)
00043     : ValSel<View,int>(home,vb) {}
00044   template<class View>
00045   forceinline
00046   ValSelMin<View>::ValSelMin(Space& home, bool shared, ValSelMin& vs)
00047     : ValSel<View,int>(home,shared,vs) {}
00048   template<class View>
00049   forceinline int
00050   ValSelMin<View>::val(const Space&, View x, int) {
00051     return x.min();
00052   }
00053 
00054   template<class View>
00055   forceinline
00056   ValSelMax<View>::ValSelMax(Space& home, const ValBranch<Var>& vb)
00057     : ValSel<View,int>(home,vb) {}
00058   template<class View>
00059   forceinline
00060   ValSelMax<View>::ValSelMax(Space& home, bool shared, ValSelMax& vs)
00061     : ValSel<View,int>(home,shared,vs) {}
00062   template<class View>
00063   forceinline int
00064   ValSelMax<View>::val(const Space&, View x, int) {
00065     return x.max();
00066   }
00067 
00068   template<class View>
00069   forceinline
00070   ValSelMed<View>::ValSelMed(Space& home, const ValBranch<Var>& vb)
00071     : ValSel<View,int>(home,vb) {}
00072   template<class View>
00073   forceinline
00074   ValSelMed<View>::ValSelMed(Space& home, bool shared, ValSelMed& vs)
00075     : ValSel<View,int>(home,shared,vs) {}
00076   template<class View>
00077   forceinline int
00078   ValSelMed<View>::val(const Space&, View x, int) {
00079     return x.med();
00080   }
00081 
00082   template<class View>
00083   forceinline
00084   ValSelAvg<View>::ValSelAvg(Space& home, const ValBranch<Var>& vb)
00085     : ValSel<View,int>(home,vb) {}
00086   template<class View>
00087   forceinline
00088   ValSelAvg<View>::ValSelAvg(Space& home, bool shared, ValSelAvg& vs)
00089     : ValSel<View,int>(home,shared,vs) {}
00090   template<class View>
00091   forceinline int
00092   ValSelAvg<View>::val(const Space&, View x, int) {
00093     return (x.width() == 2U) ? x.min() : ((x.min()+x.max()) / 2);
00094   }
00095 
00096   template<class View>
00097   forceinline
00098   ValSelRnd<View>::ValSelRnd(Space& home, const ValBranch<Var>& vb)
00099     : ValSel<View,int>(home,vb), r(vb.rnd()) {}
00100   template<class View>
00101   forceinline
00102   ValSelRnd<View>::ValSelRnd(Space& home, bool shared, ValSelRnd& vs)
00103     : ValSel<View,int>(home,shared,vs) {
00104     r.update(home,shared,vs.r);
00105   }
00106   template<class View>
00107   forceinline int
00108   ValSelRnd<View>::val(const Space&, View x, int) {
00109     unsigned int p = r(x.size());
00110     for (ViewRanges<View> i(x); i(); ++i) {
00111       if (i.width() > p)
00112         return i.min() + static_cast<int>(p);
00113       p -= i.width();
00114     }
00115     GECODE_NEVER;
00116     return 0;
00117   }
00118   template<class View>
00119   forceinline bool
00120   ValSelRnd<View>::notice(void) const {
00121     return true;
00122   }
00123   template<class View>
00124   forceinline void
00125   ValSelRnd<View>::dispose(Space&) {
00126     r.~Rnd();
00127   }
00128 
00129   forceinline
00130   ValSelRangeMin::ValSelRangeMin(Space& home, const ValBranch<IntVar>& vb)
00131     : ValSel<IntView,int>(home,vb) {}
00132   forceinline
00133   ValSelRangeMin::ValSelRangeMin(Space& home, bool shared, ValSelRangeMin& vs)
00134     : ValSel<IntView,int>(home,shared,vs) {}
00135   forceinline int
00136   ValSelRangeMin::val(const Space&, IntView x, int) {
00137     if (x.range()) {
00138       return (x.width() == 2) ? x.min() : (x.min() + (x.max()-x.min())/2);
00139     } else {
00140       ViewRanges<View> r(x);
00141       return r.max();
00142     }
00143   }
00144 
00145   forceinline
00146   ValSelRangeMax::ValSelRangeMax(Space& home, const ValBranch<IntVar>& vb)
00147     : ValSel<IntView,int>(home,vb) {}
00148   forceinline
00149   ValSelRangeMax::ValSelRangeMax(Space& home, bool shared, ValSelRangeMax& vs)
00150     : ValSel<IntView,int>(home,shared,vs) {}
00151   forceinline int
00152   ValSelRangeMax::val(const Space&, IntView x, int) {
00153     if (x.range()) {
00154       return (x.width() == 2) ? x.max() : (x.max() - (x.max()-x.min())/2);
00155     } else {
00156       int min;
00157       ViewRanges<IntView> r(x);
00158       do {
00159         min = r.min(); ++r;
00160       } while (r());
00161       return min;
00162     }
00163   }
00164 
00165 }}}
00166 
00167 // STATISTICS: int-branch
00168