Generated on Tue Mar 24 2020 14:04:04 for Gecode by doxygen 1.8.17
re-prop.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, 2011
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 Member {
37 
38  template<class View, ReifyMode rm>
41  BoolView b0)
42  : Prop<View>(home,vs,x,y), b(b0) {
43  b.subscribe(home,*this,PC_BOOL_VAL);
44  }
45 
46  template<class View, ReifyMode rm>
47  inline ExecStatus
49  if (x.size() == 0) {
50  if (rm != RM_PMI)
51  GECODE_ME_CHECK(b.zero(home));
52  return ES_OK;
53  }
54 
55  x.unique();
56 
57  if (x.size() == 1)
58  return Rel::ReEqDom<View,BoolView,rm>::post(home,x[0],y,b);
59 
60  if (x.same(y)) {
61  if (rm != RM_IMP)
62  GECODE_ME_CHECK(b.one(home));
63  return ES_OK;
64  }
65 
66  // Eliminate assigned views and store them into the value set
67  ValSet vs;
68  add(home, vs, x);
69 
70  switch (vs.compare(y)) {
72  if (rm != RM_IMP)
73  GECODE_ME_CHECK(b.one(home));
74  return ES_OK;
76  if (x.size() == 0) {
77  if (rm != RM_PMI)
78  GECODE_ME_CHECK(b.zero(home));
79  return ES_OK;
80  }
81  break;
83  break;
84  default:
86  }
87 
88  (void) new (home) ReProp<View,rm>(home, vs, x, y, b);
89  return ES_OK;
90  }
91 
92  template<class View, ReifyMode rm>
95  : Prop<View>(home, p) {
96  b.update(home, p.b);
97  }
98 
99  template<class View, ReifyMode rm>
100  Propagator*
102  return new (home) ReProp<View,rm>(home, *this);
103  }
104 
105  template<class View, ReifyMode rm>
106  forceinline size_t
108  b.cancel(home, *this, PC_BOOL_VAL);
109  (void) Prop<View>::dispose(home);
110  return sizeof(*this);
111  }
112 
113  template<class View, ReifyMode rm>
114  ExecStatus
116  // Add assigned views to value set
117  if (View::me(med) == ME_INT_VAL)
118  add(home,vs,x);
119 
120  if (b.one()) {
121  if (rm == RM_PMI)
122  return home.ES_SUBSUMED(*this);
123  ValSet vsc(vs);
124  vs.flush();
125  GECODE_REWRITE(*this,Prop<View>::post(home(*this),vsc,x,y));
126  }
127 
128  if (b.zero()) {
129  if (rm != RM_IMP) {
130  ValSet::Ranges vsr(vs);
131  GECODE_ME_CHECK(y.minus_r(home,vsr,false));
132  for (int i=0; i<x.size(); i++)
134  }
135  return home.ES_SUBSUMED(*this);
136  }
137 
138  // Eliminate views from x
139  eliminate(home);
140 
141  switch (vs.compare(y)) {
143  if (rm != RM_IMP)
144  GECODE_ME_CHECK(b.one(home));
145  return home.ES_SUBSUMED(*this);
147  if (x.size() == 0) {
148  if (rm != RM_PMI)
149  GECODE_ME_CHECK(b.zero(home));
150  return home.ES_SUBSUMED(*this);
151  }
152  break;
154  break;
155  default:
156  GECODE_NEVER;
157  }
158 
159  // Check whether y is in union of x and value set
160  if (x.size() > 0) {
161  Region r;
162 
163  ValSet::Ranges vsr(vs);
164  ViewRanges<View> xsr(x[0]);
165  Iter::Ranges::NaryUnion u(r,vsr,xsr);
166  for (int i=1; i<x.size(); i++) {
167  ViewRanges<View> xir(x[i]);
168  u |= xir;
169  }
170 
171  ViewRanges<View> yr(y);
172 
173  if (Iter::Ranges::disjoint(u,yr)) {
174  if (rm != RM_PMI)
175  GECODE_ME_CHECK(b.zero(home));
176  return home.ES_SUBSUMED(*this);
177  }
178  }
179 
180  return ES_FIX;
181  }
182 
183 }}}
184 
185 // STATISTICS: int-prop
Post propagator for SetVar x
Definition: set.hh:767
const Gecode::PropCond PC_BOOL_VAL
Propagate when a view becomes assigned (single value)
Definition: var-type.hpp:126
Post propagator for SetVar SetOpType SetVar y
Definition: set.hh:767
@ RM_PMI
Inverse implication for reification.
Definition: int.hh:869
ExecStatus ES_SUBSUMED(Propagator &p)
Definition: core.hpp:3563
@ CS_NONE
Neither of the above.
Class for storing values of already assigned views.
Definition: val-set.hh:44
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition: re-prop.hpp:115
void subscribe(Space &home, Propagator &p, PropCond pc, bool schedule=true)
Subscribe propagator p with propagation condition pc to view.
Definition: view.hpp:521
@ RM_IMP
Implication for reification.
Definition: int.hh:862
bool disjoint(I &i, J &j)
Check whether range iterators i and j are disjoint.
static ExecStatus post(Home home, View x0, View x1, CtrlView b)
Post domain consistent propagator .
Definition: eq.hpp:494
Computation spaces.
Definition: core.hpp:1742
void update(Space &home, VarImpView< Var > &y)
Update this view to be a clone of view y.
Definition: view.hpp:567
Binary disequality propagator.
Definition: rel.hh:460
const Gecode::ModEvent ME_INT_VAL
Domain operation has resulted in a value (assigned variable)
Definition: var-type.hpp:56
void eliminate(Term< BoolView > *t, int &n, long long int &d)
Eliminate assigned views.
Definition: bool-post.cpp:43
Boolean view for Boolean variables.
Definition: view.hpp:1380
Gecode toplevel namespace
Base-class for propagators.
Definition: core.hpp:1064
union Gecode::@602::NNF::@65 u
Union depending on nodetype t.
@ CS_SUBSET
First is subset of second iterator.
Range iterator for integer views.
Definition: view.hpp:54
Iterator over ranges.
Definition: val-set.hh:78
#define GECODE_ES_CHECK(es)
Check whether execution status es is failed or subsumed, and forward failure or subsumption.
Definition: macros.hpp:91
virtual size_t dispose(Space &home)
Delete propagator and return its size.
Definition: re-prop.hpp:107
Home class for posting propagators
Definition: core.hpp:856
Handle to region.
Definition: region.hpp:55
Post propagator for SetVar SetOpType SetVar SetRelType r
Definition: set.hh:767
struct Gecode::@602::NNF::@65::@66 b
For binary nodes (and, or, eqv)
Range iterator for union of iterators.
ReProp(Home home, ValSet &vs, ViewArray< View > &x, View y, BoolView b)
Constructor for posting.
Definition: re-prop.hpp:40
#define GECODE_NEVER
Assert that this command is never executed.
Definition: macros.hpp:56
Iter::Ranges::CompareStatus compare(View x) const
Compare view x with value set.
Definition: val-set.hpp:161
BoolView b
Boolean control variable.
Definition: member.hh:98
@ ES_FIX
Propagation has computed fixpoint.
Definition: core.hpp:477
virtual Propagator * copy(Space &home)
Copy propagator during cloning.
Definition: re-prop.hpp:101
#define forceinline
Definition: config.hpp:185
#define GECODE_ME_CHECK(me)
Check whether modification event me is failed, and forward failure.
Definition: macros.hpp:52
View arrays.
Definition: array.hpp:253
int ModEventDelta
Modification event deltas.
Definition: core.hpp:89
static ExecStatus post(Home home, ViewArray< View > &x, View y, BoolView b)
Post propagator for .
Definition: re-prop.hpp:48
Gecode::IntArgs i({1, 2, 3, 4})
#define GECODE_REWRITE(prop, post)
Rewrite propagator by executing post function.
Definition: macros.hpp:116
@ ES_OK
Execution is okay.
Definition: core.hpp:476
int p
Number of positive literals for node type.
Definition: bool-expr.cpp:232
Membership propagator.
Definition: member.hh:54
@ CS_DISJOINT
Intersection is empty.
ExecStatus
Definition: core.hpp:472
Reified membership propagator.
Definition: member.hh:90