this repo has no description
at develop 5.4 kB view raw
1/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */ 2/* 3 * Main authors: 4 * Guido Tack <tack@gecode.org> 5 * Christian Schulte <schulte@gecode.org> 6 * 7 * Contributing authors: 8 * Gabor Szokoli <szokoli@gecode.org> 9 * 10 * Copyright: 11 * Guido Tack, 2004 12 * Christian Schulte, 2004 13 * Gabor Szokoli, 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 RelOp { 41 42 template<class View0, class View1, class View2> 43 forceinline 44 SuperOfInter<View0,View1,View2>::SuperOfInter 45 (Home home, View0 y0, View1 y1, View2 y2) 46 : MixTernaryPropagator<View0,PC_SET_ANY,View1,PC_SET_ANY, 47 View2,PC_SET_CLUB>(home,y0,y1,y2) {} 48 49 template<class View0, class View1, class View2> 50 forceinline 51 SuperOfInter<View0,View1,View2>::SuperOfInter 52 (Space& home, SuperOfInter<View0,View1,View2>& p) 53 : MixTernaryPropagator<View0,PC_SET_ANY,View1,PC_SET_ANY, 54 View2,PC_SET_CLUB>(home,p) {} 55 56 template<class View0, class View1, class View2> 57 ExecStatus 58 SuperOfInter<View0,View1,View2>::post(Home home, 59 View0 x0, View1 x1, View2 x2) { 60 (void) new (home) SuperOfInter<View0,View1,View2>(home, x0, x1, x2); 61 return ES_OK; 62 } 63 64 template<class View0, class View1, class View2> 65 Actor* 66 SuperOfInter<View0,View1,View2>::copy(Space& home) { 67 return new (home) SuperOfInter(home,*this); 68 } 69 70 template<class View0, class View1, class View2> 71 ExecStatus 72 SuperOfInter<View0,View1,View2>::propagate(Space& home, const ModEventDelta& med) { 73 74 bool allassigned = x0.assigned() && x1.assigned() && x2.assigned(); 75 76 ModEvent me0 = View0::me(med); 77 ModEvent me1 = View1::me(med); 78 ModEvent me2 = View2::me(med); 79 80 bool modified = false; 81 82 do { 83 // glb(x2) >= glb(x0) ^ glb(x1) 84 if ( modified || Rel::testSetEventLB(me0,me1)) { 85 GlbRanges<View0> lb0(x0); 86 GlbRanges<View1> lb1(x1); 87 Iter::Ranges::Inter<GlbRanges<View0>,GlbRanges<View1> > 88 is(lb0, lb1); 89 90 GECODE_ME_CHECK_MODIFIED(modified,x2.includeI(home,is)); 91 } 92 93 // lub(x0) -= glb(x1)-lub(x2) 94 // lub(x1) -= glb(x0)-lub(x2) 95 if ( modified || Rel::testSetEventAnyB(me0,me1,me2)) { 96 modified = false; 97 GlbRanges<View1> lb12(x1); 98 LubRanges<View2> ub22(x2); 99 Iter::Ranges::Diff<GlbRanges<View1>, LubRanges<View2> > 100 diff1(lb12, ub22); 101 102 GECODE_ME_CHECK_MODIFIED(modified, x0.excludeI(home,diff1)); 103 104 GlbRanges<View0> lb01(x0); 105 LubRanges<View2> ub23(x2); 106 Iter::Ranges::Diff<GlbRanges<View0>, LubRanges<View2> > 107 diff2(lb01, ub23); 108 109 GECODE_ME_CHECK_MODIFIED(modified, x1.excludeI(home,diff2)); 110 } else { 111 modified = false; 112 } 113 114 // Cardinality propagation 115 if ( modified || 116 Rel::testSetEventCard(me0,me1,me2) || 117 Rel::testSetEventUB(me0,me1) 118 ) { 119 120 LubRanges<View0> ub0(x0); 121 LubRanges<View1> ub1(x1); 122 Iter::Ranges::Union<LubRanges<View0>, LubRanges<View1> > u(ub0,ub1); 123 124 unsigned int m = Iter::Ranges::size(u); 125 126 if (m < x0.cardMin() + x1.cardMin()) { 127 GECODE_ME_CHECK_MODIFIED(modified, 128 x2.cardMin( home, 129 x0.cardMin()+x1.cardMin() - m ) ); 130 } 131 if (m + x2.cardMax() > x1.cardMin()) { 132 GECODE_ME_CHECK_MODIFIED(modified, 133 x0.cardMax( home, 134 m+x2.cardMax()-x1.cardMin() ) ); 135 } 136 if (m + x2.cardMax() > x0.cardMin()) { 137 GECODE_ME_CHECK_MODIFIED(modified, 138 x1.cardMax( home, 139 m+x2.cardMax()-x0.cardMin() ) ); 140 } 141 } 142 } while (modified); 143 144 145 if (shared(x0,x1,x2)) { 146 if (allassigned) { 147 return home.ES_SUBSUMED(*this); 148 } else { 149 return ES_NOFIX; 150 } 151 } else { 152 if (x0.assigned() + x1.assigned() + x2.assigned() >= 2) { 153 return home.ES_SUBSUMED(*this); 154 } else { 155 return ES_FIX; 156 } 157 } 158 159 } 160 161}}} 162 163// STATISTICS: set-prop