Generated on Thu Jan 31 2019 20:56:35 for Gecode by doxygen 1.8.15
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: 2016-11-08 17:23:24 +0100 (Tue, 08 Nov 2016) $ by $Author: schulte $
11  * $Revision: 15253 $
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  template<class VX>
109  return rtest_eq_dom(x,y.val());
110  }
111  template<class VX>
114  return rtest_eq_dom(x,0);
115  }
116  template<class VX>
118  holds(VX x, const IntSet& y) {
119  if ((x.max() < y.min()) || (y.max() < x.min()))
120  return RT_FALSE;
121  ViewRanges<VX> rx(x);
122  IntSetRanges ry(y);
123  switch (Iter::Ranges::compare(rx,ry)) {
125  return RT_TRUE;
127  return RT_FALSE;
129  return RT_MAYBE;
130  default:
131  GECODE_NEVER;
132  }
133  GECODE_NEVER;
134  return RT_MAYBE;
135  }
136  template<class VX>
138  holds(VX x, VX y) {
139  return rtest_eq_dom(x,y);
140  }
141 
142  template<class VX>
145  GECODE_ME_CHECK(x.eq(home,y.val()));
146  return ES_OK;
147  }
148  template<class VX>
151  GECODE_ME_CHECK(x.eq(home,0));
152  return ES_OK;
153  }
154  template<class VX>
156  post_true(Home home, VX x, const IntSet& y) {
157  IntSetRanges ry(y);
158  GECODE_ME_CHECK(x.inter_r(home,ry,false));
159  return ES_OK;
160  }
161  template<class VX>
164  for (int i = x.size(); i--; )
165  GECODE_ME_CHECK(x[i].eq(home,y.val()));
166  return ES_OK;
167  }
168  template<class VX>
171  for (int i = x.size(); i--; )
172  GECODE_ME_CHECK(x[i].eq(home,0));
173  return ES_OK;
174  }
175  template<class VX>
177  post_true(Home home, ViewArray<VX>& x, const IntSet& y) {
178  for (int i = x.size(); i--; ) {
179  IntSetRanges ry(y);
180  GECODE_ME_CHECK(x[i].inter_r(home,ry,false));
181  }
182  return ES_OK;
183  }
184 
185  template<class VX>
188  GECODE_ME_CHECK(x.nq(home,y.val()));
189  return ES_OK;
190  }
191  template<class VX>
194  GECODE_ME_CHECK(x.nq(home,0));
195  return ES_OK;
196  }
197  template<class VX>
199  post_false(Home home, VX x, const IntSet& y) {
200  IntSetRanges ry(y);
201  GECODE_ME_CHECK(x.minus_r(home,ry,false));
202  return ES_OK;
203  }
204  template<class VX>
207  for (int i = x.size(); i--; )
208  GECODE_ME_CHECK(x[i].nq(home,y.val()));
209  return ES_OK;
210  }
211  template<class VX>
214  for (int i = x.size(); i--; )
215  GECODE_ME_CHECK(x[i].nq(home,0));
216  return ES_OK;
217  }
218  template<class VX>
220  post_false(Home home, ViewArray<VX>& x, const IntSet& y) {
221  for (int i = x.size(); i--; ) {
222  IntSetRanges ry(y);
223  GECODE_ME_CHECK(x[i].minus_r(home,ry,false));
224  }
225  return ES_OK;
226  }
227 
228  template<class VX>
231  ViewArray<VX> z(home,x.size()+1);
232  z[x.size()] = y;
233  for (int i = x.size(); i--; )
234  z[i] = x[i];
235  return Rel::NaryEqDom<VX>::post(home,z);
236  }
237  template<class VX>
239  post_true(Home home, VX x, VX y) {
240  return Rel::EqDom<VX,VX>::post(home,x,y);
241  }
242  template<class VX>
245  for (int i = x.size(); i--; )
247  return ES_OK;
248  }
249  template<class VX>
251  post_false(Home home, VX x, VX y) {
252  return Rel::Nq<VX,VX>::post(home,x,y);
253  }
254 
255  template<class VX>
258  (void) home;
259  (void) x;
260  return ES_OK;
261  }
262  template<class VX>
265  (void) home;
266  (void) x;
267  return ES_OK;
268  }
269  template<class VX>
271  prune(Space& home, ViewArray<VX>& x, const IntSet& y) {
272  (void) home;
273  (void) x;
274  (void) y;
275  return ES_OK;
276  }
277  template<class VX>
279  prune(Space& home, ViewArray<VX>& x, VX y) {
280  if (x.size() == 0)
281  return ES_OK;
282  Region r(home);
283  ViewRanges<VX>* rx = r.alloc<ViewRanges<VX> >(x.size());
284  for (int i=x.size(); i--; )
285  rx[i] = ViewRanges<VX>(x[i]);
286  Iter::Ranges::NaryUnion u(r, rx, x.size());
287  GECODE_ME_CHECK(y.inter_r(home, u, false));
288  return ES_OK;
289  }
290 
291 }}}
292 
293 // STATISTICS: int-prop
Relation may hold or not.
Definition: view.hpp:1616
static ExecStatus post(Home home, V0 x0, V1 x1)
Post propagator .
Definition: nq.hpp:53
union Gecode::@579::NNF::@61 u
Union depending on nodetype t.
Range iterator for integer sets.
Definition: int.hh:274
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
bool assigned(void) const
Test whether view is assigned.
Definition: var.hpp:123
RelTest holds(VX x, ConstIntView y)
Test whether x and y are equal.
Definition: rel.hpp:108
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:1092
bool isval(VY y)
Return whether y is a value.
Definition: rel.hpp:63
Handle to region.
Definition: region.hpp:61
Computation spaces.
Definition: core.hpp:1748
ExecStatus prune(Space &home, ViewArray< VX > &x, ConstIntView)
Definition: rel.hpp:257
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)
Relation does not hold.
Definition: view.hpp:1615
RelTest
Result of testing relation.
Definition: view.hpp:1614
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
Integer sets.
Definition: int.hh:174
Post propagator for SetVar SetOpType SetVar SetRelType SetVar z
Definition: set.hh:784
#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:959
Post propagator for SetVar SetOpType SetVar SetRelType r
Definition: set.hh:784
Constant integer view.
Definition: view.hpp:804
Post propagator for SetVar SetOpType SetVar y
Definition: set.hh:784
ExecStatus
Definition: core.hpp:540
#define forceinline
Definition: config.hpp:173
Binary disequality propagator.
Definition: rel.hh:464
Post propagator for SetVar x
Definition: set.hh:784
Execution is okay.
Definition: core.hpp:544
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:187
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
Home class for posting propagators
Definition: core.hpp:922
#define GECODE_NEVER
Assert that this command is never executed.
Definition: macros.hpp:60
Relation does hold.
Definition: view.hpp:1617
ExecStatus post_true(Home home, VX x, ConstIntView y)
Definition: rel.hpp:144