Generated on Fri Oct 19 11:24:54 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  *  Contributing authors:
00007  *     Gabor Szokoli <szokoli@gecode.org>
00008  *     Guido Tack <tack@gecode.org>
00009  *
00010  *  Copyright:
00011  *     Christian Schulte, 2012
00012  *     Gabor Szokoli, 2004
00013  *     Guido Tack, 2004
00014  *
00015  *  This file is part of Gecode, the generic constraint
00016  *  development environment:
00017  *     http://www.gecode.org
00018  *
00019  *  Permission is hereby granted, free of charge, to any person obtaining
00020  *  a copy of this software and associated documentation files (the
00021  *  "Software"), to deal in the Software without restriction, including
00022  *  without limitation the rights to use, copy, modify, merge, publish,
00023  *  distribute, sublicense, and/or sell copies of the Software, and to
00024  *  permit persons to whom the Software is furnished to do so, subject to
00025  *  the following conditions:
00026  *
00027  *  The above copyright notice and this permission notice shall be
00028  *  included in all copies or substantial portions of the Software.
00029  *
00030  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00031  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00032  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00033  *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00034  *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00035  *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00036  *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00037  *
00038  */
00039 
00040 namespace Gecode { namespace Set { namespace Branch {
00041 
00042   forceinline
00043   ValSelMin::ValSelMin(Space& home, const ValBranch<Var>& vb)
00044     : ValSel<SetView,int>(home,vb) {}
00045   forceinline
00046   ValSelMin::ValSelMin(Space& home, ValSelMin& vs)
00047     : ValSel<SetView,int>(home,vs) {}
00048   forceinline int
00049   ValSelMin::val(const Space&, SetView x, int) {
00050     UnknownRanges<SetView> u(x);
00051     return u.min();
00052   }
00053 
00054   forceinline
00055   ValSelMax::ValSelMax(Space& home, const ValBranch<Var>& vb)
00056     : ValSel<SetView,int>(home,vb) {}
00057   forceinline
00058   ValSelMax::ValSelMax(Space& home, ValSelMax& vs)
00059     : ValSel<SetView,int>(home,vs) {}
00060   forceinline int
00061   ValSelMax::val(const Space&, SetView x, int) {
00062     int max = 0;
00063     for (UnknownRanges<SetView> u(x); u(); ++u)
00064       max = u.max();
00065     return max;
00066   }
00067 
00068   forceinline
00069   ValSelMed::ValSelMed(Space& home, const ValBranch<Var>& vb)
00070     : ValSel<SetView,int>(home,vb) {}
00071   forceinline
00072   ValSelMed::ValSelMed(Space& home, ValSelMed& vs)
00073     : ValSel<SetView,int>(home,vs) {}
00074   forceinline int
00075   ValSelMed::val(const Space&, SetView x, int) {
00076     UnknownRanges<SetView> u1(x);
00077     unsigned int i = Iter::Ranges::size(u1) / 2;
00078     UnknownRanges<SetView> u2(x);
00079     int med = (u2.min()+u2.max()) / 2;
00080     ++u2;
00081     if (!u2()) {
00082       return med;
00083     }
00084     UnknownRanges<SetView> u3(x);
00085     while (i >= u3.width()) {
00086       i -= u3.width();
00087       ++u3;
00088     }
00089     return u3.min() + static_cast<int>(i);
00090   }
00091 
00092   forceinline
00093   ValSelRnd::ValSelRnd(Space& home, const ValBranch<Var>& vb)
00094     : ValSel<SetView,int>(home,vb), r(vb.rnd()) {}
00095   forceinline
00096   ValSelRnd::ValSelRnd(Space& home, ValSelRnd& vs)
00097     : ValSel<SetView,int>(home,vs), r(vs.r) {
00098   }
00099   forceinline int
00100   ValSelRnd::val(const Space&, SetView x, int) {
00101     UnknownRanges<SetView> u(x);
00102     unsigned int p = r(Iter::Ranges::size(u));
00103     for (UnknownRanges<SetView> i(x); i(); ++i) {
00104       if (i.width() > p)
00105         return i.min() + static_cast<int>(p);
00106       p -= i.width();
00107     }
00108     GECODE_NEVER;
00109     return 0;
00110   }
00111   forceinline bool
00112   ValSelRnd::notice(void) const {
00113     return true;
00114   }
00115   forceinline void
00116   ValSelRnd::dispose(Space&) {
00117     r.~Rnd();
00118   }
00119 
00120 }}}
00121 
00122 // STATISTICS: set-branch
00123