Generated on Sat Feb 7 2015 02:01:30 for Gecode by doxygen 1.8.9.1
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: 2012-10-19 05:58:26 +0200 (Fri, 19 Oct 2012) $ by $Author: tack $
13  * $Revision: 13156 $
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, ReifyMode rm>
45  View1 y1, Gecode::Int::BoolView y2)
46  : Propagator(home), x0(y0), x1(y1), b(y2) {
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, ReifyMode rm>
55  : Propagator(home,share,p) {
56  x0.update(home,share,p.x0);
57  x1.update(home,share,p.x1);
58  b.update(home,share,p.b);
59  }
60 
61  template<class View0, class View1, ReifyMode rm>
62  PropCost
65  }
66 
67  template<class View0, class View1, ReifyMode rm>
68  forceinline size_t
70  b.cancel(home,*this, Gecode::Int::PC_INT_VAL);
71  x0.cancel(home,*this, PC_SET_ANY);
72  x1.cancel(home,*this, PC_SET_ANY);
73  (void) Propagator::dispose(home);
74  return sizeof(*this);
75  }
76 
77  template<class View0, class View1, ReifyMode rm>
79  ReSubset<View0,View1,rm>::post(Home home, View0 x0, View1 x1,
81  (void) new (home) ReSubset<View0,View1,rm>(home,x0,x1,b);
82  return ES_OK;
83  }
84 
85  template<class View0, class View1, ReifyMode rm>
86  Actor*
88  return new (home) ReSubset<View0,View1,rm>(home,share,*this);
89  }
90 
91  template<class View0, class View1, ReifyMode rm>
94  if (b.one()) {
95  if (rm == RM_PMI)
96  return home.ES_SUBSUMED(*this);
97  GECODE_REWRITE(*this,(Subset<View0,View1>::post(home(*this),x0,x1)));
98  }
99  if (b.zero()) {
100  if (rm == RM_IMP)
101  return home.ES_SUBSUMED(*this);
102  GECODE_REWRITE(*this,(NoSubset<View0,View1>::post(home(*this),x0,x1)));
103  }
104 
105  // check whether cardinalities still allow subset
106  if (x0.cardMin() > x1.cardMax()) {
107  if (rm != RM_PMI)
108  GECODE_ME_CHECK(b.zero_none(home));
109  return home.ES_SUBSUMED(*this);
110  }
111 
112  // check lub(x0) subset glb(x1)
113  {
114  LubRanges<View0> x0ub(x0);
115  GlbRanges<View1> x1lb(x1);
117  if (!d()) {
118  if (rm != RM_IMP)
119  GECODE_ME_CHECK(b.one_none(home));
120  return home.ES_SUBSUMED(*this);
121  }
122  }
123 
124  // check glb(x0) subset lub(x1)
125  {
126  GlbRanges<View0> x0lb(x0);
127  LubRanges<View1> x1ub(x1);
129  if (d()) {
130  if (rm != RM_PMI)
131  GECODE_ME_CHECK(b.zero_none(home));
132  return home.ES_SUBSUMED(*this);
133  } else if (x0.assigned() && x1.assigned()) {
134  if (rm != RM_IMP)
135  GECODE_ME_CHECK(b.one_none(home));
136  return home.ES_SUBSUMED(*this);
137  }
138  }
139 
140  if (x0.cardMin() > 0) {
141  LubRanges<View0> x0ub(x0);
142  LubRanges<View1> x1ub(x1);
144  i(x0ub,x1ub);
145  if (!i()) {
146  if (rm != RM_PMI)
147  GECODE_ME_CHECK(b.zero_none(home));
148  return home.ES_SUBSUMED(*this);
149  }
150  }
151 
152  return ES_FIX;
153  }
154 
155 }}}
156 
157 // STATISTICS: set-prop
#define GECODE_REWRITE(prop, post)
Rewrite propagator by executing post function.
Definition: macros.hpp:109
Inverse implication for reification.
Definition: int.hh:847
ExecStatus ES_SUBSUMED(Propagator &p)
Definition: core.hpp:2973
Propagator for the subset constraint
Definition: rel.hh:64
Base-class for propagators.
Definition: core.hpp:755
Range iterator for the greatest lower bound.
Definition: var-imp.hpp:363
Propagation has computed fixpoint.
Definition: core.hpp:528
Computation spaces.
Definition: core.hpp:1362
Range iterator for the least upper bound.
Definition: var-imp.hpp:321
Base-class for both propagators and branchers.
Definition: core.hpp:666
Gecode::IntSet d(v, 7)
virtual Actor * copy(Space &home, bool)
Copy propagator during cloning.
Definition: re-subset.hpp:87
void subscribe(Space &home, Propagator &p, PropCond pc, bool schedule=true)
Subscribe propagator p with propagation condition pc to view.
Definition: view.hpp:453
int p
Number of positive literals for node type.
Definition: bool-expr.cpp:236
Gecode::IntArgs i(4, 1, 2, 3, 4)
Gecode::Int::BoolView b
Definition: rel.hh:119
Range iterator for computing intersection (binary)
void update(Space &home, bool share, VarImpView< Var > &y)
Update this view to be a clone of view y.
Definition: view.hpp:494
virtual PropCost cost(const Space &home, const ModEventDelta &med) const
Cost function (defined as PC_TERNARY_LO)
Definition: re-subset.hpp:63
#define GECODE_ME_CHECK(me)
Check whether modification event me is failed, and forward failure.
Definition: macros.hpp:45
const Gecode::PropCond PC_SET_ANY
Propagate when any bound or the cardinality of a view changes.
Definition: var-type.hpp:248
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition: re-subset.hpp:93
ReSubset(Space &home, bool share, ReSubset &)
Constructor for cloning p.
Definition: re-subset.hpp:54
Reified subset propagator
Definition: rel.hh:115
virtual size_t dispose(Space &home)
Delete actor and return its size.
Definition: core.hpp:2877
Propagation cost.
Definition: core.hpp:537
ExecStatus
Definition: core.hpp:523
#define forceinline
Definition: config.hpp:132
Execution is okay.
Definition: core.hpp:527
Propagator for the negated subset constraint
Definition: rel.hh:90
static PropCost ternary(PropCost::Mod m)
Three variables for modifier pcm.
Definition: core.hpp:4050
struct Gecode::@518::NNF::@57::@58 b
For binary nodes (and, or, eqv)
Gecode toplevel namespace
Implication for reification.
Definition: int.hh:840
Range iterator for computing set difference.
Definition: ranges-diff.hpp:47
int ModEventDelta
Modification event deltas.
Definition: core.hpp:173
Home class for posting propagators
Definition: core.hpp:717
static ExecStatus post(Home home, View0 x, View1 y, Gecode::Int::BoolView b)
Post propagator for .
Definition: re-subset.hpp:79
virtual size_t dispose(Space &home)
Delete propagator and return its size.
Definition: re-subset.hpp:69
const Gecode::PropCond PC_INT_VAL
Propagate when a view becomes assigned (single value)
Definition: var-type.hpp:82
Boolean view for Boolean variables.
Definition: view.hpp:1315