order.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 #include "gecode/support/sort.hh"
00023
00024 namespace Gecode { namespace Int { namespace Sortedness {
00025
00033 template <class View, class Tuple, bool Perm>
00034 forceinline void
00035 sort_sigma(ViewArray<Tuple>& xz, bool fixed) {
00036 int xs = xz.size();
00037
00038
00039
00040 if (Perm) {
00041 bool eqbnd = true;
00042 for (int i = xs - 1; i--; ) {
00043 eqbnd &= ( (xz[i][0].min() == xz[i + 1][0].min()) &&
00044 (xz[i][0].max() == xz[i + 1][0].max()));
00045 }
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058 TupleMinIncExt<Tuple> min_inc;
00059 Support::quicksort<Tuple, TupleMinIncExt<Tuple> >(&xz[0], xs, min_inc);
00060
00061 } else {
00062 TupleMinInc<Tuple> min_inc;
00063 Support::quicksort<Tuple, TupleMinInc<Tuple> >(&xz[0], xs, min_inc);
00064 }
00065 }
00066
00075 template <class View, class Tuple, bool Perm>
00076 forceinline void
00077 sort_tau(ViewArray<Tuple>& xz, int tau[]) {
00078 int xs = xz.size();
00079
00080 if (Perm) {
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095 TupleMaxIncExt<Tuple> ltmax(xz);
00096 Support::quicksort(&(*tau), xs, ltmax);
00097
00098 } else {
00099 TupleMaxInc<Tuple> ltmax(xz);
00100 Support::quicksort(&(*tau), xs, ltmax);
00101 }
00102 }
00103
00111 template <class View, class Tuple>
00112 forceinline bool
00113 normalize(Space* home,
00114 ViewArray<View>& y,
00115 ViewArray<Tuple>& xz,
00116 bool& nofix) {
00117
00118 int ys = y.size();
00119 for (int i = 1; i < ys; i++) {
00120 ModEvent me_lb = y[i].gq(home, y[i - 1].min());
00121 if (me_failed(me_lb)) {
00122 return false;
00123 }
00124 nofix |= (me_modified(me_lb) && y[i - 1].min() != y[i].min());
00125 }
00126
00127 for (int i = ys - 1; i--; ) {
00128 ModEvent me_ub = y[i].lq(home, y[i + 1].max());
00129 if (me_failed(me_ub)) {
00130 return false;
00131 }
00132 nofix |= (me_modified(me_ub) && y[i + 1].max() != y[i].max());
00133 }
00134
00135 int xs = xz.size();
00136 for (int i = xs; i--; ) {
00137 ModEvent me = xz[i][0].gq(home, y[0].min());
00138 if (me_failed(me)) {
00139 return false;
00140 }
00141 nofix |= (me_modified(me) && xz[i][0].min() != y[0].min());
00142
00143 me = xz[i][0].lq(home, y[xs - 1].max());
00144 if (me_failed(me)) {
00145 return false;
00146 }
00147 nofix |= (me_modified(me) && xz[i][0].max() != y[xs - 1].max());
00148 }
00149 return true;
00150 }
00151
00162 template<class View, class Tuple, bool Perm>
00163 forceinline bool
00164 perm_bc(Space* home, int tau[],
00165 SccComponent sinfo[],
00166 int scclist[],
00167 ViewArray<Tuple>& xz,
00168 bool& crossingedge,
00169 bool& nofix) {
00170
00171 int ps = xz.size();
00172
00173 for (int i = 1; i < ps; i++) {
00174
00175 if (xz[i - 1][0].min() < xz[i][0].min()) {
00176 if (xz[i - 1][1].min() > xz[i][1].min()) {
00177 if (xz[i][1].min() != sinfo[scclist[i]].leftmost) {
00178
00179 if (xz[i][1].assigned()) {
00180 if (xz[i - 1][0].max() < xz[i][0].min()) {
00181
00182
00183 return false;
00184 }
00185 } else {
00186 crossingedge = true;
00187
00188
00189 ModEvent me_z = xz[i][1].gq(home, xz[i - 1][1].min());
00190 if (me_failed(me_z)) {
00191 return false;
00192 }
00193 nofix |= ( me_modified(me_z) &&
00194 xz[i - 1][1].min() != xz[i][1].min());
00195 }
00196 }
00197 }
00198 }
00199 }
00200
00201
00202 for (int i = ps - 1; i--; ) {
00203 if (xz[tau[i]][0].max() < xz[tau[i + 1]][0].max()) {
00204 if (xz[tau[i]][1].max() > xz[tau[i + 1]][1].max()) {
00205 if (xz[tau[i]][1].max() != sinfo[scclist[tau[i]]].rightmost) {
00206
00207 if (xz[tau[i]][1].assigned()) {
00208 if (xz[tau[i + 1]][0].min() > xz[tau[i]][0].max()) {
00209
00210 return false;
00211 }
00212 } else {
00213 crossingedge = true;
00214 ModEvent me_z = xz[tau[i]][1].lq(home, xz[tau[i + 1]][1].max());
00215 if (me_failed(me_z)) {
00216 return false;
00217 }
00218 nofix |= (me_modified(me_z) &&
00219 xz[tau[i + 1]][1].max() != xz[tau[i]][1].max());
00220 }
00221 }
00222 }
00223 }
00224 }
00225
00226 return true;
00227 }
00228
00229 }}}
00230
00231
00232