Generated on Fri Jan 28 2022 04:43:06 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  * This file is part of Gecode, the generic constraint
12  * development environment:
13  * http://www.gecode.org
14  *
15  * Permission is hereby granted, free of charge, to any person obtaining
16  * a copy of this software and associated documentation files (the
17  * "Software"), to deal in the Software without restriction, including
18  * without limitation the rights to use, copy, modify, merge, publish,
19  * distribute, sublicense, and/or sell copies of the Software, and to
20  * permit persons to whom the Software is furnished to do so, subject to
21  * the following conditions:
22  *
23  * The above copyright notice and this permission notice shall be
24  * included in all copies or substantial portions of the Software.
25  *
26  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
27  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
28  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
29  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
30  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
31  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
32  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33  *
34  */
35 
36 namespace Gecode { namespace Set { namespace Rel {
37 
38  template<class View0, class View1, class CtrlView, ReifyMode rm>
41  View1 y1, CtrlView b0)
42  : Propagator(home), x0(y0), x1(y1), b(b0) {
43  b.subscribe(home,*this, Gecode::Int::PC_INT_VAL);
44  x0.subscribe(home,*this, PC_SET_ANY);
45  x1.subscribe(home,*this, PC_SET_ANY);
46  }
47 
48  template<class View0, class View1, class CtrlView, ReifyMode rm>
51  ReSubset& p)
52  : Propagator(home,p) {
53  x0.update(home,p.x0);
54  x1.update(home,p.x1);
55  b.update(home,p.b);
56  }
57 
58  template<class View0, class View1, class CtrlView, ReifyMode rm>
59  PropCost
61  const ModEventDelta&) const {
63  }
64 
65  template<class View0, class View1, class CtrlView, ReifyMode rm>
66  void
68  b.reschedule(home,*this, Gecode::Int::PC_INT_VAL);
69  x0.reschedule(home,*this, PC_SET_ANY);
70  x1.reschedule(home,*this, PC_SET_ANY);
71  }
72 
73  template<class View0, class View1, class CtrlView, ReifyMode rm>
74  forceinline size_t
76  b.cancel(home,*this, Gecode::Int::PC_INT_VAL);
77  x0.cancel(home,*this, PC_SET_ANY);
78  x1.cancel(home,*this, PC_SET_ANY);
79  (void) Propagator::dispose(home);
80  return sizeof(*this);
81  }
82 
83  template<class View0, class View1, class CtrlView, ReifyMode rm>
86  CtrlView b) {
87  if (!same(x0,x1)) {
88  (void) new (home) ReSubset<View0,View1,CtrlView,rm>(home,x0,x1,b);
89  } else if (rm != RM_IMP) {
90  GECODE_ME_CHECK(b.one(home));
91  }
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,*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
ReSubset(Space &home, ReSubset &p)
Constructor for cloning p.
Definition: re-subset.hpp:50
#define GECODE_REWRITE(prop, post)
Rewrite propagator by executing post function.
Definition: macros.hpp:116
virtual size_t dispose(Space &home)
Delete propagator and return its size.
Definition: re-subset.hpp:75
Inverse implication for reification.
Definition: int.hh:869
CtrlView b
Boolean control view.
Definition: rel.hh:122
ExecStatus ES_SUBSUMED(Propagator &p)
Definition: core.hpp:3490
Propagator for the subset constraint
Definition: rel.hh:64
virtual void reschedule(Space &home)
Schedule function.
Definition: re-subset.hpp:67
Base-class for propagators.
Definition: core.hpp:1023
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:359
#define forceinline
Definition: config.hpp:185
Propagation has computed fixpoint.
Definition: core.hpp:476
Computation spaces.
Definition: core.hpp:1701
Range iterator for the least upper bound.
Definition: var-imp.hpp:317
Base-class for both propagators and branchers.
Definition: core.hpp:627
virtual Actor * copy(Space &home)
Copy propagator during cloning.
Definition: re-subset.hpp:97
Gecode::IntSet d(v, 7)
int p
Number of positive literals for node type.
Definition: bool-expr.cpp:232
Gecode::IntArgs i({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:60
bool same(VX, VY)
Test whether two views are in fact the same.
Definition: common.hpp:57
struct Gecode::@593::NNF::@62::@63 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:52
const Gecode::PropCond PC_SET_ANY
Propagate when any bound or the cardinality of a view changes.
Definition: var-type.hpp:248
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:3209
Propagation cost.
Definition: core.hpp:485
ExecStatus
Definition: core.hpp:471
Execution is okay.
Definition: core.hpp:475
Propagator for the negated subset constraint
Definition: rel.hh:90
static PropCost ternary(PropCost::Mod m)
Three variables for modifier pcm.
Definition: core.hpp:4732
Gecode toplevel namespace
Implication for reification.
Definition: int.hh:862
Range iterator for computing set difference.
Definition: ranges-diff.hpp:43
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:85
int ModEventDelta
Modification event deltas.
Definition: core.hpp:89
Home class for posting propagators
Definition: core.hpp:853
const Gecode::PropCond PC_INT_VAL
Propagate when a view becomes assigned (single value)
Definition: var-type.hpp:82