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, 2009 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 Sequence { 35 36 /// Status of whether a view takes a value from a set 37 enum TakesStatus { 38 TS_NO, ///< Definitely not 39 TS_YES, ///< Definitely yes 40 TS_MAYBE ///< Maybe or maybe not 41 }; 42 43 /// Return whether view \a x takes value \a s 44 template<class View> 45 forceinline TakesStatus 46 takes(const View& x, int s) { 47 if (x.in(s)) 48 return x.assigned() ? TS_YES : TS_MAYBE; 49 else 50 return TS_NO; 51 } 52 /// Return whether view \a x takes value from \a s 53 template<class View> 54 forceinline TakesStatus 55 takes(const View& x, const IntSet& s) { 56 if ((x.max() < s.min()) || (x.min() > s.max())) 57 return TS_NO; 58 ViewRanges<View> ix(x); 59 IntSetRanges is(s); 60 switch (Iter::Ranges::compare(ix,is)) { 61 case Iter::Ranges::CS_SUBSET: return TS_YES; 62 case Iter::Ranges::CS_DISJOINT: return TS_NO; 63 case Iter::Ranges::CS_NONE: return TS_MAYBE; 64 default: GECODE_NEVER; 65 } 66 return TS_MAYBE; 67 } 68 69 /// Test whether all values of view \a x are included in \a s 70 template<class View> 71 forceinline bool 72 includes(const View& x, int s) { 73 return x.assigned() && x.in(s); 74 } 75 /// Test whether all values of view \a x are included in \a s 76 template<class View> 77 forceinline bool 78 includes(const View& x, const IntSet& s) { 79 if ((x.max() < s.min()) || (x.min() > s.max())) 80 return false; 81 ViewRanges<View> ix(x); 82 IntSetRanges is(s); 83 return Iter::Ranges::subset(ix,is); 84 } 85 86 /// Test whether all values of view \a x are excluded from \a s 87 template<class View> 88 forceinline bool 89 excludes(const View& x, int s) { 90 return !x.in(s); 91 } 92 /// Test whether all values of view \a x are excluded from \a s 93 template<class View> 94 forceinline bool 95 excludes(const View& x, const IntSet& s) { 96 if ((x.max() < s.min()) || (x.min() > s.max())) 97 return true; 98 ViewRanges<View> ix(x); 99 IntSetRanges is(s); 100 return Iter::Ranges::disjoint(ix,is); 101 } 102 103 /// Test whether no decision on inclusion or exclusion of values of view \a x in \a s can be made 104 template<class View> 105 forceinline bool 106 undecided(const View& x, int s) { 107 return !x.assigned() && x.in(s); 108 } 109 /// Test whether no decision on inclusion or exclusion of values of view \a x in \a s can be made 110 template<class View> 111 forceinline bool 112 undecided(const View& x, const IntSet& s) { 113 if ((x.max() < s.min()) || (x.min() > s.max())) 114 return false; 115 ViewRanges<View> ix(x); 116 IntSetRanges is(s); 117 return Iter::Ranges::compare(ix,is) == Iter::Ranges::CS_NONE; 118 } 119 120 /// Prune view \a x to only include values from \a s 121 template<class View> 122 forceinline ModEvent 123 include(Space& home, View& x, int s) { 124 return x.eq(home,s); 125 } 126 /// Prune view \a x to only include values from \a s 127 template<class View> 128 forceinline ModEvent 129 include(Space& home, View& x, const IntSet& s) { 130 IntSetRanges is(s); 131 return x.inter_r(home,is,false); 132 } 133 134 /// Prune view \a x to exclude all values from \a s 135 template<class View> 136 forceinline ModEvent 137 exclude(Space& home, View& x, int s) { 138 return x.nq(home,s); 139 } 140 /// Prune view \a x to exclude all values from \a s 141 template<class View> 142 forceinline ModEvent 143 exclude(Space& home, View& x, const IntSet& s) { 144 IntSetRanges is(s); 145 return x.minus_r(home,is,false); 146 } 147 148}}} 149 150// STATISTICS: int-prop