this repo has no description
1/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */ 2/* 3 * Main authors: 4 * Denys Duchier <denys.duchier@univ-orleans.fr> 5 * 6 * Copyright: 7 * Denys Duchier, 2011 8 * 9 * This file is part of Gecode, the generic constraint 10 * development environment: 11 * http://www.gecode.org 12 * 13 * Permission is hereby granted, free of charge, to any person obtaining 14 * a copy of this software and associated documentation files (the 15 * "Software"), to deal in the Software without restriction, including 16 * without limitation the rights to use, copy, modify, merge, publish, 17 * distribute, sublicense, and/or sell copies of the Software, and to 18 * permit persons to whom the Software is furnished to do so, subject to 19 * the following conditions: 20 * 21 * The above copyright notice and this permission notice shall be 22 * included in all copies or substantial portions of the Software. 23 * 24 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 25 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 26 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 27 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 28 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 29 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 30 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 31 * 32 */ 33 34namespace Gecode { namespace Set { namespace Channel { 35 36 template <typename View> 37 forceinline 38 ChannelSet<View>::ChannelSet(Home home, 39 ViewArray<CachedView<View> >& xs0, 40 ViewArray<CachedView<View> >& ys0) 41 : Propagator(home), xs(xs0), ys(ys0) { 42 for (int i=xs.size(); i--;) 43 xs[i].initCache(home,IntSet::empty,IntSet(0,ys.size()-1)); 44 for (int i=ys.size(); i--;) 45 ys[i].initCache(home,IntSet::empty,IntSet(0,xs.size()-1)); 46 xs.subscribe(home,*this, PC_SET_ANY); 47 ys.subscribe(home,*this, PC_SET_ANY); 48 } 49 50 template <typename View> 51 forceinline 52 ChannelSet<View>::ChannelSet(Space& home, ChannelSet& p) 53 : Propagator(home, p) { 54 xs.update(home, p.xs); 55 ys.update(home, p.ys); 56 } 57 58 template <typename View> 59 forceinline ExecStatus 60 ChannelSet<View>::post(Home home, 61 ViewArray<CachedView<View> >& xs, 62 ViewArray<CachedView<View> >& ys) { 63 int xssize = xs.size(); 64 for (int i=ys.size(); i--;) { 65 GECODE_ME_CHECK(ys[i].exclude(home, xssize, Limits::max)); 66 GECODE_ME_CHECK(ys[i].exclude(home, Limits::min, -1)); 67 } 68 int yssize = ys.size(); 69 for (int i=xs.size(); i--;) { 70 GECODE_ME_CHECK(xs[i].exclude(home, yssize, Limits::max)); 71 GECODE_ME_CHECK(xs[i].exclude(home, Limits::min, -1)); 72 } 73 (void) new (home) ChannelSet(home,xs,ys); 74 return ES_OK; 75 } 76 77 template <typename View> 78 PropCost 79 ChannelSet<View>::cost(const Space&, const ModEventDelta&) const { 80 return PropCost::quadratic(PropCost::HI, xs.size()+ys.size()); 81 } 82 83 template <typename View> 84 void 85 ChannelSet<View>::reschedule(Space& home) { 86 xs.reschedule(home,*this, PC_SET_ANY); 87 ys.reschedule(home,*this, PC_SET_ANY); 88 } 89 90 template <typename View> 91 forceinline size_t 92 ChannelSet<View>::dispose(Space& home) { 93 xs.cancel(home, *this, PC_SET_ANY); 94 ys.cancel(home, *this, PC_SET_ANY); 95 (void) Propagator::dispose(home); 96 return sizeof(*this); 97 } 98 99 template <typename View> 100 Actor* 101 ChannelSet<View>::copy(Space& home) { 102 return new (home) ChannelSet(home,*this); 103 } 104 105 template <typename View> 106 ExecStatus 107 ChannelSet<View>::propagate(Space& home, const ModEventDelta&) { 108 int assigned = 0; 109 bool again = true; 110 while (again) { 111 assigned = 0; 112 again = false; 113 for (int i=xs.size(); i--;) { 114 if (xs[i].assigned()) 115 ++assigned; 116 if (xs[i].glbModified()) { 117 GlbDiffRanges<View> xilb(xs[i]); 118 Iter::Ranges::ToValues<GlbDiffRanges<View> > dv(xilb); 119 for (;dv();++dv) 120 GECODE_ME_CHECK(ys[dv.val()].include(home,i)); 121 xs[i].cacheGlb(home); 122 again = true; 123 } 124 if (xs[i].lubModified()) { 125 LubDiffRanges<View> xiub(xs[i]); 126 Iter::Ranges::ToValues<LubDiffRanges<View> > dv(xiub); 127 for (;dv();++dv) 128 GECODE_ME_CHECK(ys[dv.val()].exclude(home,i)); 129 xs[i].cacheLub(home); 130 again = true; 131 } 132 } 133 for (int i=ys.size(); i--;) { 134 if (ys[i].assigned()) 135 ++assigned; 136 if (ys[i].glbModified()) { 137 GlbDiffRanges<View> yilb(ys[i]); 138 Iter::Ranges::ToValues<GlbDiffRanges<View> > dv(yilb); 139 for (;dv();++dv) 140 GECODE_ME_CHECK(xs[dv.val()].include(home,i)); 141 ys[i].cacheGlb(home); 142 again = true; 143 } 144 if (ys[i].lubModified()) { 145 LubDiffRanges<View> yiub(ys[i]); 146 Iter::Ranges::ToValues<LubDiffRanges<View> > dv(yiub); 147 for (;dv();++dv) 148 GECODE_ME_CHECK(xs[dv.val()].exclude(home,i)); 149 ys[i].cacheLub(home); 150 again = true; 151 } 152 } 153 } 154 155 return (assigned == xs.size()+ys.size()) ? home.ES_SUBSUMED(*this) : ES_FIX; 156 } 157 158}}} 159 160// STATISTICS: set-prop