Generated on Sat Feb 7 2015 02:01:21 for Gecode by doxygen 1.8.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  * Last modified:
10  * $Date: 2012-09-07 17:31:22 +0200 (Fri, 07 Sep 2012) $ by $Author: schulte $
11  * $Revision: 13068 $
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>
49  vtd(VY y) {
50  (void) y;
51  return VTD_VARVIEW;
52  }
53  template<>
55  vtd(const IntSet& y) {
56  (void) y;
57  return VTD_INTSET;
58  }
59  template<>
62  (void) y;
63  return VTD_CONSTVIEW;
64  }
65  template<>
68  (void) y;
69  return VTD_CONSTVIEW;
70  }
71 
72 
73  forceinline void
75  (void) home; (void) p; (void) y;
76  }
77  template<class VY>
78  forceinline void
79  subscribe(Space& home, Propagator& p, VY y) {
80  y.subscribe(home, p, PC_INT_DOM);
81  }
82 
83  forceinline void
84  cancel(Space& home, Propagator& p, IntSet& y) {
85  (void) home; (void) p;
86  y.~IntSet();
87  }
88  template<class VY>
89  forceinline void
90  cancel(Space& home, Propagator& p, VY y) {
91  y.cancel(home, p, PC_INT_DOM);
92  }
93 
94  template<class VX>
96  holds(VX x, ConstIntView y) {
97  return rtest_eq_dom(x,y.val());
98  }
99  template<class VX>
102  return rtest_eq_dom(x,0);
103  }
104  template<class VX>
106  holds(VX x, const IntSet& y) {
107  if ((x.max() < y.min()) || (y.max() < x.min()))
108  return RT_FALSE;
109  ViewRanges<VX> rx(x);
110  IntSetRanges ry(y);
111  switch (Iter::Ranges::compare(rx,ry)) {
113  return RT_TRUE;
115  return RT_FALSE;
117  return RT_MAYBE;
118  default:
119  GECODE_NEVER;
120  }
121  GECODE_NEVER;
122  return RT_MAYBE;
123  }
124  template<class VX>
126  holds(VX x, VX y) {
127  return rtest_eq_dom(x,y);
128  }
129 
130  template<class VX>
132  post_true(Home home, VX x, ConstIntView y) {
133  GECODE_ME_CHECK(x.eq(home,y.val()));
134  return ES_OK;
135  }
136  template<class VX>
139  GECODE_ME_CHECK(x.eq(home,0));
140  return ES_OK;
141  }
142  template<class VX>
144  post_true(Home home, VX x, const IntSet& y) {
145  IntSetRanges ry(y);
146  GECODE_ME_CHECK(x.inter_r(home,ry,false));
147  return ES_OK;
148  }
149  template<class VX>
152  for (int i = x.size(); i--; )
153  GECODE_ME_CHECK(x[i].eq(home,y.val()));
154  return ES_OK;
155  }
156  template<class VX>
159  for (int i = x.size(); i--; )
160  GECODE_ME_CHECK(x[i].eq(home,0));
161  return ES_OK;
162  }
163  template<class VX>
165  post_true(Home home, ViewArray<VX>& x, const IntSet& y) {
166  for (int i = x.size(); i--; ) {
167  IntSetRanges ry(y);
168  GECODE_ME_CHECK(x[i].inter_r(home,ry,false));
169  }
170  return ES_OK;
171  }
172 
173  template<class VX>
175  post_false(Home home, VX x, ConstIntView y) {
176  GECODE_ME_CHECK(x.nq(home,y.val()));
177  return ES_OK;
178  }
179  template<class VX>
182  GECODE_ME_CHECK(x.nq(home,0));
183  return ES_OK;
184  }
185  template<class VX>
187  post_false(Home home, VX x, const IntSet& y) {
188  IntSetRanges ry(y);
189  GECODE_ME_CHECK(x.minus_r(home,ry,false));
190  return ES_OK;
191  }
192  template<class VX>
195  for (int i = x.size(); i--; )
196  GECODE_ME_CHECK(x[i].nq(home,y.val()));
197  return ES_OK;
198  }
199  template<class VX>
202  for (int i = x.size(); i--; )
203  GECODE_ME_CHECK(x[i].nq(home,0));
204  return ES_OK;
205  }
206  template<class VX>
208  post_false(Home home, ViewArray<VX>& x, const IntSet& y) {
209  for (int i = x.size(); i--; ) {
210  IntSetRanges ry(y);
211  GECODE_ME_CHECK(x[i].minus_r(home,ry,false));
212  }
213  return ES_OK;
214  }
215 
216  template<class VX>
218  post_true(Home home, ViewArray<VX>& x, VX y) {
219  ViewArray<VX> z(home,x.size()+1);
220  z[x.size()] = y;
221  for (int i = x.size(); i--; )
222  z[i] = x[i];
223  return Rel::NaryEqDom<VX>::post(home,z);
224  }
225  template<class VX>
227  post_true(Home home, VX x, VX y) {
228  return Rel::EqDom<VX,VX>::post(home,x,y);
229  }
230  template<class VX>
232  post_false(Home home, ViewArray<VX>& x, VX y) {
233  for (int i = x.size(); i--; )
234  GECODE_ES_CHECK(Rel::Nq<VX>::post(home,x[i],y));
235  return ES_OK;
236  }
237  template<class VX>
239  post_false(Home home, VX x, VX y) {
240  return Rel::Nq<VX>::post(home,x,y);
241  }
242 
243  template<class VX>
246  (void) home;
247  (void) x;
248  return ES_OK;
249  }
250  template<class VX>
253  (void) home;
254  (void) x;
255  return ES_OK;
256  }
257  template<class VX>
259  prune(Space& home, ViewArray<VX>& x, const IntSet& y) {
260  (void) home;
261  (void) x;
262  (void) y;
263  return ES_OK;
264  }
265  template<class VX>
267  prune(Space& home, ViewArray<VX>& x, VX y) {
268  if (x.size() == 0)
269  return ES_OK;
270  Region r(home);
271  ViewRanges<VX>* rx = r.alloc<ViewRanges<VX> >(x.size());
272  for (int i=x.size(); i--; )
273  rx[i] = ViewRanges<VX>(x[i]);
274  Iter::Ranges::NaryUnion u(r, rx, x.size());
275  GECODE_ME_CHECK(y.inter_r(home, u, false));
276  return ES_OK;
277  }
278 
279 }}}
280 
281 // STATISTICS: int-prop
Relation may hold or not.
Definition: view.hpp:1616
Range iterator for integer sets.
Definition: int.hh:271
void cancel(Space &home, Propagator &p, IntSet &y)
Definition: rel.hpp:84
T * alloc(long unsigned int n)
Allocate block of n objects of type T from region.
Definition: region.hpp:326
RelTest holds(VX x, ConstIntView y)
Test whether x and y are equal.
Definition: rel.hpp:96
static ExecStatus post(Home home, View0 x0, View1 x1)
Post domain consistent propagator .
Definition: eq.hpp:120
First is subset of second iterator.
Base-class for propagators.
Definition: core.hpp:755
ViewTypeDesc
Description of view type.
Definition: count.hh:58
Handle to region.
Definition: region.hpp:61
Computation spaces.
Definition: core.hpp:1362
ExecStatus prune(Space &home, ViewArray< VX > &x, ConstIntView)
Definition: rel.hpp:245
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:84
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
NNF * r
Right subtree.
Definition: bool-expr.cpp:246
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:74
ViewTypeDesc vtd(VY y)
Return the view type description of y.
Definition: rel.hpp:49
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:171
#define GECODE_ME_CHECK(me)
Check whether modification event me is failed, and forward failure.
Definition: macros.hpp:45
RelTest rtest_eq_dom(View x, View y)
Test whether views x and y are equal (use full domain information)
Definition: rel-test.hpp:68
Zero integer view.
Definition: view.hpp:959
union Gecode::@518::NNF::@57 u
Union depending on nodetype t.
Constant integer view.
Definition: view.hpp:804
Node * x
Pointer to corresponding Boolean expression node.
Definition: bool-expr.cpp:253
ExecStatus
Definition: core.hpp:523
#define forceinline
Definition: config.hpp:132
Binary disequality propagator.
Definition: rel.hh:432
Execution is okay.
Definition: core.hpp:527
int size(void) const
Return size of array (number of elements)
Definition: array.hpp:1215
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:175
static ExecStatus post(Home home, ViewArray< View > &x)
Post domain consistent propagator .
Definition: eq.hpp:214
static ExecStatus post(Home home, View x0, View x1)
Post propagator .
Definition: nq.hpp:53
Home class for posting propagators
Definition: core.hpp:717
#define GECODE_NEVER
Assert that this command is never executed.
Definition: macros.hpp:60
Relation does hold.
Definition: view.hpp:1617
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
ExecStatus post_true(Home home, VX x, ConstIntView y)
Definition: rel.hpp:132