Generated on Thu Jan 16 2025 00:00:00 for Gecode by doxygen 1.14.0
int.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 * Gabor Szokoli <szokoli@gecode.org>
7 *
8 * Copyright:
9 * Guido Tack, 2004
10 * Christian Schulte, 2004
11 * Gabor Szokoli, 2004
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#include <gecode/int.hh>
39
40namespace Gecode { namespace Set { namespace Channel {
41
42 template<class View>
48 : Propagator(home), xs(xs0), ys(ys0) {
49 for (int i=xs.size(); i--;)
50 xs[i].initCache(home,IntSet(0,ys.size()-1));
51 for (int i=ys.size(); i--;)
52 ys[i].initCache(home,IntSet::empty,IntSet(0,xs.size()-1));
53 xs.subscribe(home,*this, Gecode::Int::PC_INT_DOM);
54 ys.subscribe(home,*this, PC_SET_ANY);
55 }
56
57 template<class View>
60 : Propagator(home,p) {
61 xs.update(home,p.xs);
62 ys.update(home,p.ys);
63 }
64
65 template<class View>
71 // Sharing of ys is taken care of in the propagator:
72 // The ys are propagated to be disjoint, so shared variables
73 // result in failure.
74 int xssize = xs.size();
75 for (int i=ys.size(); i--;) {
76 GECODE_ME_CHECK(ys[i].exclude(home, xssize, Limits::max));
77 GECODE_ME_CHECK(ys[i].exclude(home, Limits::min, -1));
78 }
79 int yssize = ys.size();
80 if (yssize > Gecode::Int::Limits::max)
81 return ES_FAILED;
82 for (int i=xs.size(); i--;) {
83 GECODE_ME_CHECK(xs[i].gq(home, 0));
84 GECODE_ME_CHECK(xs[i].le(home, static_cast<int>(yssize)));
85 }
86
87 (void) new (home) ChannelInt(home,xs,ys);
88 return ES_OK;
89 }
90
91 template<class View>
94 return PropCost::quadratic(PropCost::LO, xs.size()+ys.size());
95 }
96
97 template<class View>
98 void
100 xs.reschedule(home,*this, Gecode::Int::PC_INT_DOM);
101 ys.reschedule(home,*this, PC_SET_ANY);
102 }
103
104 template<class View>
105 forceinline size_t
107 xs.cancel(home,*this, Gecode::Int::PC_INT_DOM);
108 ys.cancel(home,*this, PC_SET_ANY);
109 (void) Propagator::dispose(home);
110 return sizeof(*this);
111 }
112
113 template<class View>
114 Actor*
116 return new (home) ChannelInt(home,*this);
117 }
118
119 template<class View>
122 int assigned = 0;
123 for (int v=xs.size(); v--;) {
124 if (xs[v].assigned()) {
125 assigned++;
126 if (xs[v].modified())
127 GECODE_ME_CHECK(ys[xs[v].val()].include(home,v));
128 }
129 if (xs[v].modified()) {
132 Gecode::Int::IntView> > dv(d);
133 for (; dv(); ++dv)
134 GECODE_ME_CHECK(ys[dv.val()].exclude(home, v));
135 xs[v].cache(home);
136 }
137 }
138
139 for (int i=ys.size(); i--;) {
140 if (ys[i].glbModified()) {
141 GlbDiffRanges<View> yilb(ys[i]);
143 for (;dv();++dv)
144 GECODE_ME_CHECK(xs[dv.val()].eq(home,i));
145 ys[i].cacheGlb(home);
146 }
147 if (ys[i].lubModified()) {
148 LubDiffRanges<View> yiub(ys[i]);
150 for (;dv();++dv)
151 GECODE_ME_CHECK(xs[dv.val()].nq(home,i));
152 ys[i].cacheLub(home);
153 }
154 }
155
156 return (assigned==xs.size()) ? home.ES_SUBSUMED(*this) : ES_NOFIX;
157 }
158
159}}}
160
161// STATISTICS: set-prop
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:3256
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
Integer view for integer variables.
Definition view.hpp:129
Range iterator for cached integer views
Definition view.hpp:1354
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:4794
friend class Space
Definition core.hpp:1068
Propagator(Home home)
Constructor for posting.
Definition core.hpp:3505
static ExecStatus post(Home home, ViewArray< Gecode::Int::CachedView< Gecode::Int::IntView > > &x, ViewArray< CachedView< View > > &y)
Post propagator for .
Definition int.hpp:67
virtual PropCost cost(const Space &home, const ModEventDelta &med) const
Cost function (defined as PC_QUADRATIC_LO)
Definition int.hpp:93
ChannelInt(Space &home, ChannelInt &p)
Constructor for cloning p.
Definition int.hpp:59
ViewArray< Gecode::Int::CachedView< Gecode::Int::IntView > > xs
IntViews, reflects which set contains element .
Definition channel.hh:108
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition int.hpp:121
virtual void reschedule(Space &home)
Schedule function.
Definition int.hpp:99
virtual Actor * copy(Space &home)
Copy propagator during cloning.
Definition int.hpp:115
ViewArray< CachedView< View > > ys
SetViews that are constrained to be disjoint.
Definition channel.hh:110
virtual size_t dispose(Space &home)
Delete propagator and return its size.
Definition int.hpp:106
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
View arrays.
Definition array.hpp:253
ExecStatus ES_SUBSUMED(Propagator &p)
Propagator p is subsumed
Definition core.hpp:3570
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 max
Largest allowed integer value.
Definition int.hh:116
const Gecode::PropCond PC_INT_DOM
Propagate when domain changes.
Definition var-type.hpp:100
Channeling propagators for set variables.
Definition channel.hh:43
const int min
Smallest allowed integer in integer set.
Definition set.hh:99
const int max
Largest allowed integer in integer set.
Definition set.hh:97
Finite integer sets.
Definition var-imp.hpp:137
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_FAILED
Execution has resulted in failure.
Definition core.hpp:474
@ ES_NOFIX
Propagation has not computed fixpoint.
Definition core.hpp:475
#define forceinline
Definition config.hpp:194