Generated on Sat Feb 7 2015 02:01:30 for Gecode by doxygen 1.8.9.1
re-eq.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  * Christian Schulte <schulte@gecode.org>
6  *
7  * Bugfixes provided by:
8  * Grégoire Dooms <dooms@info.ucl.ac.be>
9  *
10  * Copyright:
11  * Guido Tack, 2004
12  * Christian Schulte, 2004
13  *
14  * Last modified:
15  * $Date: 2012-10-22 01:13:28 +0200 (Mon, 22 Oct 2012) $ by $Author: tack $
16  * $Revision: 13161 $
17  *
18  * This file is part of Gecode, the generic constraint
19  * development environment:
20  * http://www.gecode.org
21  *
22  * Permission is hereby granted, free of charge, to any person obtaining
23  * a copy of this software and associated documentation files (the
24  * "Software"), to deal in the Software without restriction, including
25  * without limitation the rights to use, copy, modify, merge, publish,
26  * distribute, sublicense, and/or sell copies of the Software, and to
27  * permit persons to whom the Software is furnished to do so, subject to
28  * the following conditions:
29  *
30  * The above copyright notice and this permission notice shall be
31  * included in all copies or substantial portions of the Software.
32  *
33  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
34  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
35  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
36  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
37  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
38  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
39  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
40  *
41  */
42 
43 namespace Gecode { namespace Set { namespace Rel {
44 
45  template<class View0, class View1, class CtrlView, ReifyMode rm>
47  ReEq<View0,View1,CtrlView,rm>::ReEq(Home home, View0 y0, View1 y1,
48  CtrlView y2)
49  : Propagator(home), x0(y0), x1(y1), b(y2) {
50  b.subscribe(home,*this, Gecode::Int::PC_INT_VAL);
51  x0.subscribe(home,*this, PC_SET_ANY);
52  x1.subscribe(home,*this, PC_SET_ANY);
53  }
54 
55  template<class View0, class View1, class CtrlView, ReifyMode rm>
58  : Propagator(home,share,p) {
59  x0.update(home,share,p.x0);
60  x1.update(home,share,p.x1);
61  b.update(home,share,p.b);
62  }
63 
64  template<class View0, class View1, class CtrlView, ReifyMode rm>
65  PropCost
68  }
69 
70  template<class View0, class View1, class CtrlView, ReifyMode rm>
71  forceinline size_t
73  b.cancel(home,*this, Gecode::Int::PC_INT_VAL);
74  x0.cancel(home,*this, PC_SET_ANY);
75  x1.cancel(home,*this, PC_SET_ANY);
76  (void) Propagator::dispose(home);
77  return sizeof(*this);
78  }
79 
80  template<class View0, class View1, class CtrlView, ReifyMode rm>
82  ReEq<View0,View1,CtrlView,rm>::post(Home home, View0 x0, View1 x1,
83  CtrlView b) {
84  (void) new (home) ReEq<View0,View1,CtrlView,rm>(home,x0,x1,b);
85  return ES_OK;
86  }
87 
88  template<class View0, class View1, class CtrlView, ReifyMode rm>
89  Actor*
91  return new (home) ReEq<View0,View1,CtrlView,rm>(home,share,*this);
92  }
93 
94  template<class View0, class View1, class CtrlView, ReifyMode rm>
97  const ModEventDelta&) {
98  if (b.one()) {
99  if (rm == RM_PMI)
100  return home.ES_SUBSUMED(*this);
101  GECODE_REWRITE(*this,(Eq<View0,View1>::post(home(*this),x0,x1)));
102  }
103  if (b.zero()) {
104  if (rm == RM_IMP)
105  return home.ES_SUBSUMED(*this);
106  GECODE_REWRITE(*this,(Distinct<View0,View1>::post(home(*this),x0,x1)));
107  }
108 
109  if (x0.assigned() && x1.assigned()) {
110  // directly test x0==x1
111  GlbRanges<View0> x0lb(x0);
112  GlbRanges<View1> x1lb(x1);
113  bool x0eqx1 = true;
114  for (; x0lb() && x1lb(); ++x0lb, ++x1lb) {
115  if (x0lb.min() != x1lb.min() ||
116  x0lb.max() != x1lb.max()) {
117  x0eqx1 = false;
118  break;
119  }
120  }
121  if (x0eqx1 && !x0lb() && !x1lb()) {
122  if (rm != RM_IMP)
123  GECODE_ME_CHECK(b.one_none(home));
124  return home.ES_SUBSUMED(*this);
125  } else {
126  if (rm != RM_PMI)
127  GECODE_ME_CHECK(b.zero_none(home));
128  return home.ES_SUBSUMED(*this);
129  }
130  }
131 
132  // check whether cardinalities still allow equality
133  if (x0.cardMin() > x1.cardMax() ||
134  x1.cardMin() > x0.cardMax()) {
135  if (rm != RM_PMI)
136  GECODE_ME_CHECK(b.zero_none(home));
137  return home.ES_SUBSUMED(*this);
138  }
139 
140  // check glb(x0) subset lub(x1)
141  GlbRanges<View0> x0lb(x0);
142  LubRanges<View1> x1ub(x1);
144  if ( diff1() ) {
145  if (rm != RM_PMI)
146  GECODE_ME_CHECK(b.zero_none(home));
147  return home.ES_SUBSUMED(*this);
148  }
149 
150  // check glb(x1) subset lub(x0)
151  GlbRanges<View1> x1lb(x1);
152  LubRanges<View0> x0ub(x0);
154  if ( diff2() ) {
155  if (rm != RM_PMI)
156  GECODE_ME_CHECK(b.zero_none(home));
157  return home.ES_SUBSUMED(*this);
158  }
159 
160  return ES_FIX;
161  }
162 
163 }}}
164 
165 // STATISTICS: set-prop
#define GECODE_REWRITE(prop, post)
Rewrite propagator by executing post function.
Definition: macros.hpp:109
Propagator for negated equality
Definition: rel.hh:261
static ExecStatus post(Home home, View0 x, View1 y, CtrlView b)
Post propagator for .
Definition: re-eq.hpp:82
ReEq(Space &home, bool share, ReEq &)
Constructor for cloning p.
Definition: re-eq.hpp:57
Inverse implication for reification.
Definition: int.hh:847
ExecStatus ES_SUBSUMED(Propagator &p)
Definition: core.hpp:2973
Base-class for propagators.
Definition: core.hpp:755
Range iterator for the greatest lower bound.
Definition: var-imp.hpp:363
virtual PropCost cost(const Space &home, const ModEventDelta &med) const
Cost function (defined as PC_TERNARY_LO)
Definition: re-eq.hpp:66
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.
Reified equality propagator
Definition: rel.hh:170
int max(void) const
Return largest value of range.
int p
Number of positive literals for node type.
Definition: bool-expr.cpp:236
virtual Actor * copy(Space &home, bool)
Copy propagator during cloning.
Definition: re-eq.hpp:90
#define GECODE_ME_CHECK(me)
Check whether modification event me is failed, and forward failure.
Definition: macros.hpp:45
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
virtual size_t dispose(Space &home)
Delete propagator and return its size.
Definition: re-eq.hpp:72
ExecStatus
Definition: core.hpp:523
#define forceinline
Definition: config.hpp:132
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition: re-eq.hpp:96
Propagator for set equality
Definition: rel.hh:146
Execution is okay.
Definition: core.hpp:527
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
int ModEventDelta
Modification event deltas.
Definition: core.hpp:173
Home class for posting propagators
Definition: core.hpp:717
const Gecode::PropCond PC_INT_VAL
Propagate when a view becomes assigned (single value)
Definition: var-type.hpp:82