Generated on Sat Feb 7 2015 02:01:16 for Gecode by doxygen 1.8.9.1
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  * Last modified:
10  * $Date: 2013-03-05 13:52:08 +0100 (Tue, 05 Mar 2013) $ by $Author: schulte $
11  * $Revision: 13434 $
12  *
13  * This file is part of Gecode, the generic constraint
14  * development environment:
15  * http://www.gecode.org
16  *
17  * Permission is hereby granted, free of charge, to any person obtaining
18  * a copy of this software and associated documentation files (the
19  * "Software"), to deal in the Software without restriction, including
20  * without limitation the rights to use, copy, modify, merge, publish,
21  * distribute, sublicense, and/or sell copies of the Software, and to
22  * permit persons to whom the Software is furnished to do so, subject to
23  * the following conditions:
24  *
25  * The above copyright notice and this permission notice shall be
26  * included in all copies or substantial portions of the Software.
27  *
28  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
29  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
30  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
31  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
32  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
33  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
34  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35  *
36  */
37 
38 
39 #include <gecode/int/dom.hh>
40 #include <gecode/int/rel.hh>
41 
42 namespace Gecode {
43 
44  void
45  dom(Home home, IntVar x, int n, IntConLevel) {
46  using namespace Int;
47  Limits::check(n,"Int::dom");
48  if (home.failed()) return;
49  IntView xv(x);
50  GECODE_ME_FAIL(xv.eq(home,n));
51  }
52 
53  void
54  dom(Home home, const IntVarArgs& x, int n, IntConLevel) {
55  using namespace Int;
56  Limits::check(n,"Int::dom");
57  if (home.failed()) return;
58  for (int i=x.size(); i--; ) {
59  IntView xv(x[i]);
60  GECODE_ME_FAIL(xv.eq(home,n));
61  }
62  }
63 
64  void
65  dom(Home home, IntVar x, int min, int max, IntConLevel) {
66  using namespace Int;
67  Limits::check(min,"Int::dom");
68  Limits::check(max,"Int::dom");
69  if (home.failed()) return;
70  IntView xv(x);
71  GECODE_ME_FAIL(xv.gq(home,min));
72  GECODE_ME_FAIL(xv.lq(home,max));
73  }
74 
75  void
76  dom(Home home, const IntVarArgs& x, int min, int max, IntConLevel) {
77  using namespace Int;
78  Limits::check(min,"Int::dom");
79  Limits::check(max,"Int::dom");
80  if (home.failed()) return;
81  for (int i=x.size(); i--; ) {
82  IntView xv(x[i]);
83  GECODE_ME_FAIL(xv.gq(home,min));
84  GECODE_ME_FAIL(xv.lq(home,max));
85  }
86  }
87 
88  void
89  dom(Home home, IntVar x, const IntSet& is, IntConLevel) {
90  using namespace Int;
91  Limits::check(is.min(),"Int::dom");
92  Limits::check(is.max(),"Int::dom");
93  if (home.failed()) return;
94  IntView xv(x);
95  IntSetRanges ris(is);
96  GECODE_ME_FAIL(xv.inter_r(home,ris,false));
97  }
98 
99  void
100  dom(Home home, const IntVarArgs& x, const IntSet& is, IntConLevel) {
101  using namespace Int;
102  Limits::check(is.min(),"Int::dom");
103  Limits::check(is.max(),"Int::dom");
104  if (home.failed()) return;
105  for (int i = x.size(); i--; ) {
106  IntSetRanges ris(is);
107  IntView xv(x[i]);
108  GECODE_ME_FAIL(xv.inter_r(home,ris,false));
109  }
110  }
111 
112  void
113  dom(Home home, IntVar x, int n, Reify r, IntConLevel) {
114  using namespace Int;
115  Limits::check(n,"Int::dom");
116  if (home.failed()) return;
117  switch (r.mode()) {
118  case RM_EQV:
120  ::post(home,x,n,r.var())));
121  break;
122  case RM_IMP:
124  ::post(home,x,n,r.var())));
125  break;
126  case RM_PMI:
128  ::post(home,x,n,r.var())));
129  break;
130  default: throw UnknownReifyMode("Int::dom");
131  }
132  }
133 
134  void
135  dom(Home home, IntVar x, int min, int max, Reify r, IntConLevel) {
136  using namespace Int;
137  Limits::check(min,"Int::dom");
138  Limits::check(max,"Int::dom");
139  if (home.failed()) return;
140  switch (r.mode()) {
141  case RM_EQV:
143  ::post(home,x,min,max,r.var())));
144  break;
145  case RM_IMP:
147  ::post(home,x,min,max,r.var())));
148  break;
149  case RM_PMI:
151  ::post(home,x,min,max,r.var())));
152  break;
153  default: throw UnknownReifyMode("Int::dom");
154  }
155  }
156 
157 
158  void
159  dom(Home home, IntVar x, const IntSet& is, Reify r, IntConLevel) {
160  using namespace Int;
161  Limits::check(is.min(),"Int::dom");
162  Limits::check(is.max(),"Int::dom");
163  if (home.failed()) return;
164  switch (r.mode()) {
165  case RM_EQV:
167  break;
168  case RM_IMP:
170  break;
171  case RM_PMI:
173  break;
174  default: throw UnknownReifyMode("Int::dom");
175  }
176  }
177 
178  void
180  using namespace Int;
181  if (home.failed()) return;
182  IntView xv(x), dv(d);
183  if (!same(xv,dv)) {
185  GECODE_ME_FAIL(xv.inter_r(home,r,false));
186  }
187  }
188 
189  void
191  using namespace Int;
192  if (home.failed()) return;
193  if (d.one())
194  GECODE_ME_FAIL(BoolView(x).one(home));
195  else if (d.zero())
196  GECODE_ME_FAIL(BoolView(x).zero(home));
197  }
198 
199  void
200  dom(Home home, const IntVarArgs& x, const IntVarArgs& d, IntConLevel) {
201  using namespace Int;
202  if (x.size() != d.size())
203  throw ArgumentSizeMismatch("Int::dom");
204  for (int i=x.size(); i--; ) {
205  if (home.failed()) return;
206  IntView xv(x[i]), dv(d[i]);
207  if (!same(xv,dv)) {
209  GECODE_ME_FAIL(xv.inter_r(home,r,false));
210  }
211  }
212  }
213 
214  void
215  dom(Home home, const BoolVarArgs& x, const BoolVarArgs& d, IntConLevel) {
216  using namespace Int;
217  if (x.size() != d.size())
218  throw ArgumentSizeMismatch("Int::dom");
219  for (int i=x.size(); i--; ) {
220  if (home.failed()) return;
221  if (d[i].one())
222  GECODE_ME_FAIL(BoolView(x[i]).one(home));
223  else if (d[i].zero())
224  GECODE_ME_FAIL(BoolView(x[i]).zero(home));
225  }
226  }
227 
228 }
229 
230 // STATISTICS: int-post
231 
bool failed(void) const
Check whether corresponding space is failed.
Definition: core.hpp:3446
ModEvent inter_r(Space &home, I &i, bool depends=true)
Intersect domain with ranges described by i.
Definition: int.hpp:180
IntConLevel
Consistency levels for integer propagators.
Definition: int.hh:937
Inverse implication for reification.
Definition: int.hh:847
ReifyMode mode(void) const
Return reification mode.
Definition: reify.hpp:60
void post(Home home, Term *t, int n, FloatRelType frt, FloatVal c)
Post propagator for linear constraint over floats.
Definition: post.cpp:228
Range iterator for integer sets.
Definition: int.hh:271
BoolVar var(void) const
Return Boolean control variable.
Definition: reify.hpp:52
bool one(const Gecode::FloatValArgs &a)
Check whether has only one coefficients.
Definition: linear.cpp:50
int size(void) const
Return size of array (number of elements)
Definition: array.hpp:1662
ModEvent eq(Space &home, int n)
Restrict domain values to be equal to n.
Definition: int.hpp:160
bool zero(void) const
Test whether domain is zero.
Definition: bool.hpp:107
void max(Home home, FloatVar x0, FloatVar x1, FloatVar x2)
Post propagator for .
Definition: arithmetic.cpp:57
Reified domain dom-propagator.
Definition: dom.hh:88
void dom(Home home, FloatVar x, FloatVal n)
Propagates .
Definition: dom.cpp:44
Range iterator for integer variable views
Definition: int.hpp:236
bool same(const CachedView< View > &x, const CachedView< View > &y)
Definition: cached.hpp:389
Gecode::IntSet d(r, 4)
Gecode::IntArgs i(4, 1, 2, 3, 4)
int n
Number of negative literals for node type.
Definition: bool-expr.cpp:238
ModEvent lq(Space &home, int n)
Restrict domain values to be less or equal than n.
Definition: int.hpp:115
Reified range dom-propagator.
Definition: dom.hh:60
bool one(void) const
Test whether domain is one.
Definition: bool.hpp:111
Reification specification.
Definition: int.hh:854
Integer sets.
Definition: int.hh:171
Passing integer variables.
Definition: int.hh:636
Passing Boolean variables.
Definition: int.hh:690
Boolean integer variables.
Definition: int.hh:491
void min(Home home, FloatVar x0, FloatVar x1, FloatVar x2)
Post propagator for .
Definition: arithmetic.cpp:75
bool one(void) const
Test whether view is assigned to be one.
Definition: bool.hpp:218
Integer view for integer variables.
Definition: view.hpp:129
Node * x
Pointer to corresponding Boolean expression node.
Definition: bool-expr.cpp:253
Integer variables.
Definition: int.hh:350
ModEvent gq(Space &home, int n)
Restrict domain values to be greater or equal than n.
Definition: int.hpp:133
#define GECODE_ME_FAIL(me)
Check whether modification event me is failed, and fail space home.
Definition: macros.hpp:70
Exception: Unknown reification mode passed as argument
Definition: exception.hpp:119
Gecode toplevel namespace
Implication for reification.
Definition: int.hh:840
bool zero(void) const
Test whether view is assigned to be zero.
Definition: bool.hpp:214
Reified domain consistent equality with integer propagator.
Definition: rel.hh:370
void check(int n, const char *l)
Check whether n is in range, otherwise throw out of limits with information l.
Definition: limits.hpp:50
Home class for posting propagators
Definition: core.hpp:717
Exception: Arguments are of different size
Definition: exception.hpp:77
#define GECODE_ES_FAIL(es)
Check whether execution status es is failed, and fail space home.
Definition: macros.hpp:96
const int r[4][2]
Definition: dom.cpp:126
int max(int i) const
Return maximum of range at position i.
Definition: int-set-1.hpp:121
int min(int i) const
Return minimum of range at position i.
Definition: int-set-1.hpp:115
Equivalence for reification (default)
Definition: int.hh:833
Boolean view for Boolean variables.
Definition: view.hpp:1315