matching.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 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++) {
00057 int maxy = y[z].max();
00058
00059
00060 for( ; s <xs && xz[s][0].min() <= maxy; s++) {
00061 seq[s].iset = z;
00062 seq[z].rank++;
00063 }
00064 }
00065
00066
00067 for (int i = 0; i < xs; i++) {
00068
00069 int perm = tau[i];
00070
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
00078 if (j >= xs) {
00079 return false;
00080 }
00081
00082
00083 if (xz[perm][0].max() < y[j].min()) {
00084 return false;
00085 }
00086 phi[j] = perm;
00087 seq[perm].iset = -5;
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;
00093 }
00094
00095
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--; ) {
00128 miny = y[z].min();
00129
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
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
00149
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;
00160 }
00161
00162
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
00177