narrowing.hpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 namespace Gecode { namespace Int { namespace Sorted {
00039
00056 template<class View>
00057 inline void
00058 computesccs(Space& home, ViewArray<View>& x, ViewArray<View>& y,
00059 int phi[], SccComponent sinfo[], int scclist[]) {
00060
00061
00062 int xs = x.size();
00063 Region r(home);
00064 Support::StaticStack<int,Region> cs(r,xs);
00065
00066
00067 for (int j = 0; j < xs; j++) {
00068 int yjmin = y[j].min();
00069 while (!cs.empty() && x[phi[sinfo[cs.top()].rightmost]].max() < yjmin) {
00070
00071 cs.pop();
00072 }
00073
00074
00075
00076
00077 int i = phi[j];
00078 int ximin = x[i].min();
00079 while (!cs.empty() && ximin <= y[sinfo[cs.top()].rightmost].max()) {
00080
00081
00082
00083 int top = cs.top();
00084
00085 sinfo[sinfo[j].leftmost].left = top;
00086 sinfo[top].right = sinfo[j].leftmost;
00087
00088 sinfo[j].leftmost = sinfo[top].leftmost;
00089
00090 sinfo[sinfo[top].leftmost].rightmost = j;
00091 cs.pop();
00092 }
00093 cs.push(j);
00094 }
00095 cs.reset();
00096
00097
00098
00099
00100
00101 for (int i = 0; i < xs; i++) {
00102 if (sinfo[i].left == i) {
00103 int scc = sinfo[i].rightmost;
00104 int z = i;
00105
00106 while (sinfo[z].right != z) {
00107 sinfo[z].rightmost = scc;
00108 scclist[phi[z]] = scc;
00109 z = sinfo[z].right;
00110 }
00111 sinfo[z].rightmost = scc;
00112 scclist[phi[z]] = scc;
00113 }
00114 }
00115 }
00116
00132 template<class View, bool Perm>
00133 inline bool
00134 narrow_domx(Space& home,
00135 ViewArray<View>& x,
00136 ViewArray<View>& y,
00137 ViewArray<View>& z,
00138 int tau[],
00139 int[],
00140 int scclist[],
00141 SccComponent sinfo[],
00142 bool& nofix) {
00143
00144 int xs = x.size();
00145
00146
00147 for (int i = 0; i < xs; i++) {
00148
00149 int xmin = x[i].min();
00150
00151
00152
00153
00154
00155
00156
00157 int start = sinfo[scclist[i]].leftmost;
00158 while (y[start].max() < xmin) {
00159 start = sinfo[start].right;
00160 }
00161
00162 if (Perm) {
00163
00164
00165
00166 ModEvent me_plb = z[i].gq(home, start);
00167 if (me_failed(me_plb)) {
00168 return false;
00169 }
00170 nofix |= (me_modified(me_plb) && start != z[i].min());
00171 }
00172
00173 ModEvent me_lb = x[i].gq(home, y[start].min());
00174 if (me_failed(me_lb)) {
00175 return false;
00176 }
00177 nofix |= (me_modified(me_lb) &&
00178 y[start].min() != x[i].min());
00179
00180 int ptau = tau[xs - 1 - i];
00181 int xmax = x[ptau].max();
00182
00183
00184
00185
00186
00187
00188
00189 start = sinfo[scclist[ptau]].rightmost;
00190 while (y[start].min() > xmax) {
00191 start = sinfo[start].left;
00192 }
00193
00194 if (Perm) {
00195
00196
00197 ModEvent me_pub = z[ptau].lq(home, start);
00198 if (me_failed(me_pub)) {
00199 return false;
00200 }
00201 nofix |= (me_modified(me_pub) && start != z[ptau].max());
00202 }
00203
00204 ModEvent me_ub = x[ptau].lq(home, y[start].max());
00205 if (me_failed(me_ub)) {
00206 return false;
00207 }
00208 nofix |= (me_modified(me_ub) &&
00209 y[start].max() != x[ptau].max());
00210 }
00211 return true;
00212 }
00213
00224 template<class View>
00225 inline bool
00226 narrow_domy(Space& home,
00227 ViewArray<View>& x, ViewArray<View>& y,
00228 int phi[], int phiprime[], bool& nofix) {
00229 for (int i=x.size(); i--; ) {
00230 ModEvent me_lb = y[i].gq(home, x[phiprime[i]].min());
00231 if (me_failed(me_lb)) {
00232 return false;
00233 }
00234 nofix |= (me_modified(me_lb) &&
00235 x[phiprime[i]].min() != y[i].min());
00236
00237 ModEvent me_ub = y[i].lq(home, x[phi[i]].max());
00238 if (me_failed(me_ub)) {
00239 return false;
00240 }
00241 nofix |= (me_modified(me_ub) &&
00242 x[phi[i]].max() != y[i].max());
00243 }
00244 return true;
00245 }
00246
00247 }}}
00248
00249
00250