ubc.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 namespace Gecode { namespace Int { namespace GCC {
00022
00044 template <class View, class Card, bool shared>
00045 inline ExecStatus
00046 ubc(Space* home, ViewArray<View>& x, int& nb,
00047 HallInfo hall[], Rank rank[],
00048 PartialSum<Card>* ups,
00049 int mu[], int nu[]){
00050 ExecStatus es = ES_FIX;
00051
00052 int rightmost = nb + 1;
00053 int bsize = nb + 2;
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064 hall[0].h = 0;
00065 hall[0].t = 0;
00066 hall[0].d = 0;
00067
00068 for (int i = 1; i < bsize; i++) {
00069 int pred = i - 1;
00070 hall[i].h = pred;
00071 hall[i].t = pred;
00072 hall[i].d = ups->sumup(hall[pred].bounds, hall[i].bounds - 1);
00073 }
00074
00075 int n = x.size();
00076
00077 for (int i = 0; i < n; i++) {
00078
00079
00080 int x0 = rank[mu[i]].min;
00081 int succ = x0 + 1;
00082 int y = rank[mu[i]].max;
00083 int z = pathmax_t(hall, succ);
00084 int j = hall[z].t;
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101 if (--hall[z].d == 0){
00102 hall[z].t = z + 1;
00103 z = pathmax_t(hall, hall[z].t);
00104 if (z >= bsize) {
00105 z--;
00106 }
00107 hall[z].t = j;
00108 }
00109 pathset_t(hall, succ, z, z);
00110
00111
00112
00113
00114
00115
00116
00117
00118 if (hall[z].d < ups->sumup(hall[y].bounds, hall[z].bounds - 1)){
00119 return ES_FAILED;
00120 }
00121
00122
00123
00124
00125
00126
00127 if (hall[x0].h > x0) {
00128 int w = pathmax_h(hall, hall[x0].h);
00129 int m = hall[w].bounds;
00130
00131 ModEvent me = x[mu[i]].gq(home, m);
00132 if (me_failed(me)) {
00133 return ES_FAILED;
00134 }
00135 if (me_modified(me) && (m != x[mu[i]].min())) {
00136 es = ES_NOFIX;
00137 }
00138 if (shared && me_modified(me)) {
00139 es = ES_NOFIX;
00140 }
00141 pathset_h(hall, x0, w, w);
00142 }
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160 if (hall[z].d == ups->sumup(hall[y].bounds, hall[z].bounds - 1)) {
00161
00162
00163
00164
00165 int predj = j - 1;
00166 pathset_h(hall, hall[y].h, predj, y);
00167 hall[y].h = predj;
00168 }
00169 }
00170
00171
00172
00173
00174 for (int i = 0; i < rightmost; i++) {
00175 int succ = i + 1;
00176 hall[i].h = succ;
00177 hall[i].t = succ;
00178 hall[i].d = ups->sumup(hall[i].bounds, hall[succ].bounds - 1);
00179 }
00180
00181 for (int i = n; i--; ) {
00182
00183 int x0 = rank[nu[i]].max;
00184 int pred = x0 - 1;
00185 int y = rank[nu[i]].min;
00186 int z = pathmin_t(hall, pred);
00187 int j = hall[z].t;
00188
00189
00190 if (--hall[z].d == 0){
00191 hall[z].t = z - 1;
00192 z = pathmin_t(hall, hall[z].t);
00193 hall[z].t = j;
00194 }
00195 pathset_t(hall, pred, z, z);
00196
00197
00198 if (hall[z].d < ups->sumup(hall[z].bounds,hall[y].bounds-1)){
00199 return ES_FAILED;
00200 }
00201
00202
00203
00204
00205
00206
00207 if (hall[x0].h < x0) {
00208 int w = pathmin_h(hall, hall[x0].h);
00209 int m = hall[w].bounds - 1;
00210 ModEvent me = x[nu[i]].lq(home, m);
00211 if (me_failed(me)) {
00212 return ES_FAILED;
00213 }
00214 if (me_modified(me) && (m != x[nu[i]].max())) {
00215 es = ES_NOFIX;
00216 }
00217 if (me_modified(me) && shared) {
00218 es = ES_NOFIX;
00219 }
00220 pathset_h(hall, x0, w, w);
00221 }
00222
00223 if (hall[z].d == ups->sumup(hall[z].bounds, hall[y].bounds - 1)) {
00224
00225 int succj = j + 1;
00226 pathset_h(hall, hall[y].h, succj, y);
00227 hall[y].h = succj;
00228 }
00229 }
00230 return es;
00231 }
00232
00233 }}}
00234
00235
00236