Generated on for Gecode by doxygen 1.18.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.dev>
5 * Christian Schulte <schulte@gecode.dev>
6 * Gabor Szokoli <szokoli@gecode.dev>
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.dev
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>
43 forceinline
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));
54 ys.subscribe(home,*this, PC_SET_ANY);
55 }
56
57 template<class View>
58 forceinline
60 : Propagator(home,p) {
61 xs.update(home,p.xs);
62 ys.update(home,p.ys);
63 }
64
65 template<class View>
66 forceinline ExecStatus
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 // With a single set, the initial cache equals {0}, so modified() is false
86 if (xs[i].assigned())
87 GECODE_ME_CHECK(ys[xs[i].val()].include(home, i));
88 }
89
90 (void) new (home) ChannelInt(home,xs,ys);
91 return ES_OK;
92 }
93
94 template<class View>
97 return PropCost::quadratic(PropCost::LO, xs.size()+ys.size());
98 }
99
100 template<class View>
101 void
103 xs.reschedule(home,*this, Gecode::Int::PC_INT_DOM);
104 ys.reschedule(home,*this, PC_SET_ANY);
105 }
106
107 template<class View>
108 forceinline size_t
110 xs.cancel(home,*this, Gecode::Int::PC_INT_DOM);
111 ys.cancel(home,*this, PC_SET_ANY);
112 (void) Propagator::dispose(home);
113 return sizeof(*this);
114 }
115
116 template<class View>
117 Actor*
119 return new (home) ChannelInt(home,*this);
120 }
121
122 template<class View>
125 int assigned = 0;
126 for (int v=xs.size(); v--;) {
127 if (xs[v].assigned()) {
128 assigned++;
129 if (xs[v].modified())
130 GECODE_ME_CHECK(ys[xs[v].val()].include(home,v));
131 }
132 if (xs[v].modified()) {
135 Gecode::Int::IntView> > dv(d);
136 for (; dv(); ++dv)
137 GECODE_ME_CHECK(ys[dv.val()].exclude(home, v));
138 xs[v].cache(home);
139 }
140 }
141
142 for (int i=ys.size(); i--;) {
143 if (ys[i].glbModified()) {
144 GlbDiffRanges<View> yilb(ys[i]);
146 for (;dv();++dv)
147 GECODE_ME_CHECK(xs[dv.val()].eq(home,i));
148 ys[i].cacheGlb(home);
149 }
150 if (ys[i].lubModified()) {
151 LubDiffRanges<View> yiub(ys[i]);
153 for (;dv();++dv)
154 GECODE_ME_CHECK(xs[dv.val()].nq(home,i));
155 ys[i].cacheLub(home);
156 }
157 }
158
159 return (assigned==xs.size()) ? home.ES_SUBSUMED(*this) : ES_NOFIX;
160 }
161
162}}}
163
164// STATISTICS: set-prop
Base-class for both propagators and branchers.
Definition core.hpp:635
virtual size_t dispose(Space &home)
Delete actor and return its size.
Definition core.hpp:3430
Home class for posting propagators
Definition core.hpp:863
Integer sets.
Definition int.hh:179
static const IntSet empty
Empty set.
Definition int.hh:302
Cached integer view.
Definition view.hpp:1164
Integer view for integer variables.
Definition view.hpp:129
Range iterator for cached integer views
Definition view.hpp:1352
Value iterator from range iterator.
int val(void) const
Return current value.
Propagation cost.
Definition core.hpp:493
static PropCost quadratic(PropCost::Mod m, unsigned int n)
Quadratic complexity for modifier m and size measure n.
Definition core.hpp:5071
friend class Space
Definition core.hpp:1075
Propagator(Home home)
Constructor for posting.
Definition core.hpp:3707
Cached set view.
Definition view.hpp:948
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:96
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:124
virtual void reschedule(Space &home)
Schedule function.
Definition int.hpp:102
virtual Actor * copy(Space &home)
Copy propagator during cloning.
Definition int.hpp:118
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:109
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:255
void update(Space &home, ViewArray< View > &a)
Update array to be a clone of array a.
Definition array.hpp:1337
void subscribe(Space &home, Propagator &p, PropCond pc, bool schedule=true)
Subscribe propagator p with propagation condition pc to variable.
Definition array.hpp:1350
int size(void) const
Return size of array (number of elements).
Definition array.hpp:1165
ExecStatus ES_SUBSUMED(Propagator &p)
Propagator p is subsumed
Definition core.hpp:3780
int ModEventDelta
Modification event deltas.
Definition core.hpp:94
#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:121
const Gecode::PropCond PC_INT_DOM
Propagate when domain changes.
Definition var-type.hpp:108
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:145
const Gecode::PropCond PC_SET_ANY
Propagate when any bound or the cardinality of a view changes.
Definition var-type.hpp:256
Gecode toplevel namespace
ExecStatus
Definition core.hpp:479
@ ES_OK
Execution is okay.
Definition core.hpp:483
@ ES_FAILED
Execution has resulted in failure.
Definition core.hpp:481
@ ES_NOFIX
Propagation has not computed fixpoint.
Definition core.hpp:482