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
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");
44 GECODE_POST;
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");
53 GECODE_POST;
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");
65 GECODE_POST;
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");
76 GECODE_POST;
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");
89 GECODE_POST;
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");
100 GECODE_POST;
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
109 dom(Home home, IntVar x, int n, Reify r, IntPropLevel) {
110 using namespace Int;
111 Limits::check(n,"Int::dom");
112 GECODE_POST;
113 switch (r.mode()) {
114 case RM_EQV:
115 GECODE_ES_FAIL((Rel::ReEqDomInt<IntView,BoolView,RM_EQV>
116 ::post(home,x,n,r.var())));
117 break;
118 case RM_IMP:
119 GECODE_ES_FAIL((Rel::ReEqDomInt<IntView,BoolView,RM_IMP>
120 ::post(home,x,n,r.var())));
121 break;
122 case RM_PMI:
123 GECODE_ES_FAIL((Rel::ReEqDomInt<IntView,BoolView,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");
135 GECODE_POST;
136 switch (r.mode()) {
137 case RM_EQV:
138 GECODE_ES_FAIL((Dom::ReRange<IntView,RM_EQV>
139 ::post(home,x,min,max,r.var())));
140 break;
141 case RM_IMP:
142 GECODE_ES_FAIL((Dom::ReRange<IntView,RM_IMP>
143 ::post(home,x,min,max,r.var())));
144 break;
145 case RM_PMI:
146 GECODE_ES_FAIL((Dom::ReRange<IntView,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");
159 GECODE_POST;
160 switch (r.mode()) {
161 case RM_EQV:
162 GECODE_ES_FAIL((Dom::ReIntSet<IntView,RM_EQV>::post(home,x,is,r.var())));
163 break;
164 case RM_IMP:
165 GECODE_ES_FAIL((Dom::ReIntSet<IntView,RM_IMP>::post(home,x,is,r.var())));
166 break;
167 case RM_PMI:
168 GECODE_ES_FAIL((Dom::ReIntSet<IntView,RM_PMI>::post(home,x,is,r.var())));
169 break;
170 default: throw UnknownReifyMode("Int::dom");
171 }
172 }
173
174 void
175 dom(Home home, IntVar x, IntVar d, IntPropLevel) {
176 using namespace Int;
177 GECODE_POST;
178 IntView xv(x), dv(d);
179 if (xv != dv) {
180 ViewRanges<IntView> r(dv);
181 GECODE_ME_FAIL(xv.inter_r(home,r,false));
182 }
183 }
184
185 void
186 dom(Home home, BoolVar x, BoolVar d, IntPropLevel) {
187 using namespace Int;
188 GECODE_POST;
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++) {
201 GECODE_POST;
202 IntView xv(x[i]), dv(d[i]);
203 if (xv != dv) {
204 ViewRanges<IntView> r(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++) {
216 GECODE_POST;
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