Generated on Tue Feb 11 2025 17:33:26 for Gecode by doxygen 1.12.0
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
34namespace 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>
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>
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
int p
Number of positive literals for node type.
Base-class for both propagators and branchers.
Definition core.hpp:628
virtual size_t dispose(Space &home)
Delete actor and return its size.
Definition core.hpp:3252
int size(void) const
Return size of array (number of elements)
Definition array.hpp:1607
Home class for posting propagators
Definition core.hpp:856
Integer sets.
Definition int.hh:174
static const IntSet empty
Empty set.
Definition int.hh:283
Cached integer view.
Definition view.hpp:1166
Value iterator from range iterator.
int val(void) const
Return current value.
Propagation cost.
Definition core.hpp:486
static PropCost quadratic(PropCost::Mod m, unsigned int n)
Quadratic complexity for modifier m and size measure n.
Definition core.hpp:4787
@ HI
Expensive.
Definition core.hpp:514
Base-class for propagators.
Definition core.hpp:1064
size_t size
The size of the propagator (used during subsumption)
Definition core.hpp:1077
Propagator for successors/predecessors channelling
Definition channel.hh:226
virtual void reschedule(Space &home)
Schedule function.
Definition set.hpp:85
ViewArray< CachedView< View > > xs
SetViews, reflects the successors of .
Definition channel.hh:229
ViewArray< CachedView< View > > ys
SetViews, reflects the predecessors of .
Definition channel.hh:231
Range iterator for difference of greatest lower bound and cache
Definition view.hpp:1138
Range iterator for difference of least upper bound and cache
Definition view.hpp:1155
Computation spaces.
Definition core.hpp:1742
View arrays.
Definition array.hpp:253
ExecStatus ES_SUBSUMED(Propagator &p)
Definition core.hpp:3563
int ModEventDelta
Modification event deltas.
Definition core.hpp:89
#define GECODE_ME_CHECK(me)
Check whether modification event me is failed, and forward failure.
Definition macros.hpp:52
const int min
Smallest allowed integer value.
Definition int.hh:118
const int max
Largest allowed integer value.
Definition int.hh:116
const Gecode::PropCond PC_SET_ANY
Propagate when any bound or the cardinality of a view changes.
Definition var-type.hpp:248
Gecode toplevel namespace
ExecStatus
Definition core.hpp:472
@ ES_OK
Execution is okay.
Definition core.hpp:476
@ ES_FIX
Propagation has computed fixpoint.
Definition core.hpp:477
#define forceinline
Definition config.hpp:187