Generated on Sat Feb 7 2015 02:01:22 for Gecode by doxygen 1.8.9.1
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: 2011-11-03 11:52:07 +0100 (Thu, 03 Nov 2011) $ by $Author: tack $
11  * $Revision: 12452 $
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  {
47  for (int i=xs.size(); i--;)
48  xs[i].initCache(home,IntSet::empty,IntSet(0,ys.size()-1));
49  for (int i=ys.size(); i--;)
50  ys[i].initCache(home,IntSet::empty,IntSet(0,xs.size()-1));
51  xs.subscribe(home,*this, PC_SET_ANY);
52  ys.subscribe(home,*this, PC_SET_ANY);
53  }
54 
55  template <typename View>
58  : Propagator(home, share, p)
59  {
60  xs.update(home, share, p.xs);
61  ys.update(home, share, p.ys);
62  }
63 
64  template <typename View>
69  {
70  int xssize = xs.size();
71  for (int i=ys.size(); i--;)
72  {
73  GECODE_ME_CHECK(ys[i].exclude(home, xssize, Limits::max));
74  GECODE_ME_CHECK(ys[i].exclude(home, Limits::min, -1));
75  }
76  int yssize = ys.size();
77  for (int i=xs.size(); i--;)
78  {
79  GECODE_ME_CHECK(xs[i].exclude(home, yssize, Limits::max));
80  GECODE_ME_CHECK(xs[i].exclude(home, Limits::min, -1));
81  }
82  (void) new (home) ChannelSet(home,xs,ys);
83  return ES_OK;
84  }
85 
86  template <typename View>
87  PropCost
89  {
90  return PropCost::quadratic(PropCost::HI, xs.size()+ys.size());
91  }
92 
93  template <typename View>
94  forceinline size_t
96  {
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  {
107  return new (home) ChannelSet(home,share,*this);
108  }
109 
110  template <typename View>
111  ExecStatus
113  {
114  int assigned = 0;
115  bool again = true;
116  while (again)
117  {
118  assigned = 0;
119  again = false;
120  for (int i=xs.size(); i--;)
121  {
122  if (xs[i].assigned())
123  ++assigned;
124  if (xs[i].glbModified())
125  {
126  GlbDiffRanges<View> xilb(xs[i]);
128  for (;dv();++dv)
129  GECODE_ME_CHECK(ys[dv.val()].include(home,i));
130  xs[i].cacheGlb(home);
131  again = true;
132  }
133  if (xs[i].lubModified())
134  {
135  LubDiffRanges<View> xiub(xs[i]);
137  for (;dv();++dv)
138  GECODE_ME_CHECK(ys[dv.val()].exclude(home,i));
139  xs[i].cacheLub(home);
140  again = true;
141  }
142  }
143  for (int i=ys.size(); i--;)
144  {
145  if (ys[i].assigned())
146  ++assigned;
147  if (ys[i].glbModified())
148  {
149  GlbDiffRanges<View> yilb(ys[i]);
151  for (;dv();++dv)
152  GECODE_ME_CHECK(xs[dv.val()].include(home,i));
153  ys[i].cacheGlb(home);
154  again = true;
155  }
156  if (ys[i].lubModified())
157  {
158  LubDiffRanges<View> yiub(ys[i]);
160  for (;dv();++dv)
161  GECODE_ME_CHECK(xs[dv.val()].exclude(home,i));
162  ys[i].cacheLub(home);
163  again = true;
164  }
165  }
166  }
167 
168  return (assigned == xs.size()+ys.size()) ? home.ES_SUBSUMED(*this) : ES_FIX;
169  }
170 }}}
171 
172 // STATISTICS: set-prop
static PropCost quadratic(PropCost::Mod m, unsigned int n)
Quadratic complexity for modifier m and size measure n.
Definition: core.hpp:4032
Propagator for successors/predecessors channelling
Definition: channel.hh:224
const int min
Smallest allowed integer in integer set.
Definition: set.hh:101
ExecStatus ES_SUBSUMED(Propagator &p)
Definition: core.hpp:2973
int size(void) const
Return size of array (number of elements)
Definition: array.hpp:1662
ViewArray< CachedView< View > > xs
SetViews, reflects the successors of .
Definition: channel.hh:227
Base-class for propagators.
Definition: core.hpp:755
Expensive.
Definition: core.hpp:564
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition: set.hpp:112
Propagation has computed fixpoint.
Definition: core.hpp:528
const int max
Largest allowed integer in integer set.
Definition: set.hh:99
Computation spaces.
Definition: core.hpp:1362
Base-class for both propagators and branchers.
Definition: core.hpp:666
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:95
ChannelSet(Space &home, bool share, ChannelSet &p)
Constructor for cloning p.
Definition: set.hpp:57
Value iterator from range iterator.
Range iterator for difference of greatest lower bound and cache
Definition: view.hpp:907
Integer sets.
Definition: int.hh:171
View arrays.
Definition: array.hpp:234
#define GECODE_ME_CHECK(me)
Check whether modification event me is failed, and forward failure.
Definition: macros.hpp:45
static const IntSet empty
Empty set.
Definition: int.hh:262
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:229
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
bool assigned(View x, int v)
Whether x is assigned to value v.
Definition: single.hpp:47
#define forceinline
Definition: config.hpp:132
Cached integer view.
Definition: view.hpp:1107
Execution is okay.
Definition: core.hpp:527
int val(void) const
Return current value.
Gecode toplevel namespace
static ExecStatus post(Home home, ViewArray< CachedView< View > > &x, ViewArray< CachedView< View > > &y)
Post propagator for .
Definition: set.hpp:66
virtual Actor * copy(Space &home, bool)
Copy propagator during cloning.
Definition: set.hpp:105
int ModEventDelta
Modification event deltas.
Definition: core.hpp:173
Home class for posting propagators
Definition: core.hpp:717
Range iterator for difference of least upper bound and cache
Definition: view.hpp:906
virtual PropCost cost(const Space &home, const ModEventDelta &med) const
Cost function (defined as PC_QUADRATIC_HI)
Definition: set.hpp:88