narrowing.icc
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 #include "gecode/support/static-stack.hh"
00023
00024 namespace Gecode { namespace Int { namespace Sortedness {
00025
00042 template<class View, class Tuple>
00043 forceinline void
00044 computesccs(Space* home,
00045 ViewArray<Tuple>& xz,
00046 ViewArray<View>& y,
00047 int phi[],
00048 SccComponent sinfo[],
00049 int scclist[]) {
00050
00051
00052 int xs = xz.size();
00053 Support::StaticStack<int> cs(xs);
00054
00055
00056 for (int j = 0; j < xs; j++) {
00057 int yjmin = y[j].min();
00058 while (!cs.empty() && xz[phi[sinfo[cs.top()].rightmost]][0].max() < yjmin) {
00059
00060 cs.pop();
00061 }
00062
00063
00064
00065
00066 int i = phi[j];
00067 int ximin = xz[i][0].min();
00068 while (!cs.empty() && ximin <= y[sinfo[cs.top()].rightmost].max()) {
00069
00070
00071
00072 int top = cs.top();
00073
00074 sinfo[sinfo[j].leftmost].left = top;
00075 sinfo[top].right = sinfo[j].leftmost;
00076
00077 sinfo[j].leftmost = sinfo[top].leftmost;
00078
00079 sinfo[sinfo[top].leftmost].rightmost = j;
00080 cs.pop();
00081 }
00082 cs.push(j);
00083 }
00084 cs.reset();
00085
00086
00087
00088
00089
00090 for (int i = 0; i < xs; i++) {
00091 if (sinfo[i].left == i) {
00092 int scc = sinfo[i].rightmost;
00093 int z = i;
00094
00095 while (sinfo[z].right != z) {
00096 sinfo[z].rightmost = scc;
00097 scclist[phi[z]] = scc;
00098 z = sinfo[z].right;
00099 }
00100 sinfo[z].rightmost = scc;
00101 scclist[phi[z]] = scc;
00102 }
00103 }
00104 }
00105
00121 template<class View, class Tuple, bool Perm>
00122 forceinline bool
00123 narrow_domx(Space* home,
00124 ViewArray<Tuple>& xz,
00125 ViewArray<View>& y,
00126 int tau[],
00127 int phi[],
00128 int scclist[],
00129 SccComponent sinfo[],
00130 bool& nofix) {
00131
00132 int xs = xz.size();
00133
00134
00135 for (int i = 0; i < xs; i++) {
00136
00137 int xmin = xz[i][0].min();
00138
00139
00140
00141
00142
00143
00144
00145 int start = sinfo[scclist[i]].leftmost;
00146 while (y[start].max() < xmin) {
00147 start = sinfo[start].right;
00148 }
00149
00150 if (Perm) {
00151
00152
00153
00154 ModEvent me_plb = xz[i][1].gq(home, start);
00155 if (me_failed(me_plb)) {
00156 return false;
00157 }
00158 nofix |= (me_modified(me_plb) && start != xz[i][1].min());
00159 }
00160
00161 ModEvent me_lb = xz[i][0].gq(home, y[start].min());
00162 if (me_failed(me_lb)) {
00163 return false;
00164 }
00165 nofix |= (me_modified(me_lb) &&
00166 y[start].min() != xz[i][0].min());
00167
00168 int ptau = tau[xs - 1 - i];
00169 int xmax = xz[ptau][0].max();
00170
00171
00172
00173
00174
00175
00176
00177 start = sinfo[scclist[ptau]].rightmost;
00178 while (y[start].min() > xmax) {
00179 start = sinfo[start].left;
00180 }
00181
00182 if (Perm) {
00183
00184
00185 ModEvent me_pub = xz[ptau][1].lq(home, start);
00186 if (me_failed(me_pub)) {
00187 return false;
00188 }
00189 nofix |= (me_modified(me_pub) && start != xz[ptau][1].max());
00190 }
00191
00192 ModEvent me_ub = xz[ptau][0].lq(home, y[start].max());
00193 if (me_failed(me_ub)) {
00194 return false;
00195 }
00196 nofix |= (me_modified(me_ub) &&
00197 y[start].max() != xz[ptau][0].max());
00198 }
00199 return true;
00200 }
00201
00212 template<class View, class Tuple, bool Perm>
00213 forceinline bool
00214 narrow_domy(Space* home,
00215 ViewArray<Tuple>& xz,
00216 ViewArray<View>& y,
00217 int phi[],
00218 int phiprime[],
00219 bool& nofix) {
00220
00221 int xs = xz.size();
00222 for (int i = xs; i--; ) {
00223 ModEvent me_lb = y[i].gq(home, xz[phiprime[i]][0].min());
00224 if (me_failed(me_lb)) {
00225 return false;
00226 }
00227 nofix |= (me_modified(me_lb) &&
00228 xz[phiprime[i]][0].min() != y[i].min());
00229
00230 ModEvent me_ub = y[i].lq(home, xz[phi[i]][0].max());
00231 if (me_failed(me_ub)) {
00232 return false;
00233 }
00234 nofix |= (me_modified(me_ub) &&
00235 xz[phi[i]][0].max() != y[i].max());
00236 }
00237 return true;
00238 }
00239
00240 }}}
00241
00242
00243