Generated on Tue Feb 11 2025 17:33:26 for Gecode by doxygen 1.12.0
set-op.hpp
Go to the documentation of this file.
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
42
44 template<class View>
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 }
53 template<class View>
55 takes(const View& x, const IntSet& s) {
56 if ((x.max() < s.min()) || (x.min() > s.max()))
57 return TS_NO;
59 IntSetRanges is(s);
60 switch (Iter::Ranges::compare(ix,is)) {
64 default: GECODE_NEVER;
65 }
66 return TS_MAYBE;
67 }
68
70 template<class View>
71 forceinline bool
72 includes(const View& x, int s) {
73 return x.assigned() && x.in(s);
74 }
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;
82 IntSetRanges is(s);
83 return Iter::Ranges::subset(ix,is);
84 }
85
87 template<class View>
88 forceinline bool
89 excludes(const View& x, int s) {
90 return !x.in(s);
91 }
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;
99 IntSetRanges is(s);
100 return Iter::Ranges::disjoint(ix,is);
101 }
102
104 template<class View>
105 forceinline bool
106 undecided(const View& x, int s) {
107 return !x.assigned() && x.in(s);
108 }
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;
116 IntSetRanges is(s);
118 }
119
121 template<class View>
123 include(Space& home, View& x, int s) {
124 return x.eq(home,s);
125 }
127 template<class View>
129 include(Space& home, View& x, const IntSet& s) {
130 IntSetRanges is(s);
131 return x.inter_r(home,is,false);
132 }
133
135 template<class View>
137 exclude(Space& home, View& x, int s) {
138 return x.nq(home,s);
139 }
141 template<class View>
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
Range iterator for integer sets.
Definition int.hh:292
Integer sets.
Definition int.hh:174
int min(int i) const
Return minimum of range at position i.
int max(int i) const
Return maximum of range at position i.
Range iterator for integer views.
Definition view.hpp:54
Computation spaces.
Definition core.hpp:1742
bool assigned(void) const
Test whether view is assigned.
Definition var.hpp:111
ModEvent exclude(Space &home, View &x, int s)
Prune view x to exclude all values from s.
Definition set-op.hpp:137
bool excludes(const View &x, int s)
Test whether all values of view x are excluded from s.
Definition set-op.hpp:89
TakesStatus
Status of whether a view takes a value from a set.
Definition set-op.hpp:37
@ TS_MAYBE
Maybe or maybe not.
Definition set-op.hpp:40
@ TS_NO
Definitely not.
Definition set-op.hpp:38
@ TS_YES
Definitely yes.
Definition set-op.hpp:39
bool includes(const View &x, int s)
Test whether all values of view x are included in s.
Definition set-op.hpp:72
ModEvent include(Space &home, View &x, int s)
Prune view x to only include values from s.
Definition set-op.hpp:123
bool undecided(const View &x, int s)
Test whether no decision on inclusion or exclusion of values of view x in s can be made.
Definition set-op.hpp:106
TakesStatus takes(const View &x, int s)
Return whether view x takes value s.
Definition set-op.hpp:46
@ CS_NONE
Neither of the above.
@ CS_SUBSET
First is subset of second iterator.
@ CS_DISJOINT
Intersection is empty.
bool subset(I &i, J &j)
Check whether range iterator i is subset of range iterator j.
CompareStatus compare(I &i, J &j)
Check whether range iterator i is a subset of j, or whether they are disjoint.
bool disjoint(I &i, J &j)
Check whether range iterators i and j are disjoint.
Gecode toplevel namespace
Post propagator for SetVar x
Definition set.hh:767
int ModEvent
Type for modification events.
Definition core.hpp:62
#define forceinline
Definition config.hpp:187
#define GECODE_NEVER
Assert that this command is never executed.
Definition macros.hpp:56