Generated on Thu Apr 5 2018 19:44:19 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  * Last modified:
10  * $Date$ by $Author$
11  * $Revision$
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 #include <gecode/int/rel.hh>
39 
40 namespace Gecode { namespace Int { namespace Count {
41 
42  /*
43  * Counting domain consistent equality
44  *
45  */
46 
47  template<class VY>
48  forceinline bool
49  isintset(VY y) {
50  (void) y;
51  return false;
52  }
53  template<>
54  forceinline bool
56  (void) y;
57  return true;
58  }
59 
60 
61  template<class VY>
62  forceinline bool
63  isval(VY y) {
64  return y.assigned();
65  }
66  template<>
67  forceinline bool
69  (void) y;
70  return true;
71  }
72 
73 
74  forceinline void
76  (void) home; (void) p; (void) y;
77  }
78  template<class VY>
79  forceinline void
80  subscribe(Space& home, Propagator& p, VY y) {
81  y.subscribe(home, p, PC_INT_DOM);
82  }
83 
84  forceinline void
86  (void) home; (void) p;
87  y.~IntSet();
88  }
89  template<class VY>
90  forceinline void
91  cancel(Space& home, Propagator& p, VY y) {
92  y.cancel(home, p, PC_INT_DOM);
93  }
94 
95  forceinline void
97  (void) home; (void) p; (void) y;
98  }
99  template<class VY>
100  forceinline void
101  reschedule(Space& home, Propagator& p, VY y) {
102  (void) y; // To satisy MSVC
103  y.schedule(home, p, PC_INT_DOM);
104  }
105 
106  forceinline void
107  update(IntSet& y, Space& home, IntSet& py) {
108  (void) home;
109  y=py;
110  }
111  template<class VY>
112  forceinline void
113  update(VY& y, Space& home, VY py) {
114  y.update(home, py);
115  }
116 
117  template<class VX>
120  return rtest_eq_dom(x,y.val());
121  }
122  template<class VX>
125  return rtest_eq_dom(x,0);
126  }
127  template<class VX>
129  holds(VX x, const IntSet& y) {
130  if ((x.max() < y.min()) || (y.max() < x.min()))
131  return RT_FALSE;
132  ViewRanges<VX> rx(x);
133  IntSetRanges ry(y);
134  switch (Iter::Ranges::compare(rx,ry)) {
136  return RT_TRUE;
138  return RT_FALSE;
140  return RT_MAYBE;
141  default:
142  GECODE_NEVER;
143  }
144  GECODE_NEVER;
145  return RT_MAYBE;
146  }
147  template<class VX>
149  holds(VX x, VX y) {
150  return rtest_eq_dom(x,y);
151  }
152 
153  template<class VX>
156  GECODE_ME_CHECK(x.eq(home,y.val()));
157  return ES_OK;
158  }
159  template<class VX>
162  GECODE_ME_CHECK(x.eq(home,0));
163  return ES_OK;
164  }
165  template<class VX>
167  post_true(Home home, VX x, const IntSet& y) {
168  IntSetRanges ry(y);
169  GECODE_ME_CHECK(x.inter_r(home,ry,false));
170  return ES_OK;
171  }
172  template<class VX>
175  for (int i = x.size(); i--; )
176  GECODE_ME_CHECK(x[i].eq(home,y.val()));
177  return ES_OK;
178  }
179  template<class VX>
182  for (int i = x.size(); i--; )
183  GECODE_ME_CHECK(x[i].eq(home,0));
184  return ES_OK;
185  }
186  template<class VX>
188  post_true(Home home, ViewArray<VX>& x, const IntSet& y) {
189  for (int i = x.size(); i--; ) {
190  IntSetRanges ry(y);
191  GECODE_ME_CHECK(x[i].inter_r(home,ry,false));
192  }
193  return ES_OK;
194  }
195 
196  template<class VX>
199  GECODE_ME_CHECK(x.nq(home,y.val()));
200  return ES_OK;
201  }
202  template<class VX>
205  GECODE_ME_CHECK(x.nq(home,0));
206  return ES_OK;
207  }
208  template<class VX>
210  post_false(Home home, VX x, const IntSet& y) {
211  IntSetRanges ry(y);
212  GECODE_ME_CHECK(x.minus_r(home,ry,false));
213  return ES_OK;
214  }
215  template<class VX>
218  for (int i = x.size(); i--; )
219  GECODE_ME_CHECK(x[i].nq(home,y.val()));
220  return ES_OK;
221  }
222  template<class VX>
225  for (int i = x.size(); i--; )
226  GECODE_ME_CHECK(x[i].nq(home,0));
227  return ES_OK;
228  }
229  template<class VX>
231  post_false(Home home, ViewArray<VX>& x, const IntSet& y) {
232  for (int i = x.size(); i--; ) {
233  IntSetRanges ry(y);
234  GECODE_ME_CHECK(x[i].minus_r(home,ry,false));
235  }
236  return ES_OK;
237  }
238 
239  template<class VX>
242  ViewArray<VX> z(home,x.size()+1);
243  z[x.size()] = y;
244  for (int i = x.size(); i--; )
245  z[i] = x[i];
246  return Rel::NaryEqDom<VX>::post(home,z);
247  }
248  template<class VX>
250  post_true(Home home, VX x, VX y) {
251  return Rel::EqDom<VX,VX>::post(home,x,y);
252  }
253  template<class VX>
256  for (int i = x.size(); i--; )
257  GECODE_ES_CHECK((Rel::Nq<VX,VX>::post(home,x[i],y)));
258  return ES_OK;
259  }
260  template<class VX>
262  post_false(Home home, VX x, VX y) {
263  return Rel::Nq<VX,VX>::post(home,x,y);
264  }
265 
266  template<class VX>
269  (void) home;
270  (void) x;
271  return ES_OK;
272  }
273  template<class VX>
276  (void) home;
277  (void) x;
278  return ES_OK;
279  }
280  template<class VX>
282  prune(Space& home, ViewArray<VX>& x, const IntSet& y) {
283  (void) home;
284  (void) x;
285  (void) y;
286  return ES_OK;
287  }
288  template<class VX>
290  prune(Space& home, ViewArray<VX>& x, VX y) {
291  if (x.size() == 0)
292  return ES_OK;
293  Region r;
294  ViewRanges<VX>* rx = r.alloc<ViewRanges<VX> >(x.size());
295  for (int i=x.size(); i--; )
296  rx[i] = ViewRanges<VX>(x[i]);
297  Iter::Ranges::NaryUnion u(r, rx, x.size());
298  GECODE_ME_CHECK(y.inter_r(home, u, false));
299  return ES_OK;
300  }
301 
302 }}}
303 
304 // STATISTICS: int-prop
Relation may hold or not.
Definition: view.hpp:1634
static ExecStatus post(Home home, V0 x0, V1 x1)
Post propagator .
Definition: nq.hpp:53
Range iterator for integer sets.
Definition: int.hh:272
RelTest rtest_eq_dom(VX x, VY y)
Test whether views x and y are equal (use full domain information)
Definition: rel-test.hpp:69
void cancel(Space &home, Propagator &p, IntSet &y)
Definition: rel.hpp:85
T * alloc(long unsigned int n)
Allocate block of n objects of type T from region.
Definition: region.hpp:384
RelTest holds(VX x, ConstIntView y)
Test whether x and y are equal.
Definition: rel.hpp:119
static ExecStatus post(Home home, View0 x0, View1 x1)
Post domain consistent propagator .
Definition: eq.hpp:180
First is subset of second iterator.
Base-class for propagators.
Definition: core.hpp:1016
bool isval(VY y)
Return whether y is a value.
Definition: rel.hpp:63
Handle to region.
Definition: region.hpp:57
#define forceinline
Definition: config.hpp:182
Computation spaces.
Definition: core.hpp:1668
ExecStatus prune(Space &home, ViewArray< VX > &x, ConstIntView)
Definition: rel.hpp:268
int min(int i) const
Return minimum of range at position i.
Definition: int-set-1.hpp:115
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:95
int p
Number of positive literals for node type.
Definition: bool-expr.cpp:236
Gecode::IntArgs i(4, 1, 2, 3, 4)
int val(void) const
Return assigned value (only if assigned)
Definition: constint.hpp:66
Relation does not hold.
Definition: view.hpp:1633
RelTest
Result of testing relation.
Definition: view.hpp:1632
int max(int i) const
Return maximum of range at position i.
Definition: int-set-1.hpp:121
void subscribe(Space &home, Propagator &p, IntSet &y)
Definition: rel.hpp:75
Range iterator for union of iterators.
const Gecode::PropCond PC_INT_DOM
Propagate when domain changes.
Definition: var-type.hpp:100
union Gecode::@585::NNF::@62 u
Union depending on nodetype t.
Integer sets.
Definition: int.hh:174
Post propagator for SetVar SetOpType SetVar SetRelType SetVar z
Definition: set.hh:769
#define GECODE_ME_CHECK(me)
Check whether modification event me is failed, and forward failure.
Definition: macros.hpp:56
Zero integer view.
Definition: view.hpp:969
Post propagator for SetVar SetOpType SetVar SetRelType r
Definition: set.hh:769
Constant integer view.
Definition: view.hpp:812
Post propagator for SetVar SetOpType SetVar y
Definition: set.hh:769
ExecStatus
Definition: core.hpp:464
Binary disequality propagator.
Definition: rel.hh:464
Post propagator for SetVar x
Definition: set.hh:769
Execution is okay.
Definition: core.hpp:468
bool isintset(VY y)
Return whether y is an integer set.
Definition: rel.hpp:49
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:198
static ExecStatus post(Home home, ViewArray< View > &x)
Post domain consistent propagator .
Definition: eq.hpp:274
void reschedule(Space &home, Propagator &p, IntSet &y)
Definition: rel.hpp:96
int size(void) const
Return size of array (number of elements)
Definition: array.hpp:1203
Home class for posting propagators
Definition: core.hpp:846
#define GECODE_NEVER
Assert that this command is never executed.
Definition: macros.hpp:60
Relation does hold.
Definition: view.hpp:1635
void update(IntSet &y, Space &home, IntSet &py)
Definition: rel.hpp:107
ExecStatus post_true(Home home, VX x, ConstIntView y)
Definition: rel.hpp:155