Generated on Wed Nov 1 15:04:34 2006 for Gecode by doxygen 1.4.5

lbc.icc

Go to the documentation of this file.
00001 /*
00002  *  Main authors:
00003  *     Patrick Pekczynski <pekczynski@ps.uni-sb.de>
00004  *
00005  *  Copyright:
00006  *     Patrick Pekczynski, 2004
00007  *
00008  *  Last modified:
00009  *     $Date: 2006-08-04 16:03:26 +0200 (Fri, 04 Aug 2006) $ by $Author: schulte $
00010  *     $Revision: 3512 $
00011  *
00012  *  This file is part of Gecode, the generic constraint
00013  *  development environment:
00014  *     http://www.gecode.org
00015  *
00016  *  See the file "LICENSE" for information on usage and
00017  *  redistribution of this file, and for a
00018  *     DISCLAIMER OF ALL WARRANTIES.
00019  *
00020  */
00021 
00022 namespace Gecode { namespace Int { namespace GCC {
00023 
00045   template <class View, class Card, bool shared>
00046   inline ExecStatus
00047   lbc(Space* home, ViewArray<View>& x, int& nb,
00048       HallInfo hall[], Rank rank[],
00049       PartialSum<Card>* lps,
00050       int mu[], int nu[]){
00051 
00052     ExecStatus es = ES_FIX;
00053     int n = x.size();
00054 
00055     /*
00056      *  Let I(S) denote the number of variables whose domain intersects
00057      *  the set S and C(S) the number of variables whose domain is containded
00058      *  in S. Let further  min_cap(S) be the minimal number of variables
00059      *  that must be assigned to values, that is
00060      *  min_cap(S) is the sum over all l[i] for a value v_i that is an
00061      *  element of S.
00062      *
00063      *  A failure set is a set F if
00064      *       I(F) < min_cap(F)
00065      *  An unstable set is a set U if
00066      *       I(U) = min_cap(U)
00067      *  A stable set is a set S if
00068      *      C(S) > min_cap(S) and S intersetcs nor
00069      *      any failure set nor any unstable set
00070      *      forall unstable and failure sets
00071      *
00072      *  failure sets determine the satisfiability of the LBC
00073      *  unstable sets have to be pruned
00074      *  stable set do not have to be pruned
00075      *
00076      * hall[].ps ~ stores the unstable
00077      *             sets that have to be pruned
00078      * hall[].s  ~ stores sets that must not be pruned
00079      * hall[].h  ~ contains stable and unstable sets
00080      * hall[].d  ~ contains the difference between interval bounds, i.e.
00081      *             the minimal capacity of the interval
00082      * hall[].t  ~ contains the critical capacity pointer, pointing to the
00083      *             values
00084      */
00085 
00086     // LBC lower bounds
00087 
00088     int i = 0;
00089     int j = 0;
00090     int w = 0;
00091     int z = 0;
00092     int v = 0;
00093 
00094     //initialization of the tree structure
00095     int rightmost = nb + 1; // rightmost accesible value in bounds
00096     int bsize     = nb + 2;
00097     w = rightmost;
00098 
00099     // test
00100     // unused but uninitialized
00101     hall[0].d = 0;
00102     hall[0].s = 0;
00103     hall[0].ps = 0;
00104 
00105     for (i = bsize; --i; ) { // i must not be zero
00106       int pred   = i - 1;
00107       hall[i].s  = pred;
00108       hall[i].ps = pred;
00109       hall[i].d  = lps->sumup(hall[pred].bounds, hall[i].bounds - 1);
00110 
00111       /* Let [hall[i].bounds,hall[i-1].bounds]=:I
00112        * If the capacity is zero => min_cap(I) = 0
00113        * => I cannot be a failure set
00114        * => I is an unstable set
00115        */
00116       if (hall[i].d == 0) {
00117         hall[pred].h = w;
00118       } else {
00119         hall[w].h = pred;
00120         w         = pred;
00121       }
00122     }
00123 
00124     w = rightmost;
00125     for (i = bsize; i--; ) { // i can be zero
00126       hall[i].t = i - 1;
00127       if (hall[i].d == 0) {
00128         hall[i].t = w;
00129       } else {
00130         hall[w].t = i;
00131         w = i;
00132       }
00133     }
00134 
00135     /*
00136      * The algorithm assigns to each value v in bounds
00137      * empty buckets corresponding to the minimal capacity l[i] to be
00138      * filled for v. (the buckets correspond to hall[].d containing the
00139      * difference between the interval bounds) Processing it
00140      * searches for the smallest value v in dom(x_i) that has an
00141      * empty bucket, i.e. if all buckets are filled it is guaranteed
00142      * that there are at least l[i] variables that will be
00143      * instantiated to v. Since the buckets are initially empty,
00144      * they are considered as FAILURE SETS
00145      */
00146 
00147     for (i = 0; i < n; i++) {
00148       // visit intervals in increasing max order
00149       int x0   = rank[mu[i]].min;
00150       int y    = rank[mu[i]].max;
00151       int succ = x0 + 1;
00152       z        = pathmax_t(hall, succ);
00153       j        = hall[z].t;
00154 
00155       /*
00156        * POTENTIALLY STABLE SET:
00157        *  z \neq succ \Leftrigharrow z>succ, i.e.
00158        *  min(D_{\mu(i)}) is guaranteed to occur min(K_i) times
00159        *  \Rightarrow [x0, min(y,z)] is potentially stable
00160        */
00161 
00162       if (z != succ) {
00163         w = pathmax_ps(hall, succ);
00164         v = hall[w].ps;
00165         pathset_ps(hall, succ, w, w);
00166         w = std::min(y, z);
00167         pathset_ps(hall, hall[w].ps, v, w);
00168         hall[w].ps = v;
00169       }
00170 
00171       /*
00172        * STABLE SET:
00173        *   being stable implies being potentially stable, i.e.
00174        *   [hall[y].ps, hall[y].bounds-1] is the largest stable subset of
00175        *   [hall[j].bounds, hall[y].bounds-1].
00176        */
00177 
00178       if (hall[z].d <= lps->sumup(hall[y].bounds, hall[z].bounds - 1)) {
00179         w = pathmax_s(hall, hall[y].ps);
00180         pathset_s(hall, hall[y].ps, w, w);
00181         // Path compression
00182         v = hall[w].s;
00183         pathset_s(hall, hall[y].s, v, y);
00184         hall[y].s = v;
00185       } else {
00186         /*
00187          * FAILURE SET:
00188          * If the considered interval [x0,y] is neither POTENTIALLY STABLE
00189          * nor STABLE there are still buckets that can be filled,
00190          * therefore d can be decreased. If d equals zero the intervals
00191          * minimum capacity is met and thepath can be compressed to the
00192          * next value having an empty bucket.
00193          * see DOMINATION in "gcc/ubc.icc"
00194          */
00195         if (--hall[z].d == 0) {
00196           hall[z].t = z + 1;
00197           z         = pathmax_t(hall, hall[z].t);
00198           hall[z].t = j;
00199         }
00200 
00201         /*
00202          * FINDING NEW LOWER BOUND:
00203          * If the lower bound belongs to an unstable or a stable set,
00204          * remind the new value we might assigned to the lower bound
00205          * in case the variable doesn't belong to a stable set.
00206          */
00207         if (hall[x0].h > x0) {
00208           hall[i].newBound = pathmax_h(hall, x0);
00209           w                = hall[i].newBound;
00210           pathset_h(hall, x0, w, w); // path compression
00211         } else {
00212           // Do not shrink the variable: take old min as new min
00213           hall[i].newBound = x0;
00214         }
00215 
00216         /* UNSTABLE SET
00217          * If an unstable set is discovered
00218          * the difference between the interval bounds is equal to the
00219          * number of variables whose domain intersect the interval
00220          * (see ZEROTEST in "gcc/ubc.icc")
00221          */
00222         // CLEARLY THIS WAS NOT STABLE == UNSTABLE
00223         if (hall[z].d == lps->sumup(hall[y].bounds, hall[z].bounds - 1)) {
00224           if (hall[y].h > y)
00225             /*
00226              * y is not the end of the potentially stable set
00227              * thus ensure that the potentially stable superset is marked
00228              */
00229             y = hall[y].h;
00230           // Equivalent to pathmax since the path is fully compressed
00231           int predj = j - 1;
00232           pathset_h(hall, hall[y].h, predj, y);
00233           // mark the new unstable set [j,y]
00234           hall[y].h = predj;
00235         }
00236       }
00237       pathset_t(hall, succ, z, z); // path compression
00238     }
00239 
00240     /* If there is a FAILURE SET left the minimum occurences of the values
00241      * are not guaranteed. In order to satisfy the LBC the last value
00242      * in the stable and unstable datastructure hall[].h must point to
00243      * the sentinel at the beginning of bounds.
00244      */
00245     if (hall[nb].h != 0) {
00246       return ES_FAILED; // no solution
00247     }
00248 
00249     // Perform path compression over all elements in
00250     // the stable interval data structure. This data
00251     // structure will no longer be modified and will be
00252     // accessed n or 2n times. Therefore, we can afford
00253     // a linear time compression.
00254     for (i = bsize; --i;) {
00255       if (hall[i].s > i) {
00256         hall[i].s = w;
00257       } else {
00258         w = i;
00259       }
00260     }
00261 
00262     /*
00263      * UPDATING LOWER BOUND:
00264      * For all variables that are not a subset of a stable set,
00265      * shrink the lower bound, i.e. forall stable sets S we have:
00266      * x0 < S_min <= y <=S_max  or S_min <= x0 <= S_max < y
00267      * that is [x0,y] is NOT a proper subset of any stable set S
00268      */
00269     for (i = n; i--; ) {
00270       int x0 = rank[mu[i]].min;
00271       int y  = rank[mu[i]].max;
00272       // update only those variables that are not contained in a stable set
00273       if ((hall[x0].s <= x0) || (y > hall[x0].s)) {
00274         //still have to check this out, how skipping works (consider dominated indices)
00275         int m = lps->skipNonNullElementsRight(hall[hall[i].newBound].bounds);
00276         ModEvent me = x[mu[i]].gq(home, m);
00277         GECODE_ME_CHECK(me);
00278         if (me_modified(me) && m != x[mu[i]].min()) {
00279           es = ES_NOFIX;
00280         }
00281         if (shared && me_modified(me)) {
00282           es = ES_NOFIX;
00283         }
00284       }
00285     }
00286 
00287     //LBC narrow upper bounds
00288 
00289     w = 0;
00290     for (i = 0; i <= nb; i++) {
00291       hall[i].d = lps->sumup(hall[i].bounds, hall[i + 1].bounds - 1);
00292       if (hall[i].d == 0) {
00293         hall[i].t = w;
00294       } else {
00295         hall[w].t = i;
00296         w         = i;
00297       }
00298     }
00299     hall[w].t = i;
00300 
00301     w         = 0;
00302     for (i = 1; i <= nb; i++) {
00303       if (hall[i - 1].d == 0) {
00304         hall[i].h = w;
00305       } else {
00306          hall[w].h = i;
00307          w         = i;
00308       }
00309     }
00310     hall[w].h = i;
00311 
00312     for (i = n; i--; ) {
00313       // visit intervals in decreasing min order
00314       // i.e. minsorted from right to left
00315       int x0   = rank[nu[i]].max;
00316       int y    = rank[nu[i]].min;
00317       int pred = x0 - 1; // predecessor of x0 in the indices
00318       z        = pathmin_t(hall, pred);
00319       j        = hall[z].t;
00320 
00321       /* If the variable is not in a discovered stable set
00322        * (see above condition for STABLE SET)
00323        */
00324       if (hall[z].d > lps->sumup(hall[z].bounds, hall[y].bounds - 1)) {
00325         //FAILURE SET
00326         if (--hall[z].d == 0) {
00327           hall[z].t = z - 1;
00328           z         = pathmin_t(hall, hall[z].t);
00329           hall[z].t = j;
00330         }
00331         //FINDING NEW UPPER BOUND
00332         if (hall[x0].h < x0) {
00333           w                = pathmin_h(hall, hall[x0].h);
00334           hall[i].newBound = w;
00335           pathset_h(hall, x0, w, w); // path compression
00336         } else {
00337           hall[i].newBound = x0;
00338         }
00339         //UNSTABLE SET
00340         if (hall[z].d == lps->sumup(hall[z].bounds, hall[y].bounds - 1)) {
00341           if (hall[y].h < y) {
00342             y = hall[y].h;
00343           }
00344           int succj = j + 1;
00345           //mark new unstable set [y,j]
00346           pathset_h(hall, hall[y].h, succj, y);
00347           hall[y].h = succj;
00348         }
00349       }
00350       pathset_t(hall, pred, z, z);
00351     }
00352 
00353     // UPDATING UPPER BOUND
00354     for (i = n; i--; ) {
00355       int x0 =  rank[nu[i]].min;
00356       int y  =  rank[nu[i]].max;
00357       if ((hall[x0].s <= x0) || (y > hall[x0].s)){
00358         int m = lps->skipNonNullElementsLeft(hall[hall[i].newBound].bounds - 1);
00359         ModEvent me = x[nu[i]].lq(home, m);
00360         GECODE_ME_CHECK(me);
00361         if (me_modified(me) && m != x[nu[i]].max()) {
00362           es = ES_NOFIX;
00363         }
00364         if (shared && me_modified(me)) {
00365           es = ES_NOFIX;
00366         }
00367       }
00368     }
00369     return es;
00370   }
00371 
00372 }}}
00373 
00374 // STATISTICS: int-prop
00375