Generated on Sat Feb 7 2015 02:01:30 for Gecode by doxygen 1.8.9.1
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: 2012-10-19 05:58:26 +0200 (Fri, 19 Oct 2012) $ by $Author: tack $
11  * $Revision: 13156 $
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  forceinline size_t
69  b.cancel(home,*this, Gecode::Int::PC_INT_VAL);
70  x0.cancel(home,*this, PC_SET_ANY);
71  x1.cancel(home,*this, PC_SET_ANY);
72  (void) Propagator::dispose(home);
73  return sizeof(*this);
74  }
75 
76  template<class View0, class View1, ReifyMode rm, bool strict>
78  ReLq<View0,View1,rm,strict>::post(Home home, View0 x0, View1 x1,
80  (void) new (home) ReLq<View0,View1,rm,strict>(home,x0,x1,b);
81  return ES_OK;
82  }
83 
84  template<class View0, class View1, ReifyMode rm, bool strict>
85  Actor*
87  return new (home) ReLq<View0,View1,rm,strict>(home,share,*this);
88  }
89 
90  template<class View0, class View1, ReifyMode rm, bool strict>
93  if (b.one()) {
94  if (rm == RM_PMI)
95  return home.ES_SUBSUMED(*this);
96  GECODE_REWRITE(*this,(Lq<View0,View1,strict>::post(home(*this),x0,x1)));
97  }
98  if (b.zero()) {
99  if (rm == RM_IMP)
100  return home.ES_SUBSUMED(*this);
101  GECODE_REWRITE(*this,
102  (Lq<View1,View0,!strict>::post(home(*this),x1,x0)));
103  }
104  if (x0.cardMax() == 0) {
105  if ( (!strict) || x1.cardMin() > 0) {
106  if (rm != RM_IMP)
107  GECODE_ME_CHECK(b.one_none(home));
108  return home.ES_SUBSUMED(*this);
109  }
110  if (strict && x1.cardMax() == 0) {
111  if (rm != RM_PMI)
112  GECODE_ME_CHECK(b.zero_none(home));
113  return home.ES_SUBSUMED(*this);
114  }
115  }
116 
117  if (x0.assigned() && x1.assigned()) {
118  // directly test x0<=x1
119  int min01;
120  {
121  GlbRanges<View0> x0l(x0);
122  GlbRanges<View1> x1l(x1);
124  if (!d()) {
125  if ((!strict) && x0.cardMax() == x1.cardMax()) {
126  // equal
127  if (rm != RM_IMP)
128  GECODE_ME_CHECK(b.one_none(home));
129  } else {
130  // subset
131  if (rm != RM_PMI)
132  GECODE_ME_CHECK(b.zero_none(home));
133  }
134  return home.ES_SUBSUMED(*this);
135  }
136  min01 = d.min();
137  }
138  int min10;
139  {
140  GlbRanges<View0> x0l(x0);
141  GlbRanges<View1> x1l(x1);
143  if (!d()) {
144  if (strict && x0.cardMax() == x1.cardMax()) {
145  // equal
146  if (rm != RM_PMI)
147  GECODE_ME_CHECK(b.zero_none(home));
148  } else {
149  // subset
150  if (rm != RM_IMP)
151  GECODE_ME_CHECK(b.one_none(home));
152  }
153  return home.ES_SUBSUMED(*this);
154  }
155  min10 = d.min();
156  }
157 
158  assert(min01 != min10);
159  if (min01<min10) {
160  if (rm != RM_IMP)
161  GECODE_ME_CHECK(b.one_none(home));
162  } else {
163  if (rm != RM_PMI)
164  GECODE_ME_CHECK(b.zero_none(home));
165  }
166  return home.ES_SUBSUMED(*this);
167  }
168 
169  // min(x0lb - x1ub) < min(x1ub) -> b=0
170  if (x1.cardMax() > 0) {
171  GlbRanges<View0> x0l(x0);
172  LubRanges<View1> x1u(x1);
173  int x1umin=x1u.min();
175  if (d() && d.min() < x1umin) {
176  if (rm != RM_PMI)
177  GECODE_ME_CHECK(b.zero_none(home));
178  return home.ES_SUBSUMED(*this);
179  }
180  }
181  // min(x1lb - x0ub) < min(x0ub) -> b=1
182  if (x0.cardMax() > 0) {
183  LubRanges<View0> x0u(x0);
184  GlbRanges<View1> x1l(x1);
185  int x0umin=x0u.min();
187  if (d() && d.min() < x0umin) {
188  if (rm != RM_IMP)
189  GECODE_ME_CHECK(b.one_none(home));
190  return home.ES_SUBSUMED(*this);
191  }
192  }
193 
194  return ES_FIX;
195  }
196 
197 }}}
198 
199 // STATISTICS: set-prop
#define GECODE_REWRITE(prop, post)
Rewrite propagator by executing post function.
Definition: macros.hpp:109
Inverse implication for reification.
Definition: int.hh:847
ExecStatus ES_SUBSUMED(Propagator &p)
Definition: core.hpp:2973
static ExecStatus post(Home home, View0 x, View1 y, Gecode::Int::BoolView b)
Post propagator for .
Definition: re-lq.hpp:78
ReLq(Space &home, bool share, ReLq &)
Constructor for cloning p.
Definition: re-lq.hpp:52
Base-class for propagators.
Definition: core.hpp:755
Propagator for set less than or equal
Definition: rel.hh:203
Range iterator for the greatest lower bound.
Definition: var-imp.hpp:363
int min(void) const
Return smallest value of range.
Propagation has computed fixpoint.
Definition: core.hpp:528
Computation spaces.
Definition: core.hpp:1362
Range iterator for the least upper bound.
Definition: var-imp.hpp:321
Base-class for both propagators and branchers.
Definition: core.hpp:666
int min(void) const
Return smallest value of range.
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:453
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:68
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
Reified propagator for set less than or equal
Definition: rel.hh:229
const Gecode::PropCond PC_SET_ANY
Propagate when any bound or the cardinality of a view changes.
Definition: var-type.hpp:248
virtual size_t dispose(Space &home)
Delete actor and return its size.
Definition: core.hpp:2877
Propagation cost.
Definition: core.hpp:537
ExecStatus
Definition: core.hpp:523
#define forceinline
Definition: config.hpp:132
Gecode::Int::BoolView b
Definition: rel.hh:233
Execution is okay.
Definition: core.hpp:527
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition: re-lq.hpp:92
static PropCost ternary(PropCost::Mod m)
Three variables for modifier pcm.
Definition: core.hpp:4050
struct Gecode::@518::NNF::@57::@58 b
For binary nodes (and, or, eqv)
Gecode toplevel namespace
Implication for reification.
Definition: int.hh:840
Range iterator for computing set difference.
Definition: ranges-diff.hpp:47
virtual PropCost cost(const Space &home, const ModEventDelta &med) const
Cost function (defined as PC_TERNARY_LO)
Definition: re-lq.hpp:61
int ModEventDelta
Modification event deltas.
Definition: core.hpp:173
Home class for posting propagators
Definition: core.hpp:717
virtual Actor * copy(Space &home, bool)
Copy propagator during cloning.
Definition: re-lq.hpp:86
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:1315