Generated on for Gecode by doxygen 1.17.0
narrowing.hpp
Go to the documentation of this file.
1/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2/*
3 * Main authors:
4 * Patrick Pekczynski <pekczynski@ps.uni-sb.de>
5 *
6 * Copyright:
7 * Patrick Pekczynski, 2004
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
34namespace Gecode { namespace Int { namespace Sorted {
35
51
52 template<class View>
53 inline void
55 int phi[], SccComponent sinfo[], int scclist[]) {
56
57 // number of sccs is bounded by xs (number of x-nodes)
58 int xs = x.size();
59 Region r;
61
62 //select an y node from the graph
63 for (int j = 0; j < xs; j++) {
64 int yjmin = y[j].min(); // the processed min
65 while (!cs.empty() && x[phi[sinfo[cs.top()].rightmost]].max() < yjmin) {
66 // the topmost scc cannot "reach" y_j or a node to the right of it
67 cs.pop();
68 }
69
70 // a component has the form C(y-Node, matching x-Node)
71 // C is a minimal scc in the oriented intersection graph
72 // we only store y_j-Node, since \phi(j) gives the matching X-node
73 int i = phi[j];
74 int ximin = x[i].min();
75 while (!cs.empty() && ximin <= y[sinfo[cs.top()].rightmost].max()) {
76 // y_j can "reach" cs.top() ,
77 // i.e. component c can reach component cs.top()
78 // merge c and cs.top() into new component
79 int top = cs.top();
80 // connecting
81 sinfo[sinfo[j].leftmost].left = top;
82 sinfo[top].right = sinfo[j].leftmost;
83 // moving leftmost
84 sinfo[j].leftmost = sinfo[top].leftmost;
85 // moving rightmost
86 sinfo[sinfo[top].leftmost].rightmost = j;
87 cs.pop();
88 }
89 cs.push(j);
90 }
91 cs.reset();
92
93
94 // now we mark all components with the respective scc-number
95 // labeling is bound by O(k) which is bound by O(n)
96
97 for (int i = 0; i < xs; i++) {
98 if (sinfo[i].left == i) { // only label variables in sccs
99 int scc = sinfo[i].rightmost;
100 int z = i;
101 //bound by the size of the largest scc = k
102 while (sinfo[z].right != z) {
103 sinfo[z].rightmost = scc;
104 scclist[phi[z]] = scc;
105 z = sinfo[z].right;
106 }
107 sinfo[z].rightmost = scc;
108 scclist[phi[z]] = scc;
109 }
110 }
111 }
112
127
128 template<class View, bool Perm>
129 inline bool
134 int tau[],
135 int[],
136 int scclist[],
137 SccComponent sinfo[],
138 bool& nofix) {
139
140 int xs = x.size();
141
142 // For every x node
143 for (int i = 0; i < xs; i++) {
144
145 int xmin = x[i].min();
146 /*
147 * take the scc-list for the current x node
148 * start from the leftmost reachable y node of the scc
149 * and check which Y node in the scc is
150 * really the rightmost node intersecting x, i.e.
151 * search for the greatest lower bound of x
152 */
153 int start = sinfo[scclist[i]].leftmost;
154 while (y[start].max() < xmin) {
155 int next = sinfo[start].right;
156 if (next == start)
157 return false;
158 start = next;
159 }
160
161 if (Perm) {
162 // start is the leftmost-position for x_i
163 // that denotes the lower bound on p_i
164
165 ModEvent me_plb = z[i].gq(home, start);
166 if (me_failed(me_plb)) {
167 return false;
168 }
169 nofix |= (me_modified(me_plb) && start != z[i].min());
170 }
171
172 ModEvent me_lb = x[i].gq(home, y[start].min());
173 if (me_failed(me_lb)) {
174 return false;
175 }
176 nofix |= (me_modified(me_lb) &&
177 y[start].min() != x[i].min());
178
179 int ptau = tau[xs - 1 - i];
180 int xmax = x[ptau].max();
181 /*
182 * take the scc-list for the current x node
183 * start from the rightmost reachable node and check which
184 * y node in the scc is
185 * really the rightmost node intersecting x, i.e.
186 * search for the smallest upper bound of x
187 */
188 start = sinfo[scclist[ptau]].rightmost;
189 while (y[start].min() > xmax) {
190 int next = sinfo[start].left;
191 if (next == start)
192 return false;
193 start = next;
194 }
195
196 if (Perm) {
197 //start is the rightmost-position for x_i
198 //that denotes the upper bound on p_i
199 ModEvent me_pub = z[ptau].lq(home, start);
200 if (me_failed(me_pub)) {
201 return false;
202 }
203 nofix |= (me_modified(me_pub) && start != z[ptau].max());
204 }
205
206 ModEvent me_ub = x[ptau].lq(home, y[start].max());
207 if (me_failed(me_ub)) {
208 return false;
209 }
210 nofix |= (me_modified(me_ub) &&
211 y[start].max() != x[ptau].max());
212 }
213 return true;
214 }
215
225
226 template<class View>
227 inline bool
230 int phi[], int phiprime[], bool& nofix) {
231 for (int i=x.size(); i--; ) {
232 ModEvent me_lb = y[i].gq(home, x[phiprime[i]].min());
233 if (me_failed(me_lb)) {
234 return false;
235 }
236 nofix |= (me_modified(me_lb) &&
237 x[phiprime[i]].min() != y[i].min());
238
239 ModEvent me_ub = y[i].lq(home, x[phi[i]].max());
240 if (me_failed(me_ub)) {
241 return false;
242 }
243 nofix |= (me_modified(me_ub) &&
244 x[phi[i]].max() != y[i].max());
245 }
246 return true;
247 }
248
249}}}
250
251// STATISTICS: int-prop
252
Representation of a strongly connected component.
Definition sortsup.hpp:53
int leftmost
Leftmost y-node in a scc.
Definition sortsup.hpp:56
int left
Direct left neighbour of an y-node in a scc.
Definition sortsup.hpp:58
int right
Direct right neighbour of an y-node in a scc.
Definition sortsup.hpp:60
int rightmost
Rightmost reachable y-node in a scc.
Definition sortsup.hpp:62
Handle to region.
Definition region.hpp:55
Computation spaces.
Definition core.hpp:1775
Stack with fixed number of elements.
void push(const T &x)
Push element x on top of stack.
void reset(void)
Reset stack (pop all elements).
T pop(void)
Pop topmost element from stack and return it.
bool empty(void) const
Test whether stack is empty.
T & top(void) const
Return element on top of stack.
View arrays.
Definition array.hpp:255
int size(void) const
Return size of array (number of elements).
Definition array.hpp:1156
bool me_failed(ModEvent me)
Check whether modification event me is failed.
Definition modevent.hpp:54
bool me_modified(ModEvent me)
Check whether modification event me describes variable modification.
Definition modevent.hpp:59
Sorted propagators
bool narrow_domy(Space &home, ViewArray< View > &x, ViewArray< View > &y, int phi[], int phiprime[], bool &nofix)
Narrowing the domains of the y views.
bool narrow_domx(Space &home, ViewArray< View > &x, ViewArray< View > &y, ViewArray< View > &z, int tau[], int[], int scclist[], SccComponent sinfo[], bool &nofix)
Narrowing the domains of the x variables.
void computesccs(ViewArray< View > &x, ViewArray< View > &y, int phi[], SccComponent sinfo[], int scclist[])
Compute the sccs of the oriented intersection-graph.
Definition narrowing.hpp:54
Finite domain integers.
Definition lastval.hh:52
Gecode toplevel namespace
void min(Home home, FloatVar x0, FloatVar x1, FloatVar x2)
Post propagator for .
void max(Home home, FloatVar x0, FloatVar x1, FloatVar x2)
Post propagator for .
int ModEvent
Type for modification events.
Definition core.hpp:67