Generated on Tue Mar 5 2013 22:37:23 for Gecode by doxygen 1.8.3.1
re-prop.hpp
Go to the documentation of this file.
1 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2 /*
3  * Main authors:
4  * Christian Schulte <schulte@gecode.org>
5  *
6  * Copyright:
7  * Christian Schulte, 2011
8  *
9  * Last modified:
10  * $Date: 2011-08-23 05:43:31 +1000 (Tue, 23 Aug 2011) $ by $Author: schulte $
11  * $Revision: 12335 $
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 #include <gecode/int/rel.hh>
39 
40 namespace Gecode { namespace Int { namespace Member {
41 
42  template<class View>
45  BoolView b0)
46  : Prop<View>(home,vs,x,y), b(b0) {
47  b.subscribe(home,*this,PC_BOOL_VAL);
48  }
49 
50  template<class View>
51  inline ExecStatus
53  if (x.size() == 0) {
54  GECODE_ME_CHECK(b.zero(home));
55  return ES_OK;
56  }
57 
58  x.unique(home);
59 
60  if (x.size() == 1)
61  return Rel::ReEqDom<View,BoolView>::post(home,x[0],y,b);
62 
63  if (x.same(home,y)) {
64  GECODE_ME_CHECK(b.one(home));
65  return ES_OK;
66  }
67 
68  // Eliminate assigned views and store them into the value set
69  ValSet vs;
70  add(home, vs, x);
71 
72  switch (vs.compare(y)) {
74  GECODE_ME_CHECK(b.one(home));
75  return ES_OK;
77  if (x.size() == 0) {
78  GECODE_ME_CHECK(b.zero(home));
79  return ES_OK;
80  }
81  break;
83  break;
84  default:
86  }
87 
88  (void) new (home) ReProp<View>(home, vs, x, y, b);
89  return ES_OK;
90  }
91 
92  template<class View>
94  ReProp<View>::ReProp(Space& home, bool share, ReProp<View>& p)
95  : Prop<View>(home, share, p) {
96  b.update(home, share, p.b);
97  }
98 
99  template<class View>
100  Propagator*
101  ReProp<View>::copy(Space& home, bool share) {
102  return new (home) ReProp<View>(home, share, *this);
103  }
104 
105  template<class View>
106  forceinline size_t
108  b.cancel(home, *this, PC_BOOL_VAL);
109  (void) Prop<View>::dispose(home);
110  return sizeof(*this);
111  }
112 
113  template<class View>
114  ExecStatus
116  // Add assigned views to value set
117  if (View::me(med) == ME_INT_VAL)
118  add(home,vs,x);
119 
120  if (b.one()) {
121  ValSet vsc(vs);
122  vs.flush();
123  GECODE_REWRITE(*this,Prop<View>::post(home,vsc,x,y));
124  }
125 
126  if (b.zero()) {
127  ValSet::Ranges vsr(vs);
128  GECODE_ME_CHECK(y.minus_r(home,vsr,false));
129  for (int i=x.size(); i--; )
131  return home.ES_SUBSUMED(*this);
132  }
133 
134  // Eliminate views from x
135  eliminate(home);
136 
137  switch (vs.compare(y)) {
139  GECODE_ME_CHECK(b.one(home));
140  return home.ES_SUBSUMED(*this);
142  if (x.size() == 0) {
143  GECODE_ME_CHECK(b.zero(home));
144  return home.ES_SUBSUMED(*this);
145  }
146  break;
148  break;
149  default:
150  GECODE_NEVER;
151  }
152 
153  // Check whether y is in union of x and value set
154  if (x.size() > 0) {
155  Region r(home);
156 
157  ValSet::Ranges vsr(vs);
158  ViewRanges<View> xsr(x[x.size()-1]);
159  Iter::Ranges::NaryUnion u(r,vsr,xsr);
160  for (int i=x.size()-1; i--; ) {
161  ViewRanges<View> xir(x[i]);
162  u |= xir;
163  }
164 
165  ViewRanges<View> yr(y);
166 
167  if (Iter::Ranges::disjoint(u,yr)) {
168  GECODE_ME_CHECK(b.zero(home));
169  return home.ES_SUBSUMED(*this);
170  }
171  }
172 
173  return ES_FIX;
174  }
175 
176 }}}
177 
178 // STATISTICS: int-prop