Generated on Thu Jan 16 2025 00:00:00 for Gecode by doxygen 1.14.0
int.cpp
Go to the documentation of this file.
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 * Copyright:
8 * Guido Tack, 2004
9 * Christian Schulte, 2004
10 *
11 * This file is part of Gecode, the generic constraint
12 * development environment:
13 * http://www.gecode.org
14 *
15 * Permission is hereby granted, free of charge, to any person obtaining
16 * a copy of this software and associated documentation files (the
17 * "Software"), to deal in the Software without restriction, including
18 * without limitation the rights to use, copy, modify, merge, publish,
19 * distribute, sublicense, and/or sell copies of the Software, and to
20 * permit persons to whom the Software is furnished to do so, subject to
21 * the following conditions:
22 *
23 * The above copyright notice and this permission notice shall be
24 * included in all copies or substantial portions of the Software.
25 *
26 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
27 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
28 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
29 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
30 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
31 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
32 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33 *
34 */
35
36#include <gecode/set.hh>
37
38#include <gecode/set/int.hh>
39#include <gecode/set/rel.hh>
40
41namespace Gecode {
42
43 void
44 rel(Home home, SetVar s, IntRelType rt, IntVar x) {
46 switch (rt) {
47 case IRT_EQ:
48 {
50 Set::SingletonView xsingle(xv);
53 ::post(home,s,xsingle)));
54
55 }
56 break;
57 case IRT_NQ:
58 {
60 GECODE_ME_FAIL( sv.cardMin(home, 1));
62 Set::SingletonView xsingle(xv);
65 ::post(home,xsingle,sv)));
66
67 }
68 break;
69 case IRT_LQ:
70 {
72 rel(home, tmp, IRT_LQ, x);
74 }
75 break;
76 case IRT_LE:
77 {
79 rel(home, tmp, IRT_LE, x);
81 }
82 break;
83 case IRT_GQ:
84 {
86 rel(home, tmp, IRT_GQ, x);
88 }
89 break;
90 case IRT_GR:
91 {
93 rel(home, tmp, IRT_GR, x);
95 }
96 break;
97 default:
98 throw Int::UnknownRelation("Set::rel");
99 }
100
101 }
102
103}
104
105namespace Gecode { namespace Set { namespace Int {
106
108 void remin(Home home, SetVar s, IntVar m, Reify r) {
109 IntVar c(home, 0, static_cast<int>(Set::Limits::card));
110 cardinality(home, s, c);
111 // Whether set is not empty
112 BoolVar ne(home, 0, 1);
113 rel(home, c, IRT_GR, 0, ne);
114 if (r.mode() != RM_PMI)
115 rel(home, r.var(), BOT_IMP, ne, 1);
116 min(home, s, m, ne);
117 }
118
120 void remax(Home home, SetVar s, IntVar m, Reify r) {
121 IntVar c(home, 0, static_cast<int>(Set::Limits::card));
122 cardinality(home, s, c);
123 // Whether set is not empty
124 BoolVar ne(home, 0, 1);
125 rel(home, c, IRT_GR, 0, ne);
126 if (r.mode() != RM_PMI)
127 rel(home, r.var(), BOT_IMP, ne, 1);
128 max(home, s, m, ne);
129 }
130
131}}}
132
133namespace Gecode {
134
135 void
138 switch (rt) {
139 case IRT_EQ:
140 {
142 Set::SingletonView xs(xv);
143 switch (r.mode()) {
144 case RM_EQV:
147 ::post(home,s,xs,r.var())));
148 break;
149 case RM_IMP:
152 ::post(home,s,xs,r.var())));
153 break;
154 case RM_PMI:
157 ::post(home,s,xs,r.var())));
158 break;
159 default:
160 throw Gecode::Int::UnknownReifyMode("Set::rel");
161 }
162 }
163 break;
164 case IRT_NQ:
165 {
166 IntVar c(home, 0, static_cast<int>(Set::Limits::card));
167 cardinality(home, s, c);
168 // Whether set is not empty
169 BoolVar ne(home, 0 , 1);
170 rel(home, c, IRT_GR, 0, ne);
171 // Whether {x} is a subset of s
172 BoolVar ss(home, 0 , 1);
173 rel(home, x, SRT_SUB, s, ss);
174 BoolVar b;
175 switch (r.mode()) {
176 case RM_EQV:
177 b=r.var();
178 break;
179 case RM_IMP:
180 b=BoolVar(home, 0, 1);
181 rel(home, r.var(), BOT_IMP, b, 1);
182 break;
183 case RM_PMI:
184 b=BoolVar(home, 0, 1);
185 rel(home, b, BOT_IMP, r.var(), 1);
186 break;
187 default:
188 throw Gecode::Int::UnknownReifyMode("Set::rel");
189 }
190 BoolVarArgs p(1); p[0]=ne;
191 BoolVarArgs n(1); n[0]=ss;
192 clause(home, BOT_AND, p, n, b);
193 }
194 break;
195 case IRT_LQ:
196 {
198 rel(home, tmp, IRT_LQ, x, r);
199 Gecode::Set::Int::remax(home, s, tmp, r);
200 }
201 break;
202 case IRT_LE:
203 {
205 rel(home, tmp, IRT_LE, x, r);
206 Gecode::Set::Int::remax(home, s, tmp, r);
207 }
208 break;
209 case IRT_GQ:
210 {
212 rel(home, tmp, IRT_GQ, x, r);
213 Gecode::Set::Int::remin(home, s, tmp, r);
214 }
215 break;
216 case IRT_GR:
217 {
219 rel(home, tmp, IRT_GR, x, r);
220 Gecode::Set::Int::remin(home, s, tmp, r);
221 }
222 break;
223 default:
224 throw Int::UnknownRelation("Set::rel");
225 }
226 }
227
228 void
233
234 void
239
240 void
241 min(Home home, SetVar s, IntVar x, Reify r) {
243 switch (r.mode()) {
244 case RM_EQV:
246 ::post(home,s,x,r.var())));
247 break;
248 case RM_IMP:
250 ::post(home,s,x,r.var())));
251 break;
252 case RM_PMI:
254 ::post(home,s,x,r.var())));
255 break;
256 default: throw Gecode::Int::UnknownReifyMode("Set::min");
257 }
258 }
259
260 void
265
266 void
271
272 void
273 max(Home home, SetVar s, IntVar x, Reify r) {
275 switch (r.mode()) {
276 case RM_EQV:
278 ::post(home,s,x,r.var())));
279 break;
280 case RM_IMP:
282 ::post(home,s,x,r.var())));
283 break;
284 case RM_PMI:
286 ::post(home,s,x,r.var())));
287 break;
288 default: throw Gecode::Int::UnknownReifyMode("Set::max");
289 }
290 }
291
298
299}
300
301// STATISTICS: set-post
Passing Boolean variables.
Definition int.hh:721
Boolean integer variables.
Definition int.hh:515
Home class for posting propagators
Definition core.hpp:856
Integer variables.
Definition int.hh:371
Boolean view for Boolean variables.
Definition view.hpp:1380
Integer view for integer variables.
Definition view.hpp:129
Exception: Unknown reification mode passed as argument
Exception: Unknown relation passed as argument
Definition exception.hpp:87
Reification specification.
Definition int.hh:891
Set variables
Definition set.hh:127
static ExecStatus post(Home home, View s, Gecode::Int::IntView x)
Post propagator for x is the largest element of s.
Definition minmax.hpp:408
static ExecStatus post(Home home, View s, Gecode::Int::IntView x)
Post propagator for x is the minimal element of s.
Definition minmax.hpp:53
static ExecStatus post(Home home, View s, Gecode::Int::IntView x)
Post propagator for x is not the largest element of s.
Definition minmax.hpp:457
static ExecStatus post(Home home, View s, Gecode::Int::IntView x)
Post propagator for x is not the minimal element of s.
Definition minmax.hpp:141
Reified propagator for maximum element
Definition int.hh:200
Propagator for reified minimum element
Definition int.hh:113
static ExecStatus post(Home home, const SharedArray< int > &elements, const SharedArray< int > &weights, View x, Gecode::Int::IntView y)
Post propagator for .
Definition weights.hpp:167
Propagator for set equality
Definition rel.hh:150
Propagator for the negated subset constraint
Definition rel.hh:91
Reified equality propagator
Definition rel.hh:174
Set view for set variables
Definition view.hpp:56
unsigned int cardMin(void) const
Return minimum cardinality.
Definition set.hpp:82
Singleton set view.
Definition view.hpp:594
#define GECODE_POST
Check for failure in a constraint post function.
Definition macros.hpp:40
#define GECODE_ES_FAIL(es)
Check whether execution status es is failed, and fail space home.
Definition macros.hpp:103
#define GECODE_ME_FAIL(me)
Check whether modification event me is failed, and fail space home.
Definition macros.hpp:77
void rel(Home home, FloatVar x0, FloatRelType frt, FloatVar x1)
Post propagator for .
Definition rel.cpp:68
void clause(Home home, BoolOpType o, const BoolVarArgs &x, const BoolVarArgs &y, BoolVar z, IntPropLevel ipl=IPL_DEF)
Post domain consistent propagator for Boolean clause with positive variables x and negative variables...
Definition bool.cpp:955
IntRelType
Relation types for integers.
Definition int.hh:940
@ IRT_EQ
Equality ( )
Definition int.hh:941
@ IRT_NQ
Disequality ( )
Definition int.hh:942
@ IRT_GQ
Greater or equal ( )
Definition int.hh:945
@ IRT_LE
Less ( )
Definition int.hh:944
@ IRT_GR
Greater ( )
Definition int.hh:946
@ IRT_LQ
Less or equal ( )
Definition int.hh:943
@ RM_IMP
Implication for reification.
Definition int.hh:877
@ RM_PMI
Inverse implication for reification.
Definition int.hh:884
@ RM_EQV
Equivalence for reification (default)
Definition int.hh:870
@ BOT_IMP
Implication.
Definition int.hh:968
@ BOT_AND
Conjunction.
Definition int.hh:966
@ SRT_SUB
Subset ( )
Definition set.hh:652
const int min
Smallest allowed integer value.
Definition int.hh:118
const int max
Largest allowed integer value.
Definition int.hh:116
Propagators connecting set and int variables.
Definition int.cpp:105
void remax(Home home, SetVar s, IntVar m, Reify r)
Reify m to be the maximum of s.
Definition int.cpp:120
void remin(Home home, SetVar s, IntVar m, Reify r)
Reify m to be the minimum of s.
Definition int.cpp:108
const unsigned int card
Maximum cardinality of an integer set.
Definition set.hh:101
Finite integer sets.
Definition var-imp.hpp:137
Gecode toplevel namespace
void weights(Home home, IntSharedArray elements, IntSharedArray weights, SetVar x, IntVar y)
Definition int.cpp:292
Post propagator for SetVar SetOpType SetVar SetRelType r
Definition set.hh:773
void notMin(Home home, SetVar s, IntVar x)
Definition int.cpp:235
SharedArray< int > IntSharedArray
Arrays of integers that can be shared among several element constraints.
Definition int.hh:1492
void min(Home home, FloatVar x0, FloatVar x1, FloatVar x2)
Post propagator for .
Post propagator for SetVar SetOpType SetVar y
Definition set.hh:773
TFE post(PropagatorGroup g)
Only post functions (but not propagators) from g are considered.
Definition filter.cpp:138
void notMax(Home home, SetVar s, IntVar x)
Definition int.cpp:267
void max(Home home, FloatVar x0, FloatVar x1, FloatVar x2)
Post propagator for .
LinIntExpr cardinality(const SetExpr &)
Cardinality of set expression.
Definition set-expr.cpp:817
Post propagator for SetVar x
Definition set.hh:773