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 * Copyright: 7 * Christian Schulte, 2004 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 Int { namespace Dom { 35 36 template<class View, ReifyMode rm> 37 forceinline 38 ReIntSet<View,rm>::ReIntSet 39 (Home home, View x, const IntSet& s, BoolView b) 40 : ReUnaryPropagator<View,PC_INT_DOM,BoolView>(home,x,b), is(s) { 41 home.notice(*this,AP_DISPOSE); 42 } 43 44 template<class View, ReifyMode rm> 45 forceinline size_t 46 ReIntSet<View,rm>::dispose(Space& home) { 47 home.ignore(*this,AP_DISPOSE); 48 is.~IntSet(); 49 (void) ReUnaryPropagator<View,PC_INT_DOM,BoolView>::dispose(home); 50 return sizeof(*this); 51 } 52 53 template<class View, ReifyMode rm> 54 ExecStatus 55 ReIntSet<View,rm>::post(Home home, View x, const IntSet& s, BoolView b) { 56 if (s.ranges() == 0) { 57 if (rm == RM_PMI) 58 return ES_OK; 59 GECODE_ME_CHECK(b.zero(home)); 60 } else if (s.ranges() == 1) { 61 return ReRange<View,rm>::post(home,x,s.min(),s.max(),b); 62 } else if (b.one()) { 63 if (rm == RM_PMI) 64 return ES_OK; 65 IntSetRanges i_is(s); 66 GECODE_ME_CHECK(x.inter_r(home,i_is,false)); 67 } else if (b.zero()) { 68 if (rm == RM_IMP) 69 return ES_OK; 70 IntSetRanges i_is(s); 71 GECODE_ME_CHECK(x.minus_r(home,i_is,false)); 72 } else { 73 (void) new (home) ReIntSet<View,rm>(home,x,s,b); 74 } 75 return ES_OK; 76 } 77 78 79 template<class View, ReifyMode rm> 80 forceinline 81 ReIntSet<View,rm>::ReIntSet(Space& home, ReIntSet& p) 82 : ReUnaryPropagator<View,PC_INT_DOM,BoolView>(home,p), is(p.is) { 83 } 84 85 template<class View, ReifyMode rm> 86 Actor* 87 ReIntSet<View,rm>::copy(Space& home) { 88 return new (home) ReIntSet(home,*this); 89 } 90 91 template<class View, ReifyMode rm> 92 ExecStatus 93 ReIntSet<View,rm>::propagate(Space& home, const ModEventDelta&) { 94 IntSetRanges i_is(is); 95 if (b.one()) { 96 if (rm != RM_PMI) 97 GECODE_ME_CHECK(x0.inter_r(home,i_is,false)); 98 return home.ES_SUBSUMED(*this); 99 } 100 if (b.zero()) { 101 if (rm != RM_IMP) 102 GECODE_ME_CHECK(x0.minus_r(home,i_is,false)); 103 return home.ES_SUBSUMED(*this); 104 } 105 106 { 107 ViewRanges<View> i_x(x0); 108 109 switch (Iter::Ranges::compare(i_x,i_is)) { 110 case Iter::Ranges::CS_SUBSET: 111 if (rm != RM_IMP) 112 GECODE_ME_CHECK(b.one_none(home)); 113 return home.ES_SUBSUMED(*this); 114 case Iter::Ranges::CS_DISJOINT: 115 if (rm != RM_PMI) 116 GECODE_ME_CHECK(b.zero_none(home)); 117 return home.ES_SUBSUMED(*this); 118 case Iter::Ranges::CS_NONE: 119 break; 120 default: GECODE_NEVER; 121 } 122 } 123 return ES_FIX; 124 } 125 126}}} 127 128// STATISTICS: int-prop 129