Generated on Sat Jan 20 2018 22:21:14 for Gecode by doxygen 1.8.13
set.hpp
Go to the documentation of this file.
1 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2 /*
3  * Main authors:
4  * Denys Duchier <denys.duchier@univ-orleans.fr>
5  *
6  * Copyright:
7  * Denys Duchier, 2011
8  *
9  * Last modified:
10  * $Date: 2016-06-29 17:28:17 +0200 (Wed, 29 Jun 2016) $ by $Author: schulte $
11  * $Revision: 15137 $
12  *
13  * This file is part of Gecode, the generic constraint
14  * development environment:
15  * http://www.gecode.org
16  *
17  * Permission is hereby granted, free of charge, to any person obtaining
18  * a copy of this software and associated documentation files (the
19  * "Software"), to deal in the Software without restriction, including
20  * without limitation the rights to use, copy, modify, merge, publish,
21  * distribute, sublicense, and/or sell copies of the Software, and to
22  * permit persons to whom the Software is furnished to do so, subject to
23  * the following conditions:
24  *
25  * The above copyright notice and this permission notice shall be
26  * included in all copies or substantial portions of the Software.
27  *
28  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
29  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
30  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
31  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
32  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
33  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
34  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35  *
36  */
37 
38 namespace Gecode { namespace Set { namespace Channel {
39 
40  template <typename View>
45  : Propagator(home), xs(xs0), ys(ys0) {
46  for (int i=xs.size(); i--;)
47  xs[i].initCache(home,IntSet::empty,IntSet(0,ys.size()-1));
48  for (int i=ys.size(); i--;)
49  ys[i].initCache(home,IntSet::empty,IntSet(0,xs.size()-1));
50  xs.subscribe(home,*this, PC_SET_ANY);
51  ys.subscribe(home,*this, PC_SET_ANY);
52  }
53 
54  template <typename View>
57  : Propagator(home, share, p) {
58  xs.update(home, share, p.xs);
59  ys.update(home, share, p.ys);
60  }
61 
62  template <typename View>
67  int xssize = xs.size();
68  for (int i=ys.size(); i--;) {
69  GECODE_ME_CHECK(ys[i].exclude(home, xssize, Limits::max));
70  GECODE_ME_CHECK(ys[i].exclude(home, Limits::min, -1));
71  }
72  int yssize = ys.size();
73  for (int i=xs.size(); i--;) {
74  GECODE_ME_CHECK(xs[i].exclude(home, yssize, Limits::max));
75  GECODE_ME_CHECK(xs[i].exclude(home, Limits::min, -1));
76  }
77  (void) new (home) ChannelSet(home,xs,ys);
78  return ES_OK;
79  }
80 
81  template <typename View>
82  PropCost
83  ChannelSet<View>::cost(const Space&, const ModEventDelta&) const {
84  return PropCost::quadratic(PropCost::HI, xs.size()+ys.size());
85  }
86 
87  template <typename View>
88  void
90  xs.reschedule(home,*this, PC_SET_ANY);
91  ys.reschedule(home,*this, PC_SET_ANY);
92  }
93 
94  template <typename View>
95  forceinline size_t
97  xs.cancel(home, *this, PC_SET_ANY);
98  ys.cancel(home, *this, PC_SET_ANY);
99  (void) Propagator::dispose(home);
100  return sizeof(*this);
101  }
102 
103  template <typename View>
104  Actor*
105  ChannelSet<View>::copy(Space& home, bool share) {
106  return new (home) ChannelSet(home,share,*this);
107  }
108 
109  template <typename View>
110  ExecStatus
112  int assigned = 0;
113  bool again = true;
114  while (again) {
115  assigned = 0;
116  again = false;
117  for (int i=xs.size(); i--;) {
118  if (xs[i].assigned())
119  ++assigned;
120  if (xs[i].glbModified()) {
121  GlbDiffRanges<View> xilb(xs[i]);
123  for (;dv();++dv)
124  GECODE_ME_CHECK(ys[dv.val()].include(home,i));
125  xs[i].cacheGlb(home);
126  again = true;
127  }
128  if (xs[i].lubModified()) {
129  LubDiffRanges<View> xiub(xs[i]);
131  for (;dv();++dv)
132  GECODE_ME_CHECK(ys[dv.val()].exclude(home,i));
133  xs[i].cacheLub(home);
134  again = true;
135  }
136  }
137  for (int i=ys.size(); i--;) {
138  if (ys[i].assigned())
139  ++assigned;
140  if (ys[i].glbModified()) {
141  GlbDiffRanges<View> yilb(ys[i]);
143  for (;dv();++dv)
144  GECODE_ME_CHECK(xs[dv.val()].include(home,i));
145  ys[i].cacheGlb(home);
146  again = true;
147  }
148  if (ys[i].lubModified()) {
149  LubDiffRanges<View> yiub(ys[i]);
151  for (;dv();++dv)
152  GECODE_ME_CHECK(xs[dv.val()].exclude(home,i));
153  ys[i].cacheLub(home);
154  again = true;
155  }
156  }
157  }
158 
159  return (assigned == xs.size()+ys.size()) ? home.ES_SUBSUMED(*this) : ES_FIX;
160  }
161 
162 }}}
163 
164 // STATISTICS: set-prop
static PropCost quadratic(PropCost::Mod m, unsigned int n)
Quadratic complexity for modifier m and size measure n.
Definition: core.hpp:4832
Propagator for successors/predecessors channelling
Definition: channel.hh:230
const int min
Smallest allowed integer in integer set.
Definition: set.hh:103
ExecStatus ES_SUBSUMED(Propagator &p)
Definition: core.hpp:3614
ViewArray< CachedView< View > > xs
SetViews, reflects the successors of .
Definition: channel.hh:233
Base-class for propagators.
Definition: core.hpp:1092
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition: set.hpp:111
Propagation has computed fixpoint.
Definition: core.hpp:545
const int max
Largest allowed integer in integer set.
Definition: set.hh:101
Computation spaces.
Definition: core.hpp:1748
int val(void) const
Return current value.
Base-class for both propagators and branchers.
Definition: core.hpp:696
ModEvent exclude(Space &home, View &x, int s)
Prune view x to exclude all values from s.
Definition: set-op.hpp:141
int p
Number of positive literals for node type.
Definition: bool-expr.cpp:236
Gecode::IntArgs i(4, 1, 2, 3, 4)
virtual size_t dispose(Space &home)
Delete propagator and return its size.
Definition: set.hpp:96
ChannelSet(Space &home, bool share, ChannelSet &p)
Constructor for cloning p.
Definition: set.hpp:56
Value iterator from range iterator.
Range iterator for difference of greatest lower bound and cache
Definition: view.hpp:909
Integer sets.
Definition: int.hh:174
Expensive.
Definition: core.hpp:582
View arrays.
Definition: array.hpp:234
#define GECODE_ME_CHECK(me)
Check whether modification event me is failed, and forward failure.
Definition: macros.hpp:56
static const IntSet empty
Empty set.
Definition: int.hh:265
const Gecode::PropCond PC_SET_ANY
Propagate when any bound or the cardinality of a view changes.
Definition: var-type.hpp:248
ViewArray< CachedView< View > > ys
SetViews, reflects the predecessors of .
Definition: channel.hh:235
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
bool assigned(View x, int v)
Whether x is assigned to value v.
Definition: single.hpp:47
virtual PropCost cost(const Space &home, const ModEventDelta &med) const
Cost function (defined as PC_QUADRATIC_HI)
Definition: set.hpp:83
#define forceinline
Definition: config.hpp:173
Cached integer view.
Definition: view.hpp:1107
Execution is okay.
Definition: core.hpp:544
virtual void reschedule(Space &home)
Schedule function.
Definition: set.hpp:89
Gecode toplevel namespace
static ExecStatus post(Home home, ViewArray< CachedView< View > > &x, ViewArray< CachedView< View > > &y)
Post propagator for .
Definition: set.hpp:64
virtual Actor * copy(Space &home, bool)
Copy propagator during cloning.
Definition: set.hpp:105
int ModEventDelta
Modification event deltas.
Definition: core.hpp:169
Home class for posting propagators
Definition: core.hpp:922
Range iterator for difference of least upper bound and cache
Definition: view.hpp:908