Generated on Tue Feb 11 2025 17:33:26 for Gecode by doxygen 1.12.0
dom.cpp
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, 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
34
35#include <gecode/int/dom.hh>
36#include <gecode/int/rel.hh>
37
38namespace Gecode {
39
40 void
41 dom(Home home, IntVar x, int n, IntPropLevel) {
42 using namespace Int;
43 Limits::check(n,"Int::dom");
45 IntView xv(x);
46 GECODE_ME_FAIL(xv.eq(home,n));
47 }
48
49 void
50 dom(Home home, const IntVarArgs& x, int n, IntPropLevel) {
51 using namespace Int;
52 Limits::check(n,"Int::dom");
54 for (int i=0; i<x.size(); i++) {
55 IntView xv(x[i]);
56 GECODE_ME_FAIL(xv.eq(home,n));
57 }
58 }
59
60 void
61 dom(Home home, IntVar x, int min, int max, IntPropLevel) {
62 using namespace Int;
63 Limits::check(min,"Int::dom");
64 Limits::check(max,"Int::dom");
66 IntView xv(x);
67 GECODE_ME_FAIL(xv.gq(home,min));
68 GECODE_ME_FAIL(xv.lq(home,max));
69 }
70
71 void
72 dom(Home home, const IntVarArgs& x, int min, int max, IntPropLevel) {
73 using namespace Int;
74 Limits::check(min,"Int::dom");
75 Limits::check(max,"Int::dom");
77 for (int i=0; i<x.size(); i++) {
78 IntView xv(x[i]);
79 GECODE_ME_FAIL(xv.gq(home,min));
80 GECODE_ME_FAIL(xv.lq(home,max));
81 }
82 }
83
84 void
85 dom(Home home, IntVar x, const IntSet& is, IntPropLevel) {
86 using namespace Int;
87 Limits::check(is.min(),"Int::dom");
88 Limits::check(is.max(),"Int::dom");
90 IntView xv(x);
91 IntSetRanges ris(is);
92 GECODE_ME_FAIL(xv.inter_r(home,ris,false));
93 }
94
95 void
96 dom(Home home, const IntVarArgs& x, const IntSet& is, IntPropLevel) {
97 using namespace Int;
98 Limits::check(is.min(),"Int::dom");
99 Limits::check(is.max(),"Int::dom");
101 for (int i=0; i<x.size(); i++) {
102 IntSetRanges ris(is);
103 IntView xv(x[i]);
104 GECODE_ME_FAIL(xv.inter_r(home,ris,false));
105 }
106 }
107
108 void
110 using namespace Int;
111 Limits::check(n,"Int::dom");
113 switch (r.mode()) {
114 case RM_EQV:
116 ::post(home,x,n,r.var())));
117 break;
118 case RM_IMP:
120 ::post(home,x,n,r.var())));
121 break;
122 case RM_PMI:
124 ::post(home,x,n,r.var())));
125 break;
126 default: throw UnknownReifyMode("Int::dom");
127 }
128 }
129
130 void
131 dom(Home home, IntVar x, int min, int max, Reify r, IntPropLevel) {
132 using namespace Int;
133 Limits::check(min,"Int::dom");
134 Limits::check(max,"Int::dom");
136 switch (r.mode()) {
137 case RM_EQV:
139 ::post(home,x,min,max,r.var())));
140 break;
141 case RM_IMP:
143 ::post(home,x,min,max,r.var())));
144 break;
145 case RM_PMI:
147 ::post(home,x,min,max,r.var())));
148 break;
149 default: throw UnknownReifyMode("Int::dom");
150 }
151 }
152
153
154 void
155 dom(Home home, IntVar x, const IntSet& is, Reify r, IntPropLevel) {
156 using namespace Int;
157 Limits::check(is.min(),"Int::dom");
158 Limits::check(is.max(),"Int::dom");
160 switch (r.mode()) {
161 case RM_EQV:
163 break;
164 case RM_IMP:
166 break;
167 case RM_PMI:
169 break;
170 default: throw UnknownReifyMode("Int::dom");
171 }
172 }
173
174 void
176 using namespace Int;
178 IntView xv(x), dv(d);
179 if (xv != dv) {
181 GECODE_ME_FAIL(xv.inter_r(home,r,false));
182 }
183 }
184
185 void
187 using namespace Int;
189 if (d.one())
190 GECODE_ME_FAIL(BoolView(x).one(home));
191 else if (d.zero())
192 GECODE_ME_FAIL(BoolView(x).zero(home));
193 }
194
195 void
196 dom(Home home, const IntVarArgs& x, const IntVarArgs& d, IntPropLevel) {
197 using namespace Int;
198 if (x.size() != d.size())
199 throw ArgumentSizeMismatch("Int::dom");
200 for (int i=0; i<x.size(); i++) {
202 IntView xv(x[i]), dv(d[i]);
203 if (xv != dv) {
205 GECODE_ME_FAIL(xv.inter_r(home,r,false));
206 }
207 }
208 }
209
210 void
211 dom(Home home, const BoolVarArgs& x, const BoolVarArgs& d, IntPropLevel) {
212 using namespace Int;
213 if (x.size() != d.size())
214 throw ArgumentSizeMismatch("Int::dom");
215 for (int i=0; i<x.size(); i++) {
217 if (d[i].one())
218 GECODE_ME_FAIL(BoolView(x[i]).one(home));
219 else if (d[i].zero())
220 GECODE_ME_FAIL(BoolView(x[i]).zero(home));
221 }
222 }
223
224}
225
226// STATISTICS: int-post
227
int n
Number of negative literals for node type.
Passing Boolean variables.
Definition int.hh:712
Boolean integer variables.
Definition int.hh:512
Home class for posting propagators
Definition core.hpp:856
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.
unsigned int size(void) const
Return size (cardinality) of set.
Passing integer variables.
Definition int.hh:656
Integer variables.
Definition int.hh:371
Exception: Arguments are of different size
Definition exception.hpp:73
Boolean view for Boolean variables.
Definition view.hpp:1380
Reified domain dom-propagator.
Definition dom.hh:84
Reified range dom-propagator.
Definition dom.hh:56
Integer view for integer variables.
Definition view.hpp:129
ModEvent inter_r(Space &home, I &i, bool depends=true)
Intersect domain with ranges described by i.
Definition int.hpp:186
ModEvent lq(Space &home, int n)
Restrict domain values to be less or equal than n.
Definition int.hpp:121
ModEvent gq(Space &home, int n)
Restrict domain values to be greater or equal than n.
Definition int.hpp:139
ModEvent eq(Space &home, int n)
Restrict domain values to be equal to n.
Definition int.hpp:166
Reified domain consistent equality with integer propagator.
Definition rel.hh:398
Exception: Unknown reification mode passed as argument
Range iterator for integer views.
Definition view.hpp:54
Reification specification.
Definition int.hh:876
#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
IntPropLevel
Propagation levels for integer propagators.
Definition int.hh:974
@ RM_IMP
Implication for reification.
Definition int.hh:862
@ RM_PMI
Inverse implication for reification.
Definition int.hh:869
@ RM_EQV
Equivalence for reification (default)
Definition int.hh:855
void check(int n, const char *l)
Check whether n is in range, otherwise throw out of limits with information l.
Definition limits.hpp:46
Gecode toplevel namespace
Post propagator for SetVar SetOpType SetVar SetRelType r
Definition set.hh:767
void min(Home home, FloatVar x0, FloatVar x1, FloatVar x2)
Post propagator for .
void dom(Home home, FloatVar x, FloatVal n)
Propagates .
Definition dom.cpp:40
TFE post(PropagatorGroup g)
Only post functions (but not propagators) from g are considered.
Definition filter.cpp:138
void max(Home home, FloatVar x0, FloatVar x1, FloatVar x2)
Post propagator for .
Post propagator for SetVar x
Definition set.hh:767