Generated on Thu Mar 7 2013 10:21:42 for Gecode by doxygen 1.8.3.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: 2010-03-04 03:32:21 +1100 (Thu, 04 Mar 2010) $ by $Author: schulte $
16  * $Revision: 10364 $
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>
47  ReEq<View0,View1>::ReEq(Home home, View0 y0, View1 y1,
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>
57  ReEq<View0,View1>::ReEq(Space& home, bool share, ReEq& p)
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>
65  PropCost
68  }
69 
70  template<class View0, class View1>
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>
82  ReEq<View0,View1>::post(Home home, View0 x0, View1 x1,
84  (void) new (home) ReEq<View0,View1>(home,x0,x1,b);
85  return ES_OK;
86  }
87 
88  template<class View0, class View1>
89  Actor*
90  ReEq<View0,View1>::copy(Space& home, bool share) {
91  return new (home) ReEq<View0,View1>(home,share,*this);
92  }
93 
94  template<class View0, class View1>
97  if (b.one())
98  GECODE_REWRITE(*this,(Eq<View0,View1>::post(home(*this),x0,x1)));
99  if (b.zero())
100  GECODE_REWRITE(*this,(Distinct<View0,View1>::post(home(*this),x0,x1)));
101 
102  if (x0.assigned() && x1.assigned()) {
103  // directly test x0==x1
104  GlbRanges<View0> x0lb(x0);
105  GlbRanges<View1> x1lb(x1);
106  for (; x0lb() && x1lb(); ++x0lb, ++x1lb) {
107  if (x0lb.min() != x1lb.min() ||
108  x0lb.max() != x1lb.max()) {
109  GECODE_ME_CHECK(b.zero_none(home));
110  return home.ES_SUBSUMED(*this);
111  }
112  }
113  if (!x0lb() && !x1lb()) {
114  GECODE_ME_CHECK(b.one_none(home));
115  return home.ES_SUBSUMED(*this);
116  } else {
117  GECODE_ME_CHECK(b.zero_none(home));
118  return home.ES_SUBSUMED(*this);
119  }
120  }
121 
122  // check whether cardinalities still allow equality
123  if (x0.cardMin() > x1.cardMax() ||
124  x1.cardMin() > x0.cardMax()) {
125  GECODE_ME_CHECK(b.zero_none(home));
126  return home.ES_SUBSUMED(*this);
127  }
128 
129  // check glb(x0) subset lub(x1)
130  GlbRanges<View0> x0lb(x0);
131  LubRanges<View1> x1ub(x1);
133  if ( diff1() ) {
134  GECODE_ME_CHECK(b.zero_none(home));
135  return home.ES_SUBSUMED(*this);
136  }
137 
138  // check glb(x1) subset lub(x0)
139  GlbRanges<View1> x1lb(x1);
140  LubRanges<View0> x0ub(x0);
142  if ( diff2() ) {
143  GECODE_ME_CHECK(b.zero_none(home));
144  return home.ES_SUBSUMED(*this);
145  }
146 
147  return ES_FIX;
148  }
149 
150 }}}
151 
152 // STATISTICS: set-prop