Generated on Sat Jan 20 2018 22:21:18 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: 2017-03-10 10:15:56 +0100 (Fri, 10 Mar 2017) $ by $Author: schulte $
13  * $Revision: 15566 $
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,share,p) {
57  x0.update(home,share,p.x0);
58  x1.update(home,share,p.x1);
59  b.update(home,share,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  (void) new (home) ReSubset<View0,View1,CtrlView,rm>(home,x0,x1,b);
92  return ES_OK;
93  }
94 
95  template<class View0, class View1, class CtrlView, ReifyMode rm>
96  Actor*
98  return new (home) ReSubset<View0,View1,CtrlView,rm>(home,share,*this);
99  }
100 
101  template<class View0, class View1, class CtrlView, ReifyMode rm>
102  ExecStatus
104  const ModEventDelta&) {
105  if (b.one()) {
106  if (rm == RM_PMI)
107  return home.ES_SUBSUMED(*this);
108  GECODE_REWRITE(*this,(Subset<View0,View1>::post(home(*this),x0,x1)));
109  }
110  if (b.zero()) {
111  if (rm == RM_IMP)
112  return home.ES_SUBSUMED(*this);
113  GECODE_REWRITE(*this,(NoSubset<View0,View1>::post(home(*this),x0,x1)));
114  }
115 
116  // check whether cardinalities still allow subset
117  if (x0.cardMin() > x1.cardMax()) {
118  if (rm != RM_PMI)
119  GECODE_ME_CHECK(b.zero_none(home));
120  return home.ES_SUBSUMED(*this);
121  }
122 
123  // check lub(x0) subset glb(x1)
124  {
125  LubRanges<View0> x0ub(x0);
126  GlbRanges<View1> x1lb(x1);
128  if (!d()) {
129  if (rm != RM_IMP)
130  GECODE_ME_CHECK(b.one_none(home));
131  return home.ES_SUBSUMED(*this);
132  }
133  }
134 
135  // check glb(x0) subset lub(x1)
136  {
137  GlbRanges<View0> x0lb(x0);
138  LubRanges<View1> x1ub(x1);
140  if (d()) {
141  if (rm != RM_PMI)
142  GECODE_ME_CHECK(b.zero_none(home));
143  return home.ES_SUBSUMED(*this);
144  } else if (x0.assigned() && x1.assigned()) {
145  if (rm != RM_IMP)
146  GECODE_ME_CHECK(b.one_none(home));
147  return home.ES_SUBSUMED(*this);
148  }
149  }
150 
151  if (x0.cardMin() > 0) {
152  LubRanges<View0> x0ub(x0);
153  LubRanges<View1> x1ub(x1);
155  i(x0ub,x1ub);
156  if (!i()) {
157  if (rm != RM_PMI)
158  GECODE_ME_CHECK(b.zero_none(home));
159  return home.ES_SUBSUMED(*this);
160  }
161  }
162 
163  return ES_FIX;
164  }
165 
166 }}}
167 
168 // STATISTICS: set-prop
#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:850
CtrlView b
Boolean control view.
Definition: rel.hh:122
ExecStatus ES_SUBSUMED(Propagator &p)
Definition: core.hpp:3614
Propagator for the subset constraint
Definition: rel.hh:64
virtual void reschedule(Space &home)
Schedule function.
Definition: re-subset.hpp:71
Base-class for propagators.
Definition: core.hpp:1092
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition: re-subset.hpp:103
Range iterator for the greatest lower bound.
Definition: var-imp.hpp:363
Propagation has computed fixpoint.
Definition: core.hpp:545
Computation spaces.
Definition: core.hpp:1748
Range iterator for the least upper bound.
Definition: var-imp.hpp:321
virtual Actor * copy(Space &home, bool share)
Copy propagator during cloning.
Definition: re-subset.hpp:97
Base-class for both propagators and branchers.
Definition: core.hpp:696
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
struct Gecode::@579::NNF::@61::@62 b
For binary nodes (and, or, eqv)
#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
ReSubset(Space &home, bool share, ReSubset &p)
Constructor for cloning p.
Definition: re-subset.hpp:54
Reified subset propagator
Definition: rel.hh:115
View1 x1
Variable view.
Definition: rel.hh:120
virtual size_t dispose(Space &home)
Delete actor and return its size.
Definition: core.hpp:3354
Propagation cost.
Definition: core.hpp:554
ExecStatus
Definition: core.hpp:540
#define forceinline
Definition: config.hpp:173
Execution is okay.
Definition: core.hpp:544
Propagator for the negated subset constraint
Definition: rel.hh:90
static PropCost ternary(PropCost::Mod m)
Three variables for modifier pcm.
Definition: core.hpp:4850
Gecode toplevel namespace
Implication for reification.
Definition: int.hh:843
Range iterator for computing set difference.
Definition: ranges-diff.hpp:47
View0 x0
Variable view.
Definition: rel.hh:118
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:169
Home class for posting propagators
Definition: core.hpp:922
const Gecode::PropCond PC_INT_VAL
Propagate when a view becomes assigned (single value)
Definition: var-type.hpp:82