Generated on Tue Jan 28 2020 00:00:00 for Gecode by doxygen 1.8.17
re-lq.hpp
Go to the documentation of this file.
1 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2 /*
3  * Main authors:
4  * Guido Tack <tack@gecode.org>
5  *
6  * Copyright:
7  * Guido Tack, 2011
8  *
9  * Last modified:
10  * $Date: 2016-06-29 17:28:17 +0200 (Wed, 29 Jun 2016) $ by $Author: schulte $
11  * $Revision: 15137 $
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 namespace Gecode { namespace Set { namespace Rel {
39 
40  template<class View0, class View1, ReifyMode rm, bool strict>
42  ReLq<View0,View1,rm,strict>::ReLq(Home home, View0 y0, View1 y1,
44  : Propagator(home), x0(y0), x1(y1), b(y2) {
45  b.subscribe(home,*this, Gecode::Int::PC_INT_VAL);
46  x0.subscribe(home,*this, PC_SET_ANY);
47  x1.subscribe(home,*this, PC_SET_ANY);
48  }
49 
50  template<class View0, class View1, ReifyMode rm, bool strict>
53  : Propagator(home,share,p) {
54  x0.update(home,share,p.x0);
55  x1.update(home,share,p.x1);
56  b.update(home,share,p.b);
57  }
58 
59  template<class View0, class View1, ReifyMode rm, bool strict>
60  PropCost
62  {
64  }
65 
66  template<class View0, class View1, ReifyMode rm, bool strict>
67  void
69  b.reschedule(home,*this, Gecode::Int::PC_INT_VAL);
70  x0.reschedule(home,*this, PC_SET_ANY);
71  x1.reschedule(home,*this, PC_SET_ANY);
72  }
73 
74  template<class View0, class View1, ReifyMode rm, bool strict>
75  forceinline size_t
77  b.cancel(home,*this, Gecode::Int::PC_INT_VAL);
78  x0.cancel(home,*this, PC_SET_ANY);
79  x1.cancel(home,*this, PC_SET_ANY);
80  (void) Propagator::dispose(home);
81  return sizeof(*this);
82  }
83 
84  template<class View0, class View1, ReifyMode rm, bool strict>
86  ReLq<View0,View1,rm,strict>::post(Home home, View0 x0, View1 x1,
88  (void) new (home) ReLq<View0,View1,rm,strict>(home,x0,x1,b);
89  return ES_OK;
90  }
91 
92  template<class View0, class View1, ReifyMode rm, bool strict>
93  Actor*
95  return new (home) ReLq<View0,View1,rm,strict>(home,share,*this);
96  }
97 
98  template<class View0, class View1, ReifyMode rm, bool strict>
101  if (b.one()) {
102  if (rm == RM_PMI)
103  return home.ES_SUBSUMED(*this);
104  GECODE_REWRITE(*this,(Lq<View0,View1,strict>::post(home(*this),x0,x1)));
105  }
106  if (b.zero()) {
107  if (rm == RM_IMP)
108  return home.ES_SUBSUMED(*this);
109  GECODE_REWRITE(*this,
110  (Lq<View1,View0,!strict>::post(home(*this),x1,x0)));
111  }
112  if (x0.cardMax() == 0) {
113  if ( (!strict) || x1.cardMin() > 0) {
114  if (rm != RM_IMP)
115  GECODE_ME_CHECK(b.one_none(home));
116  return home.ES_SUBSUMED(*this);
117  }
118  if (strict && x1.cardMax() == 0) {
119  if (rm != RM_PMI)
120  GECODE_ME_CHECK(b.zero_none(home));
121  return home.ES_SUBSUMED(*this);
122  }
123  }
124 
125  if (x0.assigned() && x1.assigned()) {
126  // directly test x0<=x1
127  int min01;
128  {
129  GlbRanges<View0> x0l(x0);
130  GlbRanges<View1> x1l(x1);
132  if (!d()) {
133  if ((!strict) && x0.cardMax() == x1.cardMax()) {
134  // equal
135  if (rm != RM_IMP)
136  GECODE_ME_CHECK(b.one_none(home));
137  } else {
138  // subset
139  if (rm != RM_PMI)
140  GECODE_ME_CHECK(b.zero_none(home));
141  }
142  return home.ES_SUBSUMED(*this);
143  }
144  min01 = d.min();
145  }
146  int min10;
147  {
148  GlbRanges<View0> x0l(x0);
149  GlbRanges<View1> x1l(x1);
151  if (!d()) {
152  if (strict && x0.cardMax() == x1.cardMax()) {
153  // equal
154  if (rm != RM_PMI)
155  GECODE_ME_CHECK(b.zero_none(home));
156  } else {
157  // subset
158  if (rm != RM_IMP)
159  GECODE_ME_CHECK(b.one_none(home));
160  }
161  return home.ES_SUBSUMED(*this);
162  }
163  min10 = d.min();
164  }
165 
166  assert(min01 != min10);
167  if (min01<min10) {
168  if (rm != RM_IMP)
169  GECODE_ME_CHECK(b.one_none(home));
170  } else {
171  if (rm != RM_PMI)
172  GECODE_ME_CHECK(b.zero_none(home));
173  }
174  return home.ES_SUBSUMED(*this);
175  }
176 
177  // min(x0lb - x1ub) < min(x1ub) -> b=0
178  if (x1.cardMax() > 0) {
179  GlbRanges<View0> x0l(x0);
180  LubRanges<View1> x1u(x1);
181  int x1umin=x1u.min();
183  if (d() && d.min() < x1umin) {
184  if (rm != RM_PMI)
185  GECODE_ME_CHECK(b.zero_none(home));
186  return home.ES_SUBSUMED(*this);
187  }
188  }
189  // min(x1lb - x0ub) < min(x0ub) -> b=1
190  if (x0.cardMax() > 0) {
191  LubRanges<View0> x0u(x0);
192  GlbRanges<View1> x1l(x1);
193  int x0umin=x0u.min();
195  if (d() && d.min() < x0umin) {
196  if (rm != RM_IMP)
197  GECODE_ME_CHECK(b.one_none(home));
198  return home.ES_SUBSUMED(*this);
199  }
200  }
201 
202  return ES_FIX;
203  }
204 
205 }}}
206 
207 // STATISTICS: set-prop
int min(int i) const
Return minimum of range at position i.
Definition: int-set-1.hpp:115
#define forceinline
Definition: config.hpp:173
@ RM_PMI
Inverse implication for reification.
Definition: int.hh:850
ExecStatus ES_SUBSUMED(Propagator &p)
Definition: core.hpp:3614
void subscribe(Space &home, Propagator &p, PropCond pc, bool schedule=true)
Subscribe propagator p with propagation condition pc to view.
@ RM_IMP
Implication for reification.
Definition: int.hh:843
@ LO
Cheap.
Definition: core.hpp:581
Computation spaces.
Definition: core.hpp:1748
Base-class for both propagators and branchers.
Definition: core.hpp:696
Gecode::Int::BoolView b
Definition: rel.hh:238
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition: re-lq.hpp:100
Boolean view for Boolean variables.
Definition: view.hpp:1315
virtual Actor * copy(Space &home, bool)
Copy propagator during cloning.
Definition: re-lq.hpp:94
Gecode toplevel namespace
Base-class for propagators.
Definition: core.hpp:1092
Home class for posting propagators
Definition: core.hpp:922
struct Gecode::@579::NNF::@61::@62 b
For binary nodes (and, or, eqv)
ReLq(Space &home, bool share, ReLq &p)
Constructor for cloning p.
Definition: re-lq.hpp:52
Range iterator for computing set difference.
Definition: ranges-diff.hpp:47
static ExecStatus post(Home home, View0 x, View1 y, Gecode::Int::BoolView b)
Post propagator for .
Definition: re-lq.hpp:86
View0 x0
Definition: rel.hh:236
Range iterator for the greatest lower bound.
Definition: var-imp.hpp:363
void update(Space &home, bool share, VarImpView< Var > &y)
Update this view to be a clone of view y.
View1 x1
Definition: rel.hh:237
static PropCost ternary(PropCost::Mod m)
Three variables for modifier pcm.
Definition: core.hpp:4850
Propagation cost.
Definition: core.hpp:554
const Gecode::PropCond PC_INT_VAL
Propagate when a view becomes assigned (single value)
Definition: var-type.hpp:82
Gecode::IntSet d(v, 7)
Reified propagator for set less than or equal
Definition: rel.hh:234
@ ES_FIX
Propagation has computed fixpoint.
Definition: core.hpp:545
Range iterator for the least upper bound.
Definition: var-imp.hpp:321
virtual void reschedule(Space &home)
Schedule function.
Definition: re-lq.hpp:68
const Gecode::PropCond PC_SET_ANY
Propagate when any bound or the cardinality of a view changes.
Definition: var-type.hpp:248
#define GECODE_ME_CHECK(me)
Check whether modification event me is failed, and forward failure.
Definition: macros.hpp:56
virtual size_t dispose(Space &home)
Delete actor and return its size.
Definition: core.hpp:3354
virtual size_t dispose(Space &home)
Delete propagator and return its size.
Definition: re-lq.hpp:76
Propagator for set less than or equal
Definition: rel.hh:208
int min(void) const
Return smallest value of range.
int ModEventDelta
Modification event deltas.
Definition: core.hpp:169
#define GECODE_REWRITE(prop, post)
Rewrite propagator by executing post function.
Definition: macros.hpp:120
@ ES_OK
Execution is okay.
Definition: core.hpp:544
int p
Number of positive literals for node type.
Definition: bool-expr.cpp:236
ExecStatus
Definition: core.hpp:540
virtual PropCost cost(const Space &home, const ModEventDelta &med) const
Cost function (defined as PC_TERNARY_LO)
Definition: re-lq.hpp:61