Generated on Tue Jan 19 2021 06:15:49 for Gecode by doxygen 1.8.13
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
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>
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>
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>
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>
252  for (int i=0; i<x.size(); i++)
253  GECODE_ES_CHECK((Rel::Nq<VX,VX>::post(home,x[i],y)));
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
Relation may hold or not.
Definition: view.hpp:1703
static ExecStatus post(Home home, V0 x0, V1 x1)
Post propagator .
Definition: nq.hpp:49
Range iterator for integer sets.
Definition: int.hh:292
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
void cancel(Space &home, Propagator &p, IntSet &y)
Definition: rel.hpp:81
T * alloc(long unsigned int n)
Allocate block of n objects of type T from region.
Definition: region.hpp:386
RelTest holds(VX x, ConstIntView y)
Test whether x and y are equal.
Definition: rel.hpp:115
static ExecStatus post(Home home, View0 x0, View1 x1)
Post domain consistent propagator .
Definition: eq.hpp:176
First is subset of second iterator.
Base-class for propagators.
Definition: core.hpp:1023
bool isval(VY y)
Return whether y is a value.
Definition: rel.hpp:59
Handle to region.
Definition: region.hpp:55
#define forceinline
Definition: config.hpp:185
Computation spaces.
Definition: core.hpp:1701
ExecStatus prune(Space &home, ViewArray< VX > &x, ConstIntView)
Definition: rel.hpp:264
int min(int i) const
Return minimum of range at position i.
Definition: int-set-1.hpp:149
Range iterator for integer views.
Definition: view.hpp:54
#define GECODE_ES_CHECK(es)
Check whether execution status es is failed or subsumed, and forward failure or subsumption.
Definition: macros.hpp:91
int p
Number of positive literals for node type.
Definition: bool-expr.cpp:232
int val(void) const
Return assigned value (only if assigned)
Definition: constint.hpp:62
Gecode::IntArgs i({1, 2, 3, 4})
Relation does not hold.
Definition: view.hpp:1702
RelTest
Result of testing relation.
Definition: view.hpp:1701
int max(int i) const
Return maximum of range at position i.
Definition: int-set-1.hpp:155
void subscribe(Space &home, Propagator &p, IntSet &y)
Definition: rel.hpp:71
Range iterator for union of iterators.
const Gecode::PropCond PC_INT_DOM
Propagate when domain changes.
Definition: var-type.hpp:100
Integer sets.
Definition: int.hh:174
Post propagator for SetVar SetOpType SetVar SetRelType SetVar z
Definition: set.hh:767
#define GECODE_ME_CHECK(me)
Check whether modification event me is failed, and forward failure.
Definition: macros.hpp:52
Zero integer view.
Definition: view.hpp:1014
union Gecode::@593::NNF::@62 u
Union depending on nodetype t.
Post propagator for SetVar SetOpType SetVar SetRelType r
Definition: set.hh:767
Constant integer view.
Definition: view.hpp:851
Post propagator for SetVar SetOpType SetVar y
Definition: set.hh:767
ExecStatus
Definition: core.hpp:471
Binary disequality propagator.
Definition: rel.hh:460
Post propagator for SetVar x
Definition: set.hh:767
Execution is okay.
Definition: core.hpp:475
bool isintset(VY y)
Return whether y is an integer set.
Definition: rel.hpp:45
CompareStatus compare(I &i, J &j)
Check whether range iterator i is a subset of j, or whether they are disjoint.
Gecode toplevel namespace
ExecStatus post_false(Home home, VX x, ConstIntView y)
Definition: rel.hpp:194
static ExecStatus post(Home home, ViewArray< View > &x)
Post domain consistent propagator .
Definition: eq.hpp:270
void reschedule(Space &home, Propagator &p, IntSet &y)
Definition: rel.hpp:92
int size(void) const
Return size of array (number of elements)
Definition: array.hpp:1138
Home class for posting propagators
Definition: core.hpp:853
#define GECODE_NEVER
Assert that this command is never executed.
Definition: macros.hpp:56
Relation does hold.
Definition: view.hpp:1704
void update(IntSet &y, Space &home, IntSet &py)
Definition: rel.hpp:103
ExecStatus post_true(Home home, VX x, ConstIntView y)
Definition: rel.hpp:151