Generated on Thu Mar 13 2014 04:39:36 for Gecode by doxygen 1.8.1.2
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: 2011-08-25 00:34:16 +1000 (Thu, 25 Aug 2011) $ by $Author: tack $
11  * $Revision: 12346 $
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, bool strict>
42  ReLq<View0,View1,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, bool strict>
52  ReLq<View0,View1,strict>::ReLq(Space& home, bool share, ReLq& p)
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, bool strict>
60  PropCost
63  }
64 
65  template<class View0, class View1, bool strict>
66  forceinline size_t
68  b.cancel(home,*this, Gecode::Int::PC_INT_VAL);
69  x0.cancel(home,*this, PC_SET_ANY);
70  x1.cancel(home,*this, PC_SET_ANY);
71  (void) Propagator::dispose(home);
72  return sizeof(*this);
73  }
74 
75  template<class View0, class View1, bool strict>
77  ReLq<View0,View1,strict>::post(Home home, View0 x0, View1 x1,
79  (void) new (home) ReLq<View0,View1,strict>(home,x0,x1,b);
80  return ES_OK;
81  }
82 
83  template<class View0, class View1, bool strict>
84  Actor*
86  return new (home) ReLq<View0,View1,strict>(home,share,*this);
87  }
88 
89  template<class View0, class View1, bool strict>
92  if (b.one())
93  GECODE_REWRITE(*this,(Lq<View0,View1,strict>::post(home(*this),x0,x1)));
94  if (b.zero())
95  GECODE_REWRITE(*this,(Lq<View1,View0,!strict>::post(home(*this),x1,x0)));
96 
97  if (x0.cardMax() == 0) {
98  if ( (!strict) || x1.cardMin() > 0) {
99  GECODE_ME_CHECK(b.one_none(home));
100  return home.ES_SUBSUMED(*this);
101  }
102  if (strict && x1.cardMax() == 0) {
103  GECODE_ME_CHECK(b.zero_none(home));
104  return home.ES_SUBSUMED(*this);
105  }
106  }
107 
108  if (x0.assigned() && x1.assigned()) {
109  // directly test x0<=x1
110  int min01;
111  {
112  GlbRanges<View0> x0l(x0);
113  GlbRanges<View1> x1l(x1);
115  if (!d()) {
116  if ((!strict) && x0.cardMax() == x1.cardMax()) {
117  // equal
118  GECODE_ME_CHECK(b.one_none(home));
119  } else {
120  // subset
121  GECODE_ME_CHECK(b.zero_none(home));
122  }
123  return home.ES_SUBSUMED(*this);
124  }
125  min01 = d.min();
126  }
127  int min10;
128  {
129  GlbRanges<View0> x0l(x0);
130  GlbRanges<View1> x1l(x1);
132  if (!d()) {
133  if (strict && x0.cardMax() == x1.cardMax()) {
134  // equal
135  GECODE_ME_CHECK(b.zero_none(home));
136  } else {
137  // subset
138  GECODE_ME_CHECK(b.one_none(home));
139  }
140  return home.ES_SUBSUMED(*this);
141  }
142  min10 = d.min();
143  }
144 
145  assert(min01 != min10);
146  if (min01<min10) {
147  GECODE_ME_CHECK(b.one_none(home));
148  } else {
149  GECODE_ME_CHECK(b.zero_none(home));
150  }
151  return home.ES_SUBSUMED(*this);
152  }
153 
154  // min(x0lb - x1ub) < min(x1ub) -> b=0
155  if (x1.cardMax() > 0) {
156  GlbRanges<View0> x0l(x0);
157  LubRanges<View1> x1u(x1);
158  int x1umin=x1u.min();
160  if (d() && d.min() < x1umin) {
161  GECODE_ME_CHECK(b.zero_none(home));
162  return home.ES_SUBSUMED(*this);
163  }
164  }
165  // min(x1lb - x0ub) < min(x0ub) -> b=1
166  if (x0.cardMax() > 0) {
167  LubRanges<View0> x0u(x0);
168  GlbRanges<View1> x1l(x1);
169  int x0umin=x0u.min();
171  if (d() && d.min() < x0umin) {
172  GECODE_ME_CHECK(b.one_none(home));
173  return home.ES_SUBSUMED(*this);
174  }
175  }
176 
177  return ES_FIX;
178  }
179 
180 }}}
181 
182 // STATISTICS: set-prop