Generated on Sat May 25 2013 18:00:34 for Gecode by doxygen 1.8.3.1
lq-le.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  * Gabor Szokoli <szokoli@gecode.org>
6  * Vincent Barichard <Vincent.Barichard@univ-angers.fr>
7  *
8  * Copyright:
9  * Christian Schulte, 2003
10  * Gabor Szokoli, 2003
11  * Vincent Barichard, 2012
12  *
13  * Last modified:
14  * $Date: 2012-12-13 16:02:59 +0100 (Thu, 13 Dec 2012) $ by $Author: vbarichard $
15  * $Revision: 13202 $
16  *
17  * This file is part of Gecode, the generic constraint
18  * development environment:
19  * http://www.gecode.org
20  *
21  * Permission is hereby granted, free of charge, to any person obtaining
22  * a copy of this software and associated documentation files (the
23  * "Software"), to deal in the Software without restriction, including
24  * without limitation the rights to use, copy, modify, merge, publish,
25  * distribute, sublicense, and/or sell copies of the Software, and to
26  * permit persons to whom the Software is furnished to do so, subject to
27  * the following conditions:
28  *
29  * The above copyright notice and this permission notice shall be
30  * included in all copies or substantial portions of the Software.
31  *
32  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
33  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
34  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
35  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
36  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
37  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
38  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
39  *
40  */
41 
42 namespace Gecode { namespace Float { namespace Rel {
43 
44  /*
45  * Less or equal propagator
46  *
47  */
48 
49  template<class View>
51  Lq<View>::Lq(Home home, View x0, View x1)
52  : BinaryPropagator<View,PC_FLOAT_BND>(home,x0,x1) {}
53 
54  template<class View>
56  Lq<View>::post(Home home, View x0, View x1) {
57  GECODE_ME_CHECK(x0.lq(home,x1.max()));
58  GECODE_ME_CHECK(x1.gq(home,x0.min()));
59  if (!same(x0,x1) && (x0.max() > x1.min()))
60  (void) new (home) Lq<View>(home,x0,x1);
61  return ES_OK;
62  }
63 
64  template<class View>
66  Lq<View>::Lq(Space& home, bool share, Lq<View>& p)
67  : BinaryPropagator<View,PC_FLOAT_BND>(home,share,p) {}
68 
69  template<class View>
70  Actor*
71  Lq<View>::copy(Space& home, bool share) {
72  return new (home) Lq<View>(home,share,*this);
73  }
74 
75  template<class View>
78  GECODE_ME_CHECK(x0.lq(home,x1.max()));
79  GECODE_ME_CHECK(x1.gq(home,x0.min()));
80  return (x0.assigned() || x1.assigned() || (x0.max() <= x1.min())) ? home.ES_SUBSUMED(*this) : ES_FIX;
81  }
82 
83 
84  /*
85  * Less propagator
86  *
87  */
88  template<class View>
90  Le<View>::Le(Home home, View x0, View x1)
91  : BinaryPropagator<View,PC_FLOAT_BND>(home,x0,x1) {}
92 
93  template<class View>
95  Le<View>::post(Home home, View x0, View x1) {
96  GECODE_ME_CHECK(x0.lq(home,x1.max()));
97  GECODE_ME_CHECK(x1.gq(home,x0.min()));
98  if (x0.assigned() && x1.assigned()) {
99  if (x0.max() >= x1.min())
100  return ES_FAILED;
101  } else if (same(x0,x1))
102  return ES_FAILED;
103  if (x0.max() >= x1.min())
104  (void) new (home) Le<View>(home,x0,x1);
105  return ES_OK;
106  }
107 
108  template<class View>
110  Le<View>::Le(Space& home, bool share, Le<View>& p)
111  : BinaryPropagator<View,PC_FLOAT_BND>(home,share,p) {}
112 
113  template<class View>
114  Actor*
115  Le<View>::copy(Space& home, bool share) {
116  return new (home) Le<View>(home,share,*this);
117  }
118 
119  template<class View>
120  ExecStatus
122  GECODE_ME_CHECK(x0.lq(home,x1.max()));
123  GECODE_ME_CHECK(x1.gq(home,x0.min()));
124  if (x0.assigned() && x1.assigned()) {
125  return (x0.max() >= x1.min()) ? ES_FAILED : home.ES_SUBSUMED(*this);
126  }
127  return (x0.max() < x1.min()) ? home.ES_SUBSUMED(*this) : ES_FIX;
128  }
129 
130 
131 
132 
133  /*
134  * Reified less or equal propagator
135  *
136  */
137 
138  template<class View, class CtrlView, ReifyMode rm>
140  ReLq<View,CtrlView,rm>::ReLq(Home home, View x0, View x1, CtrlView b)
141  : Int::ReBinaryPropagator<View,PC_FLOAT_BND,CtrlView>(home,x0,x1,b) {}
142 
143  template<class View, class CtrlView, ReifyMode rm>
144  ExecStatus
145  ReLq<View,CtrlView,rm>::post(Home home, View x0, View x1, CtrlView b) {
146  if (b.one()) {
147  if (rm == RM_PMI)
148  return ES_OK;
149  return Lq<View>::post(home,x0,x1);
150  }
151  if (b.zero()) {
152  if (rm == RM_IMP)
153  return ES_OK;
154  return Le<View>::post(home,x1,x0);
155  }
156  if (!same(x0,x1)) {
157  switch (rtest_lq(x0,x1)) {
158  case RT_TRUE:
159  if (rm != RM_IMP)
160  GECODE_ME_CHECK(b.one_none(home));
161  break;
162  case RT_FALSE:
163  if (rm != RM_PMI)
164  GECODE_ME_CHECK(b.zero_none(home));
165  break;
166  case RT_MAYBE:
167  if (!x0.assigned() || !x1.assigned())
168  (void) new (home) ReLq<View,CtrlView,rm>(home,x0,x1,b);
169  else {
170  if (rm != RM_IMP)
171  GECODE_ME_CHECK(b.one_none(home));
172  }
173  break;
174  default: GECODE_NEVER;
175  }
176  } else if (rm != RM_IMP) {
177  GECODE_ME_CHECK(b.one_none(home));
178  }
179  return ES_OK;
180  }
181 
182  template<class View, class CtrlView, ReifyMode rm>
185  : Int::ReBinaryPropagator<View,PC_FLOAT_BND,CtrlView>(home,share,p) {}
186 
187  template<class View, class CtrlView, ReifyMode rm>
188  Actor*
189  ReLq<View,CtrlView,rm>::copy(Space& home, bool share) {
190  return new (home) ReLq<View,CtrlView,rm>(home,share,*this);
191  }
192 
193  template<class View, class CtrlView, ReifyMode rm>
194  ExecStatus
196  if (b.one()) {
197  if (rm != RM_PMI)
198  GECODE_REWRITE(*this,Lq<View>::post(home(*this),x0,x1));
199  } else if (b.zero()) {
200  if (rm != RM_IMP)
201  GECODE_REWRITE(*this,Le<View>::post(home(*this),x1,x0));
202  } else {
203  switch (rtest_lq(x0,x1)) {
204  case RT_TRUE:
205  if (rm != RM_IMP)
206  GECODE_ME_CHECK(b.one_none(home));
207  break;
208  case RT_FALSE:
209  if (rm != RM_PMI)
210  GECODE_ME_CHECK(b.zero_none(home));
211  break;
212  case RT_MAYBE:
213  if (!x0.assigned() || !x1.assigned())
214  return ES_FIX;
215  else {
216  if (rm != RM_IMP)
217  GECODE_ME_CHECK(b.one_none(home));
218  break;
219  }
220  default: GECODE_NEVER;
221  }
222  }
223  return home.ES_SUBSUMED(*this);
224  }
225 
226  /*
227  * Reified less or equal propagator involving one variable
228  *
229  */
230 
231  template<class View, class CtrlView, ReifyMode rm>
234  : Int::ReUnaryPropagator<View,PC_FLOAT_BND,CtrlView>(home,x,b), c(c0) {}
235 
236  template<class View, class CtrlView, ReifyMode rm>
237  ExecStatus
239  if (b.one()) {
240  if (rm != RM_PMI)
241  GECODE_ME_CHECK(x.lq(home,c));
242  } else {
243  switch (rtest_lq(x,c)) {
244  case RT_TRUE:
245  if (rm != RM_IMP)
246  GECODE_ME_CHECK(b.one(home));
247  break;
248  case RT_FALSE:
249  if (rm != RM_PMI)
250  GECODE_ME_CHECK(b.zero(home));
251  break;
252  case RT_MAYBE:
253  (void) new (home) ReLqFloat<View,CtrlView,rm>(home,x,c,b);
254  break;
255  default: GECODE_NEVER;
256  }
257  }
258  return ES_OK;
259  }
260 
261 
262  template<class View, class CtrlView, ReifyMode rm>
265  : Int::ReUnaryPropagator<View,PC_FLOAT_BND,CtrlView>(home,share,p), c(p.c) {}
266 
267  template<class View, class CtrlView, ReifyMode rm>
268  Actor*
270  return new (home) ReLqFloat<View,CtrlView,rm>(home,share,*this);
271  }
272 
273  template<class View, class CtrlView, ReifyMode rm>
274  ExecStatus
276  if (b.one()) {
277  if (rm != RM_PMI)
278  GECODE_ME_CHECK(x0.lq(home,c));
279  } else {
280  switch (rtest_lq(x0,c)) {
281  case RT_TRUE:
282  if (rm != RM_IMP)
283  GECODE_ME_CHECK(b.one(home));
284  break;
285  case RT_FALSE:
286  if (rm != RM_PMI)
287  GECODE_ME_CHECK(b.zero(home));
288  break;
289  case RT_MAYBE:
290  return ES_FIX;
291  default: GECODE_NEVER;
292  }
293  }
294  return home.ES_SUBSUMED(*this);
295  }
296 
297 
298  /*
299  * Reified less
300  *
301  */
302 
303  template<class View, class CtrlView, ReifyMode rm>
306  : Int::ReUnaryPropagator<View,PC_FLOAT_BND,CtrlView>(home,x,b), c(c0) {}
307 
308  template<class View, class CtrlView, ReifyMode rm>
309  ExecStatus
311  if (b.one()) {
312  if (rm != RM_PMI)
313  {
314  GECODE_ME_CHECK(x.lq(home,c.max()));
315  if (x.assigned() && (x.max() >= c.min()))
316  return ES_FAILED;
317  }
318  } else {
319  switch (rtest_le(x,c)) {
320  case RT_TRUE:
321  if (rm != RM_IMP)
322  GECODE_ME_CHECK(b.one(home));
323  break;
324  case RT_FALSE:
325  if (rm != RM_PMI)
326  GECODE_ME_CHECK(b.zero(home));
327  break;
328  case RT_MAYBE:
329  (void) new (home) ReLeFloat<View,CtrlView,rm>(home,x,c,b);
330  break;
331  default: GECODE_NEVER;
332  }
333  }
334  return ES_OK;
335  }
336 
337 
338  template<class View, class CtrlView, ReifyMode rm>
341  : Int::ReUnaryPropagator<View,PC_FLOAT_BND,CtrlView>(home,share,p), c(p.c) {}
342 
343  template<class View, class CtrlView, ReifyMode rm>
344  Actor*
346  return new (home) ReLeFloat<View,CtrlView,rm>(home,share,*this);
347  }
348 
349  template<class View, class CtrlView, ReifyMode rm>
350  ExecStatus
352  if (b.one()) {
353  if (rm != RM_PMI)
354  {
355  GECODE_ME_CHECK(x0.lq(home,c.max()));
356  if (x0.assigned()) {
357  return (x0.max() >= c.min()) ? ES_FAILED : home.ES_SUBSUMED(*this);
358  }
359  }
360  } else {
361  switch (rtest_le(x0,c)) {
362  case RT_TRUE:
363  if (rm != RM_IMP)
364  GECODE_ME_CHECK(b.one(home));
365  break;
366  case RT_FALSE:
367  if (rm != RM_PMI)
368  GECODE_ME_CHECK(b.zero(home));
369  break;
370  case RT_MAYBE:
371  return ES_FIX;
372  default: GECODE_NEVER;
373  }
374  }
375  return home.ES_SUBSUMED(*this);
376  }
377 
378 }}}
379 
380 // STATISTICS: float-prop
381