matching.hpp
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
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 namespace Gecode { namespace Int { namespace Sorted {
00039
00057 template<class View>
00058 inline bool
00059 glover(ViewArray<View>& x, ViewArray<View>& y,
00060 int tau[], int phi[], OfflineMinItem sequence[], int vertices[]) {
00061
00062 int xs = x.size();
00063 OfflineMin seq(sequence, vertices, xs);
00064 int s = 0;
00065 seq.makeset();
00066
00067 for (int z = 0; z < xs; z++) {
00068 int maxy = y[z].max();
00069
00070 for( ; s <xs && x[s].min() <= maxy; s++) {
00071 seq[s].iset = z;
00072 seq[z].rank++;
00073 }
00074 }
00075
00076
00077 for (int i = 0; i < xs; i++) {
00078
00079 int perm = tau[i];
00080
00081 int iter = seq[perm].iset;
00082 if (iter<0)
00083 return false;
00084 int j = 0;
00085 j = seq.find_pc(iter);
00086
00087 if (j >= xs)
00088 return false;
00089
00090
00091 if (x[perm].max() < y[j].min())
00092 return false;
00093 phi[j] = perm;
00094 seq[perm].iset = -5;
00095 int sqjsucc = seq[j].succ;
00096 if (sqjsucc < xs) {
00097 seq.unite(j,sqjsucc,sqjsucc);
00098 } else {
00099 seq[seq[j].root].name = sqjsucc;
00100 }
00101
00102
00103 int pr = seq[j].pred;
00104 if (pr != -1)
00105 seq[pr].succ = sqjsucc;
00106 if (sqjsucc != xs)
00107 seq[sqjsucc].pred = pr;
00108 }
00109 return true;
00110 }
00111
00116 template<class View>
00117 inline bool
00118 revglover(ViewArray<View>& x, ViewArray<View>& y,
00119 int tau[], int phiprime[], OfflineMinItem sequence[],
00120 int vertices[]) {
00121
00122 int xs = x.size();
00123 OfflineMin seq(sequence, vertices, xs);
00124 int s = xs - 1;
00125 seq.makeset();
00126
00127 int miny = 0;
00128 for (int z = xs; z--; ) {
00129 miny = y[z].min();
00130
00131 for ( ; s > -1 && x[tau[s]].max() >= miny; s--) {
00132 seq[tau[s]].iset = z;
00133 seq[z].rank++;
00134 }
00135 }
00136
00137
00138 for (int i = xs; i--; ) {
00139 int perm = i;
00140 int iter = seq[perm].iset;
00141 if (iter < 0)
00142 return false;
00143 int j = 0;
00144 j = seq.find_pc(iter);
00145 if (j <= -1)
00146 return false;
00147
00148
00149 if (x[perm].min() > y[j].max())
00150 return false;
00151 phiprime[j] = perm;
00152 seq[perm].iset = -5;
00153 int sqjsucc = seq[j].pred;
00154 if (sqjsucc >= 0) {
00155 seq.unite(j, sqjsucc, sqjsucc);
00156 } else {
00157 seq[seq[j].root].name = sqjsucc;
00158 }
00159
00160
00161 int pr = seq[j].succ;
00162 if (pr != xs)
00163 seq[pr].pred = sqjsucc;
00164 if (sqjsucc != -1)
00165 seq[sqjsucc].succ = pr;
00166 }
00167 return true;
00168 }
00169
00170 }}}
00171
00172
00173