this repo has no description
1/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */ 2/* 3 * Main authors: 4 * Christian Schulte <schulte@gecode.org> 5 * 6 * Contributing authors: 7 * Gabor Szokoli <szokoli@gecode.org> 8 * Guido Tack <tack@gecode.org> 9 * 10 * Copyright: 11 * Christian Schulte, 2012 12 * Gabor Szokoli, 2004 13 * Guido Tack, 2004 14 * 15 * This file is part of Gecode, the generic constraint 16 * development environment: 17 * http://www.gecode.org 18 * 19 * Permission is hereby granted, free of charge, to any person obtaining 20 * a copy of this software and associated documentation files (the 21 * "Software"), to deal in the Software without restriction, including 22 * without limitation the rights to use, copy, modify, merge, publish, 23 * distribute, sublicense, and/or sell copies of the Software, and to 24 * permit persons to whom the Software is furnished to do so, subject to 25 * the following conditions: 26 * 27 * The above copyright notice and this permission notice shall be 28 * included in all copies or substantial portions of the Software. 29 * 30 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 31 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 32 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 33 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 34 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 35 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 36 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 37 * 38 */ 39 40namespace Gecode { namespace Set { namespace Branch { 41 42 forceinline 43 ValSelMin::ValSelMin(Space& home, const ValBranch<Var>& vb) 44 : ValSel<SetView,int>(home,vb) {} 45 forceinline 46 ValSelMin::ValSelMin(Space& home, ValSelMin& vs) 47 : ValSel<SetView,int>(home,vs) {} 48 forceinline int 49 ValSelMin::val(const Space&, SetView x, int) { 50 UnknownRanges<SetView> u(x); 51 return u.min(); 52 } 53 54 forceinline 55 ValSelMax::ValSelMax(Space& home, const ValBranch<Var>& vb) 56 : ValSel<SetView,int>(home,vb) {} 57 forceinline 58 ValSelMax::ValSelMax(Space& home, ValSelMax& vs) 59 : ValSel<SetView,int>(home,vs) {} 60 forceinline int 61 ValSelMax::val(const Space&, SetView x, int) { 62 int max = 0; 63 for (UnknownRanges<SetView> u(x); u(); ++u) 64 max = u.max(); 65 return max; 66 } 67 68 forceinline 69 ValSelMed::ValSelMed(Space& home, const ValBranch<Var>& vb) 70 : ValSel<SetView,int>(home,vb) {} 71 forceinline 72 ValSelMed::ValSelMed(Space& home, ValSelMed& vs) 73 : ValSel<SetView,int>(home,vs) {} 74 forceinline int 75 ValSelMed::val(const Space&, SetView x, int) { 76 UnknownRanges<SetView> u1(x); 77 unsigned int i = Iter::Ranges::size(u1) / 2; 78 UnknownRanges<SetView> u2(x); 79 int med = (u2.min()+u2.max()) / 2; 80 ++u2; 81 if (!u2()) { 82 return med; 83 } 84 UnknownRanges<SetView> u3(x); 85 while (i >= u3.width()) { 86 i -= u3.width(); 87 ++u3; 88 } 89 return u3.min() + static_cast<int>(i); 90 } 91 92 forceinline 93 ValSelRnd::ValSelRnd(Space& home, const ValBranch<Var>& vb) 94 : ValSel<SetView,int>(home,vb), r(vb.rnd()) {} 95 forceinline 96 ValSelRnd::ValSelRnd(Space& home, ValSelRnd& vs) 97 : ValSel<SetView,int>(home,vs), r(vs.r) { 98 } 99 forceinline int 100 ValSelRnd::val(const Space&, SetView x, int) { 101 UnknownRanges<SetView> u(x); 102 unsigned int p = r(Iter::Ranges::size(u)); 103 for (UnknownRanges<SetView> i(x); i(); ++i) { 104 if (i.width() > p) 105 return i.min() + static_cast<int>(p); 106 p -= i.width(); 107 } 108 GECODE_NEVER; 109 return 0; 110 } 111 forceinline bool 112 ValSelRnd::notice(void) const { 113 return true; 114 } 115 forceinline void 116 ValSelRnd::dispose(Space&) { 117 r.~Rnd(); 118 } 119 120}}} 121 122// STATISTICS: set-branch 123