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