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