Generated on Mon Jul 27 2020 00:00:00 for Gecode by doxygen 1.8.18
range.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, 2004
8  *
9  * This file is part of Gecode, the generic constraint
10  * development environment:
11  * http://www.gecode.org
12  *
13  * Permission is hereby granted, free of charge, to any person obtaining
14  * a copy of this software and associated documentation files (the
15  * "Software"), to deal in the Software without restriction, including
16  * without limitation the rights to use, copy, modify, merge, publish,
17  * distribute, sublicense, and/or sell copies of the Software, and to
18  * permit persons to whom the Software is furnished to do so, subject to
19  * the following conditions:
20  *
21  * The above copyright notice and this permission notice shall be
22  * included in all copies or substantial portions of the Software.
23  *
24  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
29  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31  *
32  */
33 
34 #include <gecode/int/rel.hh>
35 
36 namespace Gecode { namespace Int { namespace Dom {
37 
38  template<class View, ReifyMode rm>
40  ReRange<View,rm>::ReRange(Home home, View x, int min0, int max0, BoolView b)
41  : ReUnaryPropagator<View,PC_INT_DOM,BoolView>(home,x,b),
42  min(min0), max(max0) {}
43 
44  template<class View, ReifyMode rm>
46  ReRange<View,rm>::post(Home home, View x, int min, int max, BoolView b) {
47  if (min == max) {
49  } else if ((min > max) || (max < x.min()) || (min > x.max())) {
50  if (rm == RM_PMI)
51  return ES_OK;
52  GECODE_ME_CHECK(b.zero(home));
53  } else if ((min <= x.min()) && (x.max() <= max)) {
54  if (rm == RM_IMP)
55  return ES_OK;
56  GECODE_ME_CHECK(b.one(home));
57  } else if (b.one()) {
58  if (rm == RM_PMI)
59  return ES_OK;
60  GECODE_ME_CHECK(x.gq(home,min));
61  GECODE_ME_CHECK(x.lq(home,max));
62  } else if (b.zero()) {
63  if (rm == RM_IMP)
64  return ES_OK;
66  GECODE_ME_CHECK(x.minus_r(home,r,false));
67  } else {
68  (void) new (home) ReRange<View,rm>(home,x,min,max,b);
69  }
70  return ES_OK;
71  }
72 
73 
74  template<class View, ReifyMode rm>
77  : ReUnaryPropagator<View,PC_INT_DOM,BoolView>(home,p),
78  min(p.min), max(p.max) {}
79 
80  template<class View, ReifyMode rm>
81  Actor*
83  return new (home) ReRange<View,rm>(home,*this);
84  }
85 
86  template<class View, ReifyMode rm>
89  if (b.one()) {
90  if (rm != RM_PMI) {
91  GECODE_ME_CHECK(x0.gq(home,min));
92  GECODE_ME_CHECK(x0.lq(home,max));
93  }
94  return home.ES_SUBSUMED(*this);
95  } else if (b.zero()) {
96  if (rm != RM_IMP) {
98  GECODE_ME_CHECK(x0.minus_r(home,r,false));
99  }
100  return home.ES_SUBSUMED(*this);
101  } else if ((x0.max() <= max) && (x0.min() >= min)) {
102  if (rm != RM_IMP)
103  GECODE_ME_CHECK(b.one_none(home));
104  return home.ES_SUBSUMED(*this);
105  } else if ((x0.max() < min) || (x0.min() > max)) {
106  if (rm != RM_PMI)
107  GECODE_ME_CHECK(b.zero_none(home));
108  return home.ES_SUBSUMED(*this);
109  } else if (!x0.range()) {
110  ViewRanges<View> i_x(x0);
112 
113  switch (Iter::Ranges::compare(i_x,i_mm)) {
115  if (rm != RM_IMP)
116  GECODE_ME_CHECK(b.one_none(home));
117  return home.ES_SUBSUMED(*this);
119  if (rm != RM_PMI)
120  GECODE_ME_CHECK(b.zero_none(home));
121  return home.ES_SUBSUMED(*this);
123  break;
124  default: GECODE_NEVER;
125  }
126  return ES_FIX;
127  }
128  return ES_FIX;
129  }
130 
131 }}}
132 
133 // STATISTICS: int-prop
134 
Post propagator for SetVar x
Definition: set.hh:767
@ RM_PMI
Inverse implication for reification.
Definition: int.hh:869
static ExecStatus post(Home home, View x, int c, CtrlView b)
Post domain consistent propagator .
Definition: eq.hpp:644
Reified range dom-propagator.
Definition: dom.hh:56
void max(Home home, FloatVar x0, FloatVar x1, FloatVar x2)
Post propagator for .
Definition: arithmetic.cpp:49
ExecStatus ES_SUBSUMED(Propagator &p)
Definition: core.hpp:3563
@ CS_NONE
Neither of the above.
virtual Actor * copy(Space &home)
Copy propagator during cloning.
Definition: range.hpp:82
@ RM_IMP
Implication for reification.
Definition: int.hh:862
Computation spaces.
Definition: core.hpp:1742
Base-class for both propagators and branchers.
Definition: core.hpp:628
Reified unary propagator.
Definition: propagator.hpp:54
static ExecStatus post(Home home, View x, int min, int max, BoolView b)
Post propagator for .
Definition: range.hpp:46
Boolean view for Boolean variables.
Definition: view.hpp:1380
Gecode toplevel namespace
@ CS_SUBSET
First is subset of second iterator.
Range iterator for integer views.
Definition: view.hpp:54
Home class for posting propagators
Definition: core.hpp:856
Post propagator for SetVar SetOpType SetVar SetRelType r
Definition: set.hh:767
struct Gecode::@602::NNF::@65::@66 b
For binary nodes (and, or, eqv)
#define GECODE_NEVER
Assert that this command is never executed.
Definition: macros.hpp:56
ReRange(Space &home, ReRange &p)
Constructor for cloning p.
Definition: range.hpp:76
@ ES_FIX
Propagation has computed fixpoint.
Definition: core.hpp:477
#define forceinline
Definition: config.hpp:185
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition: range.hpp:88
Range iterator for singleton range.
#define GECODE_ME_CHECK(me)
Check whether modification event me is failed, and forward failure.
Definition: macros.hpp:52
void min(Home home, FloatVar x0, FloatVar x1, FloatVar x2)
Post propagator for .
Definition: arithmetic.cpp:67
const Gecode::PropCond PC_INT_DOM
Propagate when domain changes.
Definition: var-type.hpp:100
int ModEventDelta
Modification event deltas.
Definition: core.hpp:89
CompareStatus compare(I &i, J &j)
Check whether range iterator i is a subset of j, or whether they are disjoint.
@ ES_OK
Execution is okay.
Definition: core.hpp:476
int p
Number of positive literals for node type.
Definition: bool-expr.cpp:232
@ CS_DISJOINT
Intersection is empty.
ExecStatus
Definition: core.hpp:472