Generated on Sat May 25 2013 18:00:41 for Gecode by doxygen 1.8.3.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