Generated on Sat Feb 7 2015 02:01:24 for Gecode by doxygen 1.8.9.1
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  * 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 Member {
41 
42  template<class View, ReifyMode rm>
45  BoolView b0)
46  : Prop<View>(home,vs,x,y), b(b0) {
47  b.subscribe(home,*this,PC_BOOL_VAL);
48  }
49 
50  template<class View, ReifyMode rm>
51  inline ExecStatus
53  if (x.size() == 0) {
54  if (rm != RM_PMI)
55  GECODE_ME_CHECK(b.zero(home));
56  return ES_OK;
57  }
58 
59  x.unique(home);
60 
61  if (x.size() == 1)
62  return Rel::ReEqDom<View,BoolView,rm>::post(home,x[0],y,b);
63 
64  if (x.same(home,y)) {
65  if (rm != RM_IMP)
66  GECODE_ME_CHECK(b.one(home));
67  return ES_OK;
68  }
69 
70  // Eliminate assigned views and store them into the value set
71  ValSet vs;
72  add(home, vs, x);
73 
74  switch (vs.compare(y)) {
76  if (rm != RM_IMP)
77  GECODE_ME_CHECK(b.one(home));
78  return ES_OK;
80  if (x.size() == 0) {
81  if (rm != RM_PMI)
82  GECODE_ME_CHECK(b.zero(home));
83  return ES_OK;
84  }
85  break;
87  break;
88  default:
90  }
91 
92  (void) new (home) ReProp<View,rm>(home, vs, x, y, b);
93  return ES_OK;
94  }
95 
96  template<class View, ReifyMode rm>
99  : Prop<View>(home, share, p) {
100  b.update(home, share, p.b);
101  }
102 
103  template<class View, ReifyMode rm>
104  Propagator*
105  ReProp<View,rm>::copy(Space& home, bool share) {
106  return new (home) ReProp<View,rm>(home, share, *this);
107  }
108 
109  template<class View, ReifyMode rm>
110  forceinline size_t
112  b.cancel(home, *this, PC_BOOL_VAL);
113  (void) Prop<View>::dispose(home);
114  return sizeof(*this);
115  }
116 
117  template<class View, ReifyMode rm>
118  ExecStatus
120  // Add assigned views to value set
121  if (View::me(med) == ME_INT_VAL)
122  add(home,vs,x);
123 
124  if (b.one()) {
125  if (rm == RM_PMI)
126  return home.ES_SUBSUMED(*this);
127  ValSet vsc(vs);
128  vs.flush();
129  GECODE_REWRITE(*this,Prop<View>::post(home,vsc,x,y));
130  }
131 
132  if (b.zero()) {
133  if (rm != RM_IMP) {
134  ValSet::Ranges vsr(vs);
135  GECODE_ME_CHECK(y.minus_r(home,vsr,false));
136  for (int i=x.size(); i--; )
138  }
139  return home.ES_SUBSUMED(*this);
140  }
141 
142  // Eliminate views from x
143  eliminate(home);
144 
145  switch (vs.compare(y)) {
147  if (rm != RM_IMP)
148  GECODE_ME_CHECK(b.one(home));
149  return home.ES_SUBSUMED(*this);
151  if (x.size() == 0) {
152  if (rm != RM_PMI)
153  GECODE_ME_CHECK(b.zero(home));
154  return home.ES_SUBSUMED(*this);
155  }
156  break;
158  break;
159  default:
160  GECODE_NEVER;
161  }
162 
163  // Check whether y is in union of x and value set
164  if (x.size() > 0) {
165  Region r(home);
166 
167  ValSet::Ranges vsr(vs);
168  ViewRanges<View> xsr(x[x.size()-1]);
169  Iter::Ranges::NaryUnion u(r,vsr,xsr);
170  for (int i=x.size()-1; i--; ) {
171  ViewRanges<View> xir(x[i]);
172  u |= xir;
173  }
174 
175  ViewRanges<View> yr(y);
176 
177  if (Iter::Ranges::disjoint(u,yr)) {
178  if (rm != RM_PMI)
179  GECODE_ME_CHECK(b.zero(home));
180  return home.ES_SUBSUMED(*this);
181  }
182  }
183 
184  return ES_FIX;
185  }
186 
187 }}}
188 
189 // STATISTICS: int-prop
#define GECODE_REWRITE(prop, post)
Rewrite propagator by executing post function.
Definition: macros.hpp:109
Reified membership propagator.
Definition: member.hh:94
Inverse implication for reification.
Definition: int.hh:847
void eliminate(Term< BoolView > *t, int &n, long long int &d)
Eliminate assigned views.
Definition: bool-post.cpp:62
ExecStatus ES_SUBSUMED(Propagator &p)
Definition: core.hpp:2973
First is subset of second iterator.
Base-class for propagators.
Definition: core.hpp:755
Membership propagator.
Definition: member.hh:58
Handle to region.
Definition: region.hpp:61
Propagation has computed fixpoint.
Definition: core.hpp:528
void unique(const Space &home)
Remove all duplicate views from array (changes element order)
Definition: array.hpp:1498
Computation spaces.
Definition: core.hpp:1362
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
static ExecStatus post(Home home, ViewArray< View > &x, View y, BoolView b)
Post propagator for .
Definition: re-prop.hpp:52
void subscribe(Space &home, Propagator &p, PropCond pc, bool schedule=true)
Subscribe propagator p with propagation condition pc to view.
Definition: view.hpp:453
int p
Number of positive literals for node type.
Definition: bool-expr.cpp:236
Gecode::IntArgs i(4, 1, 2, 3, 4)
BoolView b
Boolean control variable.
Definition: member.hh:102
NNF * r
Right subtree.
Definition: bool-expr.cpp:246
Iterator over ranges.
Definition: val-set.hh:82
virtual size_t dispose(Space &home)
Delete propagator and return its size.
Definition: re-prop.hpp:111
const Gecode::ModEvent ME_INT_VAL
Domain operation has resulted in a value (assigned variable)
Definition: var-type.hpp:56
Reified binary domain consistent equality propagator.
Definition: rel.hh:318
Range iterator for union of iterators.
Iter::Ranges::CompareStatus compare(View x) const
Compare view x with value set.
Definition: val-set.hpp:166
View arrays.
Definition: array.hpp:234
void update(Space &home, bool share, VarImpView< Var > &y)
Update this view to be a clone of view y.
Definition: view.hpp:494
#define GECODE_ME_CHECK(me)
Check whether modification event me is failed, and forward failure.
Definition: macros.hpp:45
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition: re-prop.hpp:119
union Gecode::@518::NNF::@57 u
Union depending on nodetype t.
bool one(void) const
Test whether view is assigned to be one.
Definition: bool.hpp:218
Node * x
Pointer to corresponding Boolean expression node.
Definition: bool-expr.cpp:253
ExecStatus
Definition: core.hpp:523
bool disjoint(I &i, J &j)
Check whether range iterators i and j are disjoint.
#define forceinline
Definition: config.hpp:132
bool same(const Space &home) const
Test whether array has multiple occurence of the same view.
Definition: array.hpp:1468
Binary disequality propagator.
Definition: rel.hh:432
Execution is okay.
Definition: core.hpp:527
virtual Propagator * copy(Space &home, bool share)
Copy propagator during cloning.
Definition: re-prop.hpp:105
Class for storing values of already assigned views.
Definition: val-set.hh:48
int size(void) const
Return size of array (number of elements)
Definition: array.hpp:1215
struct Gecode::@518::NNF::@57::@58 b
For binary nodes (and, or, eqv)
Gecode toplevel namespace
Implication for reification.
Definition: int.hh:840
bool zero(void) const
Test whether view is assigned to be zero.
Definition: bool.hpp:214
int ModEventDelta
Modification event deltas.
Definition: core.hpp:173
ReProp(Home home, ValSet &vs, ViewArray< View > &x, View y, BoolView b)
Constructor for posting.
Definition: re-prop.hpp:44
Home class for posting propagators
Definition: core.hpp:717
#define GECODE_NEVER
Assert that this command is never executed.
Definition: macros.hpp:60
const Gecode::PropCond PC_BOOL_VAL
Propagate when a view becomes assigned (single value)
Definition: var-type.hpp:126
Boolean view for Boolean variables.
Definition: view.hpp:1315