Generated on for Gecode by doxygen 1.15.0
pair.cpp
Go to the documentation of this file.
1/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2/*
3 * Main authors:
4 * Christian Schulte <schulte@gecode.dev>
5 *
6 * Copyright:
7 * Christian Schulte, 2009
8 *
9 * This file is part of Gecode, the generic constraint
10 * development environment:
11 * http://www.gecode.dev
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#include <gecode/int/element.hh>
35
36namespace Gecode { namespace Int { namespace Element {
37
38 Actor*
40 return new (home) Pair(home,*this);
41 }
42
44 template<class View>
45 class PairValues {
46 private:
48 View x;
54 int w;
55 public:
57
58
59 PairValues(View x, View y, int w);
61
63
64
65 bool operator ()(void) const;
67 void operator ++(void);
69
71
72
73 int val(void) const;
75 };
76
77 template<class View>
80 : x(x0), xv(x0), yv(y0), w(w0) {}
81 template<class View>
82 forceinline void
84 ++xv;
85 if (!xv()) {
86 xv.init(x); ++yv;
87 }
88 }
89 template<class View>
90 forceinline bool
92 return yv();
93 }
94 template<class View>
95 forceinline int
97 return xv.val() + w*yv.val();
98 }
99
100
103 Region r;
104
105 if (x0.assigned()) {
106 // Bitset for supported div and mod values
107 Support::BitSet<Region> d(r,static_cast<unsigned int>((x2.max() / w)+1));
108 for (ViewValues<IntView> i(x2); i(); ++i) {
109 d.set(static_cast<unsigned int>(i.val() / w));
110 }
112 GECODE_ME_CHECK(x1.inter_v(home,id,false));
113 } else {
114 // Bitset for supported div and mod values
116 d(r,static_cast<unsigned int>((x2.max() / w)+1)),
117 m(r,static_cast<unsigned int>(w));
118 for (ViewValues<IntView> i(x2); i(); ++i) {
119 d.set(static_cast<unsigned int>(i.val() / w));
120 m.set(static_cast<unsigned int>(i.val() % w));
121 }
123 GECODE_ME_CHECK(x0.inter_v(home,im,false));
125 GECODE_ME_CHECK(x1.inter_v(home,id,false));
126 }
127
128 if (x0.assigned() && x1.assigned()) {
129 GECODE_ME_CHECK(x2.eq(home,x0.val()+w*x1.val()));
130 return home.ES_SUBSUMED(*this);
131 } else if (x1.assigned()) {
132 OffsetView x0x1w(x0,x1.val()*w);
134 ::post(home(*this),x0x1w,x2)));
135 }
136
138 GECODE_ME_CHECK(x2.inter_v(home,xy,false));
139
140 if (x2.assigned()) {
141 GECODE_ME_CHECK(x0.eq(home,x2.val() % w));
142 GECODE_ME_CHECK(x1.eq(home,static_cast<int>(x2.val() / w)));
143 return home.ES_SUBSUMED(*this);
144 }
145
146 return ES_NOFIX;
147 }
148
149 Actor*
151 return new (home) PairWithOffsets(home,*this);
152 }
153
156 Region r;
157
158 if (x0.assigned()) {
159 // Bitset for supported div and mod values
160 Support::BitSet<Region> d(r,static_cast<unsigned int>((x2.max() / w)+1));
161 for (ViewValues<OffsetView> i(x2); i(); ++i) {
162 d.set(static_cast<unsigned int>(i.val() / w));
163 }
165 GECODE_ME_CHECK(x1.inter_v(home,id,false));
166 } else {
167 // Bitset for supported div and mod values
169 d(r,static_cast<unsigned int>((x2.max() / w)+1)),
170 m(r,static_cast<unsigned int>(w));
171 for (ViewValues<OffsetView> i(x2); i(); ++i) {
172 d.set(static_cast<unsigned int>(i.val() / w));
173 m.set(static_cast<unsigned int>(i.val() % w));
174 }
176 GECODE_ME_CHECK(x0.inter_v(home,im,false));
178 GECODE_ME_CHECK(x1.inter_v(home,id,false));
179 }
180
181 if (x0.assigned() && x1.assigned()) {
182 GECODE_ME_CHECK(x2.eq(home,x0.val()+w*x1.val()));
183 return home.ES_SUBSUMED(*this);
184 } else if (x1.assigned()) {
185 OffsetView x0x1w(x0.base(),x0.offset()+x1.val()*w);
187 ::post(home(*this),x0x1w,x2)));
188 }
189
191 GECODE_ME_CHECK(x2.inter_v(home,xy,false));
192
193 if (x2.assigned()) {
194 GECODE_ME_CHECK(x0.eq(home,x2.val() % w));
195 GECODE_ME_CHECK(x1.eq(home,static_cast<int>(x2.val() / w)));
196 return home.ES_SUBSUMED(*this);
197 }
198
199 return ES_NOFIX;
200 }
201
202}}}
203
204// STATISTICS: int-prop
205
Base-class for both propagators and branchers.
Definition core.hpp:635
Value iterator for pair of iterators.
Definition pair.cpp:45
PairValues(View x, View y, int w)
Initialize with views x and y and width w.
Definition pair.cpp:79
int val(void) const
Return current value.
Definition pair.cpp:96
void operator++(void)
Move iterator to next value (if possible).
Definition pair.cpp:83
bool operator()(void) const
Test whether iterator is still at a value or done.
Definition pair.cpp:91
virtual Actor * copy(Space &home)
Copy propagator during cloning.
Definition pair.cpp:150
static ExecStatus post(Home home, OffsetView x0, OffsetView x1, IntView x2, int w, int h)
Post propagator .
Definition pair.hpp:74
PairWithOffsets(Space &home, PairWithOffsets &p)
Constructor for cloning p.
Definition pair.hpp:95
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition pair.cpp:155
Pair(Space &home, Pair &p)
Constructor for cloning p.
Definition pair.hpp:64
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition pair.cpp:102
static ExecStatus post(Home home, IntView x0, IntView x1, IntView x2, int w, int h)
Post propagator .
Definition pair.hpp:43
virtual Actor * copy(Space &home)
Copy propagator during cloning.
Definition pair.cpp:39
Base-class for element propagator for array of views.
Definition element.hh:203
Offset integer view.
Definition view.hpp:443
Binary domain consistent equality propagator.
Definition rel.hh:68
Value iterator for integer views.
Definition view.hpp:94
Value iterator for values in a bitset.
friend class Space
Definition core.hpp:1075
unsigned int id(void) const
Return propagator id.
Definition core.hpp:3651
Handle to region.
Definition region.hpp:55
void set(unsigned int i)
Set bit i.
Simple bitsets.
Definition bitset.hpp:45
ExecStatus ES_SUBSUMED(Propagator &p)
Propagator p is subsumed
Definition core.hpp:3672
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
#define GECODE_REWRITE(prop, post)
Rewrite propagator by executing post function.
Definition macros.hpp:116
Element propagators
Finite domain integers.
Definition lastval.hh:52
Gecode toplevel namespace
ExecStatus
Definition core.hpp:479
@ ES_NOFIX
Propagation has not computed fixpoint.
Definition core.hpp:482
#define forceinline
Definition config.hpp:141