Generated on Thu Apr 5 2018 19:44:19 for Gecode by doxygen 1.8.13
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$ by $Author$
11  * $Revision$
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,p) {
54  x0.update(home,p.x0);
55  x1.update(home,p.x1);
56  b.update(home,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
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>
88  if (!same(x0,x1)) {
89  (void) new (home) ReLq<View0,View1,rm,strict>(home,x0,x1,b);
90  } else {
91  if (strict) {
92  if (rm != RM_PMI) {
93  GECODE_ME_CHECK(b.zero(home));
94  }
95  } else {
96  if (rm != RM_IMP) {
97  GECODE_ME_CHECK(b.one(home));
98  }
99  }
100  }
101  return ES_OK;
102  }
103 
104  template<class View0, class View1, ReifyMode rm, bool strict>
105  Actor*
107  return new (home) ReLq<View0,View1,rm,strict>(home,*this);
108  }
109 
110  template<class View0, class View1, ReifyMode rm, bool strict>
111  ExecStatus
113  if (b.one()) {
114  if (rm == RM_PMI)
115  return home.ES_SUBSUMED(*this);
116  GECODE_REWRITE(*this,(Lq<View0,View1,strict>::post(home(*this),x0,x1)));
117  }
118  if (b.zero()) {
119  if (rm == RM_IMP)
120  return home.ES_SUBSUMED(*this);
121  GECODE_REWRITE(*this,
122  (Lq<View1,View0,!strict>::post(home(*this),x1,x0)));
123  }
124  if (x0.cardMax() == 0) {
125  if ( (!strict) || x1.cardMin() > 0) {
126  if (rm != RM_IMP)
127  GECODE_ME_CHECK(b.one_none(home));
128  return home.ES_SUBSUMED(*this);
129  }
130  if (strict && x1.cardMax() == 0) {
131  if (rm != RM_PMI)
132  GECODE_ME_CHECK(b.zero_none(home));
133  return home.ES_SUBSUMED(*this);
134  }
135  }
136 
137  if (x0.assigned() && x1.assigned()) {
138  // directly test x0<=x1
139  int min01;
140  {
141  GlbRanges<View0> x0l(x0);
142  GlbRanges<View1> x1l(x1);
144  if (!d()) {
145  if ((!strict) && x0.cardMax() == x1.cardMax()) {
146  // equal
147  if (rm != RM_IMP)
148  GECODE_ME_CHECK(b.one_none(home));
149  } else {
150  // subset
151  if (rm != RM_PMI)
152  GECODE_ME_CHECK(b.zero_none(home));
153  }
154  return home.ES_SUBSUMED(*this);
155  }
156  min01 = d.min();
157  }
158  int min10;
159  {
160  GlbRanges<View0> x0l(x0);
161  GlbRanges<View1> x1l(x1);
163  if (!d()) {
164  if (strict && x0.cardMax() == x1.cardMax()) {
165  // equal
166  if (rm != RM_PMI)
167  GECODE_ME_CHECK(b.zero_none(home));
168  } else {
169  // subset
170  if (rm != RM_IMP)
171  GECODE_ME_CHECK(b.one_none(home));
172  }
173  return home.ES_SUBSUMED(*this);
174  }
175  min10 = d.min();
176  }
177 
178  assert(min01 != min10);
179  if (min01<min10) {
180  if (rm != RM_IMP)
181  GECODE_ME_CHECK(b.one_none(home));
182  } else {
183  if (rm != RM_PMI)
184  GECODE_ME_CHECK(b.zero_none(home));
185  }
186  return home.ES_SUBSUMED(*this);
187  }
188 
189  // min(x0lb - x1ub) < min(x1ub) -> b=0
190  if (x1.cardMax() > 0) {
191  GlbRanges<View0> x0l(x0);
192  LubRanges<View1> x1u(x1);
193  int x1umin=x1u.min();
195  if (d() && d.min() < x1umin) {
196  if (rm != RM_PMI)
197  GECODE_ME_CHECK(b.zero_none(home));
198  return home.ES_SUBSUMED(*this);
199  }
200  }
201  // min(x1lb - x0ub) < min(x0ub) -> b=1
202  if (x0.cardMax() > 0) {
203  LubRanges<View0> x0u(x0);
204  GlbRanges<View1> x1l(x1);
205  int x0umin=x0u.min();
207  if (d() && d.min() < x0umin) {
208  if (rm != RM_IMP)
209  GECODE_ME_CHECK(b.one_none(home));
210  return home.ES_SUBSUMED(*this);
211  }
212  }
213 
214  return ES_FIX;
215  }
216 
217 }}}
218 
219 // STATISTICS: set-prop
void cancel(Space &home, Propagator &p, PropCond pc)
Cancel subscription of propagator p with propagation condition pc to view.
Definition: view.hpp:489
#define GECODE_REWRITE(prop, post)
Rewrite propagator by executing post function.
Definition: macros.hpp:120
void update(Space &home, VarImpView< Var > &y)
Update this view to be a clone of view y.
Definition: view.hpp:529
bool zero(void) const
Test whether view is assigned to be zero.
Definition: bool.hpp:214
Inverse implication for reification.
Definition: int.hh:848
ExecStatus ES_SUBSUMED(Propagator &p)
Definition: core.hpp:3433
bool one(void) const
Test whether view is assigned to be one.
Definition: bool.hpp:218
static ExecStatus post(Home home, View0 x, View1 y, Gecode::Int::BoolView b)
Post propagator for .
Definition: re-lq.hpp:86
Base-class for propagators.
Definition: core.hpp:1016
Propagator for set less than or equal
Definition: rel.hh:212
Range iterator for the greatest lower bound.
Definition: var-imp.hpp:363
void reschedule(Space &home, Propagator &p, PropCond pc)
Re-schedule propagator p with propagation condition pc.
Definition: view.hpp:494
#define forceinline
Definition: config.hpp:182
Propagation has computed fixpoint.
Definition: core.hpp:469
Computation spaces.
Definition: core.hpp:1668
Range iterator for the least upper bound.
Definition: var-imp.hpp:321
virtual void reschedule(Space &home)
Schedule function.
Definition: re-lq.hpp:68
Base-class for both propagators and branchers.
Definition: core.hpp:620
Gecode::IntSet d(v, 7)
void subscribe(Space &home, Propagator &p, PropCond pc, bool schedule=true)
Subscribe propagator p with propagation condition pc to view.
Definition: view.hpp:483
int p
Number of positive literals for node type.
Definition: bool-expr.cpp:236
virtual size_t dispose(Space &home)
Delete propagator and return its size.
Definition: re-lq.hpp:76
ModEvent zero_none(Space &home)
Assign not yet assigned view to zero.
Definition: bool.hpp:232
bool same(VX, VY)
Test whether two views are in fact the same.
Definition: common.hpp:61
int min(void) const
Return smallest value of range.
virtual PropCost cost(const Space &home, const ModEventDelta &med) const
Cost function (defined as PC_TERNARY_LO)
Definition: re-lq.hpp:61
#define GECODE_ME_CHECK(me)
Check whether modification event me is failed, and forward failure.
Definition: macros.hpp:56
Reified propagator for set less than or equal
Definition: rel.hh:238
const Gecode::PropCond PC_SET_ANY
Propagate when any bound or the cardinality of a view changes.
Definition: var-type.hpp:248
struct Gecode::@585::NNF::@62::@63 b
For binary nodes (and, or, eqv)
virtual size_t dispose(Space &home)
Delete actor and return its size.
Definition: core.hpp:3172
Propagation cost.
Definition: core.hpp:478
ExecStatus
Definition: core.hpp:464
Gecode::Int::BoolView b
Definition: rel.hh:242
Execution is okay.
Definition: core.hpp:468
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition: re-lq.hpp:112
static PropCost ternary(PropCost::Mod m)
Three variables for modifier pcm.
Definition: core.hpp:4652
Gecode toplevel namespace
Implication for reification.
Definition: int.hh:841
ModEvent one_none(Space &home)
Assign not yet assigned view to one.
Definition: bool.hpp:236
Range iterator for computing set difference.
Definition: ranges-diff.hpp:47
int min(void) const
Return smallest value of range.
int ModEventDelta
Modification event deltas.
Definition: core.hpp:91
Home class for posting propagators
Definition: core.hpp:846
virtual Actor * copy(Space &home)
Copy propagator during cloning.
Definition: re-lq.hpp:106
ReLq(Space &home, ReLq &p)
Constructor for cloning p.
Definition: re-lq.hpp:52
const Gecode::PropCond PC_INT_VAL
Propagate when a view becomes assigned (single value)
Definition: var-type.hpp:82
Boolean view for Boolean variables.
Definition: view.hpp:1329