Generated on Thu Apr 11 13:58:57 2019 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
00039   (Space& home, const ValBranch<ValSelMin<View>::Var>& vb)
00040     : ValSel<View,int>(home,vb) {}
00041   template<class View>
00042   forceinline
00043   ValSelMin<View>::ValSelMin(Space& home, ValSelMin& vs)
00044     : ValSel<View,int>(home,vs) {}
00045   template<class View>
00046   forceinline int
00047   ValSelMin<View>::val(const Space&, View x, int) {
00048     return x.min();
00049   }
00050 
00051   template<class View>
00052   forceinline
00053   ValSelMax<View>::ValSelMax
00054   (Space& home, const ValBranch<ValSelMax<View>::Var>& vb)
00055     : ValSel<View,int>(home,vb) {}
00056   template<class View>
00057   forceinline
00058   ValSelMax<View>::ValSelMax(Space& home, ValSelMax& vs)
00059     : ValSel<View,int>(home,vs) {}
00060   template<class View>
00061   forceinline int
00062   ValSelMax<View>::val(const Space&, View x, int) {
00063     return x.max();
00064   }
00065 
00066   template<class View>
00067   forceinline
00068   ValSelMed<View>::ValSelMed
00069   (Space& home, const ValBranch<ValSelMed<View>::Var>& vb)
00070     : ValSel<View,int>(home,vb) {}
00071   template<class View>
00072   forceinline
00073   ValSelMed<View>::ValSelMed(Space& home, ValSelMed& vs)
00074     : ValSel<View,int>(home,vs) {}
00075   template<class View>
00076   forceinline int
00077   ValSelMed<View>::val(const Space&, View x, int) {
00078     return x.med();
00079   }
00080 
00081   template<class View>
00082   forceinline
00083   ValSelAvg<View>::ValSelAvg
00084   (Space& home, const ValBranch<ValSelAvg<View>::Var>& vb)
00085     : ValSel<View,int>(home,vb) {}
00086   template<class View>
00087   forceinline
00088   ValSelAvg<View>::ValSelAvg(Space& home, ValSelAvg& vs)
00089     : ValSel<View,int>(home,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
00099   (Space& home, const ValBranch<ValSelRnd<View>::Var>& vb)
00100     : ValSel<View,int>(home,vb), r(vb.rnd()) {}
00101   template<class View>
00102   forceinline
00103   ValSelRnd<View>::ValSelRnd(Space& home, ValSelRnd& vs)
00104     : ValSel<View,int>(home,vs), r(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
00131   (Space& home, const ValBranch<IntVar>& vb)
00132     : ValSel<IntView,int>(home,vb) {}
00133   forceinline
00134   ValSelRangeMin::ValSelRangeMin(Space& home, ValSelRangeMin& vs)
00135     : ValSel<IntView,int>(home,vs) {}
00136   forceinline int
00137   ValSelRangeMin::val(const Space&, IntView x, int) {
00138     if (x.range()) {
00139       return (x.width() == 2) ? x.min() : (x.min() + (x.max()-x.min())/2);
00140     } else {
00141       ViewRanges<View> r(x);
00142       return r.max();
00143     }
00144   }
00145 
00146   forceinline
00147   ValSelRangeMax::ValSelRangeMax(Space& home, const ValBranch<IntVar>& vb)
00148     : ValSel<IntView,int>(home,vb) {}
00149   forceinline
00150   ValSelRangeMax::ValSelRangeMax(Space& home, ValSelRangeMax& vs)
00151     : ValSel<IntView,int>(home,vs) {}
00152   forceinline int
00153   ValSelRangeMax::val(const Space&, IntView x, int) {
00154     if (x.range()) {
00155       return (x.width() == 2) ? x.max() : (x.max() - (x.max()-x.min())/2);
00156     } else {
00157       int min;
00158       ViewRanges<IntView> r(x);
00159       do {
00160         min = r.min(); ++r;
00161       } while (r());
00162       return min;
00163     }
00164   }
00165 
00166 }}}
00167 
00168 // STATISTICS: int-branch
00169