Generated on Thu Mar 16 2017 03:24:24 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: 2016-06-29 17:28:17 +0200 (Wed, 29 Jun 2016) $ by $Author: schulte $
13  * $Revision: 15137 $
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  void
71  x0.reschedule(home,*this, PC_SET_ANY);
72  x1.reschedule(home,*this, PC_SET_ANY);
73  }
74 
75  template<class View0, class View1, ReifyMode rm>
76  forceinline size_t
78  b.cancel(home,*this, Gecode::Int::PC_INT_VAL);
79  x0.cancel(home,*this, PC_SET_ANY);
80  x1.cancel(home,*this, PC_SET_ANY);
81  (void) Propagator::dispose(home);
82  return sizeof(*this);
83  }
84 
85  template<class View0, class View1, ReifyMode rm>
89  (void) new (home) ReSubset<View0,View1,rm>(home,x0,x1,b);
90  return ES_OK;
91  }
92 
93  template<class View0, class View1, ReifyMode rm>
94  Actor*
96  return new (home) ReSubset<View0,View1,rm>(home,share,*this);
97  }
98 
99  template<class View0, class View1, ReifyMode rm>
100  ExecStatus
102  if (b.one()) {
103  if (rm == RM_PMI)
104  return home.ES_SUBSUMED(*this);
105  GECODE_REWRITE(*this,(Subset<View0,View1>::post(home(*this),x0,x1)));
106  }
107  if (b.zero()) {
108  if (rm == RM_IMP)
109  return home.ES_SUBSUMED(*this);
110  GECODE_REWRITE(*this,(NoSubset<View0,View1>::post(home(*this),x0,x1)));
111  }
112 
113  // check whether cardinalities still allow subset
114  if (x0.cardMin() > x1.cardMax()) {
115  if (rm != RM_PMI)
116  GECODE_ME_CHECK(b.zero_none(home));
117  return home.ES_SUBSUMED(*this);
118  }
119 
120  // check lub(x0) subset glb(x1)
121  {
122  LubRanges<View0> x0ub(x0);
123  GlbRanges<View1> x1lb(x1);
125  if (!d()) {
126  if (rm != RM_IMP)
127  GECODE_ME_CHECK(b.one_none(home));
128  return home.ES_SUBSUMED(*this);
129  }
130  }
131 
132  // check glb(x0) subset lub(x1)
133  {
134  GlbRanges<View0> x0lb(x0);
135  LubRanges<View1> x1ub(x1);
137  if (d()) {
138  if (rm != RM_PMI)
139  GECODE_ME_CHECK(b.zero_none(home));
140  return home.ES_SUBSUMED(*this);
141  } else if (x0.assigned() && x1.assigned()) {
142  if (rm != RM_IMP)
143  GECODE_ME_CHECK(b.one_none(home));
144  return home.ES_SUBSUMED(*this);
145  }
146  }
147 
148  if (x0.cardMin() > 0) {
149  LubRanges<View0> x0ub(x0);
150  LubRanges<View1> x1ub(x1);
152  i(x0ub,x1ub);
153  if (!i()) {
154  if (rm != RM_PMI)
155  GECODE_ME_CHECK(b.zero_none(home));
156  return home.ES_SUBSUMED(*this);
157  }
158  }
159 
160  return ES_FIX;
161  }
162 
163 }}}
164 
165 // STATISTICS: set-prop
View1 x1
Variable view.
Definition: rel.hh:120
void cancel(Space &home, Propagator &p, PropCond pc)
Cancel subscription of propagator p with propagation condition pc to view.
Definition: view.hpp:477
#define GECODE_REWRITE(prop, post)
Rewrite propagator by executing post function.
Definition: macros.hpp:120
bool zero(void) const
Test whether view is assigned to be zero.
Definition: bool.hpp:214
Inverse implication for reification.
Definition: int.hh:848
ExecStatus ES_SUBSUMED(Propagator &p)
Definition: core.hpp:3484
Propagator for the subset constraint
Definition: rel.hh:64
bool one(void) const
Test whether view is assigned to be one.
Definition: bool.hpp:218
Base-class for propagators.
Definition: core.hpp:1012
Range iterator for the greatest lower bound.
Definition: var-imp.hpp:363
void reschedule(Space &home, Propagator &p, PropCond pc)
Re-schedule propagator p with propagation condition pc.
Definition: view.hpp:482
Propagation has computed fixpoint.
Definition: core.hpp:541
Computation spaces.
Definition: core.hpp:1672
Range iterator for the least upper bound.
Definition: var-imp.hpp:321
Base-class for both propagators and branchers.
Definition: core.hpp:682
Gecode::IntSet d(v, 7)
void subscribe(Space &home, Propagator &p, PropCond pc, bool schedule=true)
Subscribe propagator p with propagation condition pc to view.
Definition: view.hpp:471
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
Boolean control view.
Definition: rel.hh:122
ModEvent zero_none(Space &home)
Assign not yet assigned view to zero.
Definition: bool.hpp:232
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:63
virtual void reschedule(Space &home)
Schedule function.
Definition: re-subset.hpp:69
void update(Space &home, bool share, VarImpView< Var > &y)
Update this view to be a clone of view y.
Definition: view.hpp:517
#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
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition: re-subset.hpp:101
View0 x0
Variable view.
Definition: rel.hh:118
virtual Actor * copy(Space &home, bool share)
Copy propagator during cloning.
Definition: re-subset.hpp:95
Reified subset propagator
Definition: rel.hh:115
virtual size_t dispose(Space &home)
Delete actor and return its size.
Definition: core.hpp:3281
Propagation cost.
Definition: core.hpp:550
ExecStatus
Definition: core.hpp:536
#define forceinline
Definition: config.hpp:173
Execution is okay.
Definition: core.hpp:540
Propagator for the negated subset constraint
Definition: rel.hh:90
static PropCost ternary(PropCost::Mod m)
Three variables for modifier pcm.
Definition: core.hpp:4586
Gecode toplevel namespace
ReSubset(Space &home, bool share, ReSubset &p)
Constructor for cloning p.
Definition: re-subset.hpp:54
Implication for reification.
Definition: int.hh:841
ModEvent one_none(Space &home)
Assign not yet assigned view to one.
Definition: bool.hpp:236
Range iterator for computing set difference.
Definition: ranges-diff.hpp:47
struct Gecode::@554::NNF::@60::@61 b
For binary nodes (and, or, eqv)
int ModEventDelta
Modification event deltas.
Definition: core.hpp:169
Home class for posting propagators
Definition: core.hpp:905
static ExecStatus post(Home home, View0 x, View1 y, Gecode::Int::BoolView b)
Post propagator for .
Definition: re-subset.hpp:87
virtual size_t dispose(Space &home)
Delete propagator and return its size.
Definition: re-subset.hpp:77
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