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

matching.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 Sortedness {
00023 
00041   template <class View, class Tuple, bool Perm>
00042   forceinline bool
00043   glover(Space* home,
00044          ViewArray<Tuple>& xz,
00045          ViewArray<View>& y,
00046          int tau[],
00047          int phi[],
00048          OfflineMinItem sequence[],
00049          int vertices[]) {
00050 
00051     int xs = xz.size();
00052     OfflineMin seq(sequence, vertices, xs);
00053     int s  = 0;
00054     seq.makeset();
00055 
00056     for (int z = 0; z < xs; z++) {  // forall y nodes
00057       int maxy = y[z].max();
00058       // creating the sequence of inserts and extractions from the queue
00059 //       for( ; s <xs && xz[s][0].min() <= maxy; s++) {
00060       for( ; s <xs && xz[s][0].min() <= maxy; s++) {
00061         seq[s].iset = z;
00062         seq[z].rank++;
00063       }
00064     }
00065 
00066     // offline-min-procedure
00067     for (int i = 0; i < xs; i++) {
00068       // the upper bound of the x-node should be minimal
00069       int perm = tau[i];
00070       // find the iteration where \tau(i) became a maching candidate
00071       int iter = seq[perm].iset;
00072       if (iter<0) {
00073         return false;
00074       }
00075       int j = 0;
00076       j = seq.find_pc(iter);
00077       // check whether the sequence is valid
00078       if (j >= xs) {
00079         return false;
00080       }
00081       // if there is no intersection between the matching candidate
00082       // and the y node then there exists NO perfect matching
00083       if (xz[perm][0].max() < y[j].min()) {
00084         return false;
00085       }
00086       phi[j]         = perm;
00087       seq[perm].iset = -5;           //remove from candidate set
00088       int sqjsucc    = seq[j].succ;
00089       if (sqjsucc < xs){
00090         seq.unite(j,sqjsucc,sqjsucc);
00091       } else {
00092         seq[seq[j].root].name = sqjsucc; // end of sequence achieved
00093       }
00094 
00095       // adjust tree list
00096       int pr = seq[j].pred;
00097       if (pr != -1) {
00098         seq[pr].succ = sqjsucc;
00099       }
00100       if (sqjsucc != xs) {
00101         seq[sqjsucc].pred = pr;
00102       }
00103     }
00104     return true;
00105   }
00106 
00111   template <class View, class Tuple, bool Perm>
00112   forceinline bool
00113   revglover(Space* home,
00114             ViewArray<Tuple>& xz,
00115             ViewArray<View>& y,
00116             int tau[],
00117             int phiprime[],
00118             OfflineMinItem sequence[],
00119             int vertices[]) {
00120 
00121     int xs = xz.size();
00122     OfflineMin seq(sequence, vertices, xs);
00123     int s  = xs - 1;
00124     seq.makeset();
00125 
00126     int miny = 0;
00127     for (int z = xs; z--; ) {     // forall y nodes
00128       miny = y[z].min();
00129       // creating the sequence of inserts and extractions from the queue
00130       for ( ; s > -1 && xz[tau[s]][0].max() >= miny; s--) {
00131         seq[tau[s]].iset = z;
00132         seq[z].rank++;
00133       }
00134     }
00135 
00136     // offline-min-procedure
00137     for (int i = xs; i--; ) {
00138       int perm = i;
00139       int iter = seq[perm].iset;
00140       if (iter < 0) {
00141         return false;
00142       }
00143       int j = 0;
00144       j = seq.find_pc(iter);
00145       if (j <= -1) {
00146         return false;
00147       }
00148       // if there is no intersection between the matching candidate
00149       // and the y node then there exists NO perfect matching
00150       if (xz[perm][0].min() > y[j].max()) {
00151         return false;
00152       }
00153       phiprime[j]    = perm;
00154       seq[perm].iset = -5;
00155       int sqjsucc    = seq[j].pred;
00156       if (sqjsucc >= 0) {
00157         seq.unite(j, sqjsucc, sqjsucc);
00158       } else {
00159         seq[seq[j].root].name = sqjsucc; // end of sequence achieved
00160       }
00161 
00162       // adjust tree list
00163       int pr = seq[j].succ;
00164       if (pr != xs) {
00165         seq[pr].pred = sqjsucc;
00166       }
00167       if (sqjsucc != -1) {
00168         seq[sqjsucc].succ = pr;
00169       }
00170     }
00171     return true;
00172   }
00173 
00174 }}}
00175 
00176 // STATISTICS: int-prop
00177