Generated on Thu Apr 5 2018 19:44:19 for Gecode by doxygen 1.8.13
re-subset.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  * Christian Schulte <schulte@gecode.org>
6  *
7  * Copyright:
8  * Guido Tack, 2004
9  * Christian Schulte, 2004
10  *
11  * Last modified:
12  * $Date$ by $Author$
13  * $Revision$
14  *
15  * This file is part of Gecode, the generic constraint
16  * development environment:
17  * http://www.gecode.org
18  *
19  * Permission is hereby granted, free of charge, to any person obtaining
20  * a copy of this software and associated documentation files (the
21  * "Software"), to deal in the Software without restriction, including
22  * without limitation the rights to use, copy, modify, merge, publish,
23  * distribute, sublicense, and/or sell copies of the Software, and to
24  * permit persons to whom the Software is furnished to do so, subject to
25  * the following conditions:
26  *
27  * The above copyright notice and this permission notice shall be
28  * included in all copies or substantial portions of the Software.
29  *
30  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
31  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
32  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
33  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
34  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
35  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
36  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
37  *
38  */
39 
40 namespace Gecode { namespace Set { namespace Rel {
41 
42  template<class View0, class View1, class CtrlView, ReifyMode rm>
45  View1 y1, CtrlView b0)
46  : Propagator(home), x0(y0), x1(y1), b(b0) {
47  b.subscribe(home,*this, Gecode::Int::PC_INT_VAL);
48  x0.subscribe(home,*this, PC_SET_ANY);
49  x1.subscribe(home,*this, PC_SET_ANY);
50  }
51 
52  template<class View0, class View1, class CtrlView, ReifyMode rm>
55  ReSubset& p)
56  : Propagator(home,p) {
57  x0.update(home,p.x0);
58  x1.update(home,p.x1);
59  b.update(home,p.b);
60  }
61 
62  template<class View0, class View1, class CtrlView, ReifyMode rm>
63  PropCost
65  const ModEventDelta&) const {
67  }
68 
69  template<class View0, class View1, class CtrlView, ReifyMode rm>
70  void
72  b.reschedule(home,*this, Gecode::Int::PC_INT_VAL);
73  x0.reschedule(home,*this, PC_SET_ANY);
74  x1.reschedule(home,*this, PC_SET_ANY);
75  }
76 
77  template<class View0, class View1, class CtrlView, ReifyMode rm>
78  forceinline size_t
80  b.cancel(home,*this, Gecode::Int::PC_INT_VAL);
81  x0.cancel(home,*this, PC_SET_ANY);
82  x1.cancel(home,*this, PC_SET_ANY);
83  (void) Propagator::dispose(home);
84  return sizeof(*this);
85  }
86 
87  template<class View0, class View1, class CtrlView, ReifyMode rm>
90  CtrlView b) {
91  if (!same(x0,x1)) {
92  (void) new (home) ReSubset<View0,View1,CtrlView,rm>(home,x0,x1,b);
93  } else if (rm != RM_IMP) {
94  GECODE_ME_CHECK(b.one(home));
95  }
96  return ES_OK;
97  }
98 
99  template<class View0, class View1, class CtrlView, ReifyMode rm>
100  Actor*
102  return new (home) ReSubset<View0,View1,CtrlView,rm>(home,*this);
103  }
104 
105  template<class View0, class View1, class CtrlView, ReifyMode rm>
106  ExecStatus
108  const ModEventDelta&) {
109  if (b.one()) {
110  if (rm == RM_PMI)
111  return home.ES_SUBSUMED(*this);
112  GECODE_REWRITE(*this,(Subset<View0,View1>::post(home(*this),x0,x1)));
113  }
114  if (b.zero()) {
115  if (rm == RM_IMP)
116  return home.ES_SUBSUMED(*this);
117  GECODE_REWRITE(*this,(NoSubset<View0,View1>::post(home(*this),x0,x1)));
118  }
119 
120  // check whether cardinalities still allow subset
121  if (x0.cardMin() > x1.cardMax()) {
122  if (rm != RM_PMI)
123  GECODE_ME_CHECK(b.zero_none(home));
124  return home.ES_SUBSUMED(*this);
125  }
126 
127  // check lub(x0) subset glb(x1)
128  {
129  LubRanges<View0> x0ub(x0);
130  GlbRanges<View1> x1lb(x1);
132  if (!d()) {
133  if (rm != RM_IMP)
134  GECODE_ME_CHECK(b.one_none(home));
135  return home.ES_SUBSUMED(*this);
136  }
137  }
138 
139  // check glb(x0) subset lub(x1)
140  {
141  GlbRanges<View0> x0lb(x0);
142  LubRanges<View1> x1ub(x1);
144  if (d()) {
145  if (rm != RM_PMI)
146  GECODE_ME_CHECK(b.zero_none(home));
147  return home.ES_SUBSUMED(*this);
148  } else if (x0.assigned() && x1.assigned()) {
149  if (rm != RM_IMP)
150  GECODE_ME_CHECK(b.one_none(home));
151  return home.ES_SUBSUMED(*this);
152  }
153  }
154 
155  if (x0.cardMin() > 0) {
156  LubRanges<View0> x0ub(x0);
157  LubRanges<View1> x1ub(x1);
159  i(x0ub,x1ub);
160  if (!i()) {
161  if (rm != RM_PMI)
162  GECODE_ME_CHECK(b.zero_none(home));
163  return home.ES_SUBSUMED(*this);
164  }
165  }
166 
167  return ES_FIX;
168  }
169 
170 }}}
171 
172 // STATISTICS: set-prop
ReSubset(Space &home, ReSubset &p)
Constructor for cloning p.
Definition: re-subset.hpp:54
#define GECODE_REWRITE(prop, post)
Rewrite propagator by executing post function.
Definition: macros.hpp:120
virtual size_t dispose(Space &home)
Delete propagator and return its size.
Definition: re-subset.hpp:79
Inverse implication for reification.
Definition: int.hh:848
CtrlView b
Boolean control view.
Definition: rel.hh:126
ExecStatus ES_SUBSUMED(Propagator &p)
Definition: core.hpp:3433
Propagator for the subset constraint
Definition: rel.hh:68
virtual void reschedule(Space &home)
Schedule function.
Definition: re-subset.hpp:71
Base-class for propagators.
Definition: core.hpp:1016
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition: re-subset.hpp:107
Range iterator for the greatest lower bound.
Definition: var-imp.hpp:363
#define forceinline
Definition: config.hpp:182
Propagation has computed fixpoint.
Definition: core.hpp:469
Computation spaces.
Definition: core.hpp:1668
Range iterator for the least upper bound.
Definition: var-imp.hpp:321
Base-class for both propagators and branchers.
Definition: core.hpp:620
virtual Actor * copy(Space &home)
Copy propagator during cloning.
Definition: re-subset.hpp:101
Gecode::IntSet d(v, 7)
int p
Number of positive literals for node type.
Definition: bool-expr.cpp:236
Gecode::IntArgs i(4, 1, 2, 3, 4)
Range iterator for computing intersection (binary)
virtual PropCost cost(const Space &home, const ModEventDelta &med) const
Cost function (defined as ternary low)
Definition: re-subset.hpp:64
bool same(VX, VY)
Test whether two views are in fact the same.
Definition: common.hpp:61
#define GECODE_ME_CHECK(me)
Check whether modification event me is failed, and forward failure.
Definition: macros.hpp:56
const Gecode::PropCond PC_SET_ANY
Propagate when any bound or the cardinality of a view changes.
Definition: var-type.hpp:248
struct Gecode::@585::NNF::@62::@63 b
For binary nodes (and, or, eqv)
Reified subset propagator
Definition: rel.hh:119
View1 x1
Variable view.
Definition: rel.hh:124
virtual size_t dispose(Space &home)
Delete actor and return its size.
Definition: core.hpp:3172
Propagation cost.
Definition: core.hpp:478
ExecStatus
Definition: core.hpp:464
Execution is okay.
Definition: core.hpp:468
Propagator for the negated subset constraint
Definition: rel.hh:94
static PropCost ternary(PropCost::Mod m)
Three variables for modifier pcm.
Definition: core.hpp:4652
Gecode toplevel namespace
Implication for reification.
Definition: int.hh:841
Range iterator for computing set difference.
Definition: ranges-diff.hpp:47
View0 x0
Variable view.
Definition: rel.hh:122
static ExecStatus post(Home home, View0 x, View1 y, CtrlView b)
Post propagator for .
Definition: re-subset.hpp:89
int ModEventDelta
Modification event deltas.
Definition: core.hpp:91
Home class for posting propagators
Definition: core.hpp:846
const Gecode::PropCond PC_INT_VAL
Propagate when a view becomes assigned (single value)
Definition: var-type.hpp:82