Generated on Thu Jan 20 2022 00:00:00 for Gecode by doxygen 1.9.1
rel.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, 2003
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 #include <gecode/int/rel.hh>
35 
36 namespace Gecode { namespace Int { namespace Count {
37 
38  /*
39  * Counting domain consistent equality
40  *
41  */
42 
43  template<class VY>
44  forceinline bool
45  isintset(VY y) {
46  (void) y;
47  return false;
48  }
49  template<>
50  forceinline bool
52  (void) y;
53  return true;
54  }
55 
56 
57  template<class VY>
58  forceinline bool
59  isval(VY y) {
60  return y.assigned();
61  }
62  template<>
63  forceinline bool
65  (void) y;
66  return true;
67  }
68 
69 
70  forceinline void
72  (void) home; (void) p; (void) y;
73  }
74  template<class VY>
75  forceinline void
76  subscribe(Space& home, Propagator& p, VY y) {
77  y.subscribe(home, p, PC_INT_DOM);
78  }
79 
80  forceinline void
81  cancel(Space& home, Propagator& p, IntSet& y) {
82  (void) home; (void) p;
83  y.~IntSet();
84  }
85  template<class VY>
86  forceinline void
87  cancel(Space& home, Propagator& p, VY y) {
88  y.cancel(home, p, PC_INT_DOM);
89  }
90 
91  forceinline void
93  (void) home; (void) p; (void) y;
94  }
95  template<class VY>
96  forceinline void
97  reschedule(Space& home, Propagator& p, VY y) {
98  (void) y; // To satisy MSVC
99  y.schedule(home, p, PC_INT_DOM);
100  }
101 
102  forceinline void
103  update(IntSet& y, Space& home, IntSet& py) {
104  (void) home;
105  y=py;
106  }
107  template<class VY>
108  forceinline void
109  update(VY& y, Space& home, VY py) {
110  y.update(home, py);
111  }
112 
113  template<class VX>
116  return rtest_eq_dom(x,y.val());
117  }
118  template<class VX>
121  return rtest_eq_dom(x,0);
122  }
123  template<class VX>
125  holds(VX x, const IntSet& y) {
126  if ((x.max() < y.min()) || (y.max() < x.min()))
127  return RT_FALSE;
128  ViewRanges<VX> rx(x);
129  IntSetRanges ry(y);
130  switch (Iter::Ranges::compare(rx,ry)) {
132  return RT_TRUE;
134  return RT_FALSE;
136  return RT_MAYBE;
137  default:
138  GECODE_NEVER;
139  }
140  GECODE_NEVER;
141  return RT_MAYBE;
142  }
143  template<class VX>
145  holds(VX x, VX y) {
146  return rtest_eq_dom(x,y);
147  }
148 
149  template<class VX>
151  post_true(Home home, VX x, ConstIntView y) {
152  GECODE_ME_CHECK(x.eq(home,y.val()));
153  return ES_OK;
154  }
155  template<class VX>
158  GECODE_ME_CHECK(x.eq(home,0));
159  return ES_OK;
160  }
161  template<class VX>
163  post_true(Home home, VX x, const IntSet& y) {
164  IntSetRanges ry(y);
165  GECODE_ME_CHECK(x.inter_r(home,ry,false));
166  return ES_OK;
167  }
168  template<class VX>
171  for (int i=0; i<x.size(); i++)
172  GECODE_ME_CHECK(x[i].eq(home,y.val()));
173  return ES_OK;
174  }
175  template<class VX>
178  for (int i=0; i<x.size(); i++)
179  GECODE_ME_CHECK(x[i].eq(home,0));
180  return ES_OK;
181  }
182  template<class VX>
184  post_true(Home home, ViewArray<VX>& x, const IntSet& y) {
185  for (int i=0; i<x.size(); i++) {
186  IntSetRanges ry(y);
187  GECODE_ME_CHECK(x[i].inter_r(home,ry,false));
188  }
189  return ES_OK;
190  }
191 
192  template<class VX>
194  post_false(Home home, VX x, ConstIntView y) {
195  GECODE_ME_CHECK(x.nq(home,y.val()));
196  return ES_OK;
197  }
198  template<class VX>
201  GECODE_ME_CHECK(x.nq(home,0));
202  return ES_OK;
203  }
204  template<class VX>
206  post_false(Home home, VX x, const IntSet& y) {
207  IntSetRanges ry(y);
208  GECODE_ME_CHECK(x.minus_r(home,ry,false));
209  return ES_OK;
210  }
211  template<class VX>
214  for (int i=0; i<x.size(); i++)
215  GECODE_ME_CHECK(x[i].nq(home,y.val()));
216  return ES_OK;
217  }
218  template<class VX>
221  for (int i=0; i<x.size(); i++)
222  GECODE_ME_CHECK(x[i].nq(home,0));
223  return ES_OK;
224  }
225  template<class VX>
227  post_false(Home home, ViewArray<VX>& x, const IntSet& y) {
228  for (int i=0; i<x.size(); i++) {
229  IntSetRanges ry(y);
230  GECODE_ME_CHECK(x[i].minus_r(home,ry,false));
231  }
232  return ES_OK;
233  }
234 
235  template<class VX>
237  post_true(Home home, ViewArray<VX>& x, VX y) {
238  ViewArray<VX> z(home,x.size()+1);
239  z[x.size()] = y;
240  for (int i=0; i<x.size(); i++)
241  z[i] = x[i];
242  return Rel::NaryEqDom<VX>::post(home,z);
243  }
244  template<class VX>
246  post_true(Home home, VX x, VX y) {
247  return Rel::EqDom<VX,VX>::post(home,x,y);
248  }
249  template<class VX>
251  post_false(Home home, ViewArray<VX>& x, VX y) {
252  for (int i=0; i<x.size(); i++)
254  return ES_OK;
255  }
256  template<class VX>
258  post_false(Home home, VX x, VX y) {
259  return Rel::Nq<VX,VX>::post(home,x,y);
260  }
261 
262  template<class VX>
265  (void) home;
266  (void) x;
267  return ES_OK;
268  }
269  template<class VX>
272  (void) home;
273  (void) x;
274  return ES_OK;
275  }
276  template<class VX>
278  prune(Space& home, ViewArray<VX>& x, const IntSet& y) {
279  (void) home;
280  (void) x;
281  (void) y;
282  return ES_OK;
283  }
284  template<class VX>
286  prune(Space& home, ViewArray<VX>& x, VX y) {
287  if (x.size() == 0)
288  return ES_OK;
289  Region r;
290  ViewRanges<VX>* rx = r.alloc<ViewRanges<VX> >(x.size());
291  for (int i=0; i<x.size(); i++)
292  rx[i] = ViewRanges<VX>(x[i]);
293  Iter::Ranges::NaryUnion u(r, rx, x.size());
294  GECODE_ME_CHECK(y.inter_r(home, u, false));
295  return ES_OK;
296  }
297 
298 }}}
299 
300 // STATISTICS: int-prop
int p
Number of positive literals for node type.
Definition: bool-expr.cpp:232
union Gecode::@602::NNF::@65 u
Union depending on nodetype t.
Node * x
Pointer to corresponding Boolean expression node.
Definition: bool-expr.cpp:249
NNF * r
Right subtree.
Definition: bool-expr.cpp:242
Home class for posting propagators
Definition: core.hpp:856
Range iterator for integer sets.
Definition: int.hh:292
Integer sets.
Definition: int.hh:174
Constant integer view.
Definition: view.hpp:851
static ExecStatus post(Home home, View0 x0, View1 x1)
Post domain consistent propagator .
Definition: eq.hpp:176
static ExecStatus post(Home home, ViewArray< View > &x)
Post domain consistent propagator .
Definition: eq.hpp:270
Binary disequality propagator.
Definition: rel.hh:460
static ExecStatus post(Home home, V0 x0, V1 x1)
Post propagator .
Definition: nq.hpp:49
Range iterator for integer views.
Definition: view.hpp:54
Zero integer view.
Definition: view.hpp:1014
Range iterator for union of iterators.
Base-class for propagators.
Definition: core.hpp:1064
Handle to region.
Definition: region.hpp:55
Computation spaces.
Definition: core.hpp:1742
void update(Space &home, VarImpVar< VarImp > &y)
Update this variable to be a clone of variable y.
Definition: var.hpp:116
bool assigned(void) const
Test whether view is assigned.
Definition: var.hpp:111
ExecStatus
Definition: core.hpp:472
@ ES_OK
Execution is okay.
Definition: core.hpp:476
Post propagator for SetVar SetOpType SetVar SetRelType SetVar z
Definition: set.hh:767
Post propagator for SetVar SetOpType SetVar y
Definition: set.hh:767
#define GECODE_ME_CHECK(me)
Check whether modification event me is failed, and forward failure.
Definition: macros.hpp:52
#define GECODE_ES_CHECK(es)
Check whether execution status es is failed or subsumed, and forward failure or subsumption.
Definition: macros.hpp:91
ExecStatus prune(Space &home, ViewArray< VX > &x, ConstIntView)
Definition: rel.hpp:264
void cancel(Space &home, Propagator &p, IntSet &y)
Definition: rel.hpp:81
RelTest holds(VX x, ConstIntView y)
Test whether x and y are equal.
Definition: rel.hpp:115
void subscribe(Space &home, Propagator &p, IntSet &y)
Definition: rel.hpp:71
ExecStatus post_true(Home home, VX x, ConstIntView y)
Definition: rel.hpp:151
bool isval(VY y)
Return whether y is a value.
Definition: rel.hpp:59
bool isintset(VY y)
Return whether y is an integer set.
Definition: rel.hpp:45
void update(IntSet &y, Space &home, IntSet &py)
Definition: rel.hpp:103
void reschedule(Space &home, Propagator &p, IntSet &y)
Definition: rel.hpp:92
ExecStatus post_false(Home home, VX x, ConstIntView y)
Definition: rel.hpp:194
RelTest rtest_eq_dom(VX x, VY y)
Test whether views x and y are equal (use full domain information)
Definition: rel-test.hpp:65
const Gecode::PropCond PC_INT_DOM
Propagate when domain changes.
Definition: var-type.hpp:100
RelTest
Result of testing relation.
Definition: view.hpp:1734
@ RT_TRUE
Relation does hold.
Definition: view.hpp:1737
@ RT_MAYBE
Relation may hold or not.
Definition: view.hpp:1736
@ RT_FALSE
Relation does not hold.
Definition: view.hpp:1735
@ CS_NONE
Neither of the above.
@ CS_SUBSET
First is subset of second iterator.
@ CS_DISJOINT
Intersection is empty.
CompareStatus compare(I &i, J &j)
Check whether range iterator i is a subset of j, or whether they are disjoint.
Gecode::IntArgs i({1, 2, 3, 4})
#define forceinline
Definition: config.hpp:194
#define GECODE_NEVER
Assert that this command is never executed.
Definition: macros.hpp:56