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 Rel {
00039
00040 template <class View>
00041 inline
00042 Lex<View>::Lex(Space* home,
00043 ViewArray<ViewTuple<View,2> >& xy, bool s)
00044 : NaryPropagator<ViewTuple<View,2>,PC_INT_BND>(home,xy), strict(s) {}
00045
00046 template <class View>
00047 forceinline
00048 Lex<View>::Lex(Space* home, bool share, Lex<View>& p)
00049 : NaryPropagator<ViewTuple<View,2>,PC_INT_BND>(home,share,p),
00050 strict(p.strict) {}
00051
00052 template <class View>
00053 Actor*
00054 Lex<View>::copy(Space* home, bool share) {
00055 return new (home) Lex<View>(home,share,*this);
00056 }
00057
00058 template <class View>
00059 inline Support::Symbol
00060 Lex<View>::ati(void) {
00061 return Reflection::mangle<View>("Gecode::Int::Rel::Lex");
00062 }
00063
00064 template <class View>
00065 Reflection::ActorSpec
00066 Lex<View>::spec(const Space* home, Reflection::VarMap& m) const {
00067 return NaryPropagator<ViewTuple<View,2>,PC_INT_BND>
00068 ::spec(home, m, ati()) << strict;
00069 }
00070
00071 template <class View>
00072 void
00073 Lex<View>::post(Space* home, Reflection::VarMap& vars,
00074 const Reflection::ActorSpec& spec) {
00075 spec.checkArity(2);
00076 ViewArray<ViewTuple<View,2> > x(home, vars, spec[0]);
00077 bool strict = spec[1]->toInt();
00078 (void) new (home) Lex<View>(home, x, strict);
00079 }
00080
00081 template <class View>
00082 ExecStatus
00083 Lex<View>::propagate(Space* home, ModEventDelta) {
00084
00085
00086
00087
00088 {
00089 int i = 0;
00090 int n = x.size();
00091
00092 while ((i < n) && (x[i][0].min() == x[i][1].max())) {
00093
00094 GECODE_ME_CHECK(x[i][0].lq(home,x[i][1].max()));
00095 GECODE_ME_CHECK(x[i][1].gq(home,x[i][0].min()));
00096 i++;
00097 }
00098
00099 if (i == n)
00100 return strict ? ES_FAILED : ES_SUBSUMED(this,sizeof(*this));
00101
00102
00103 GECODE_ME_CHECK(x[i][0].lq(home,x[i][1].max()));
00104 GECODE_ME_CHECK(x[i][1].gq(home,x[i][0].min()));
00105
00106 if (x[i][0].max() < x[i][1].min())
00107 return ES_SUBSUMED(this,home);
00108
00109
00110 assert(!(x[i][0].assigned() && x[i][1].assigned() &&
00111 x[i][0].val() == x[i][1].val()));
00112
00113 x.drop_fst(i);
00114
00115 }
00116
00117
00118
00119
00120
00121
00122 {
00123 int i = 1;
00124 int n = x.size();
00125
00126 while ((i < n) &&
00127 (x[i][0].min() == x[i][1].max()) &&
00128 (x[i][0].max() == x[i][1].min())) {
00129 assert(x[i][0].assigned() && x[i][1].assigned() &&
00130 (x[i][0].val() == x[i][1].val()));
00131 i++;
00132 }
00133
00134 if (i == n) {
00135 if (strict)
00136 goto rewrite_le;
00137 else
00138 goto rewrite_lq;
00139 }
00140
00141 if (x[i][0].max() < x[i][1].min())
00142 goto rewrite_lq;
00143
00144 if (x[i][0].min() > x[i][1].max())
00145 goto rewrite_le;
00146
00147 if (i > 1) {
00148
00149 x[i-1]=x[0]; x.drop_fst(i-1);
00150 }
00151 }
00152
00153 if (x[1][0].max() <= x[1][1].min()) {
00154
00155
00156
00157
00158
00159
00160 int i = 2;
00161 int n = x.size();
00162
00163 while ((i < n) && (x[i][0].max() == x[i][1].min()))
00164 i++;
00165
00166 if (i == n) {
00167 if (strict)
00168 return ES_FIX;
00169 else
00170 goto rewrite_lq;
00171 }
00172
00173 if (x[i][0].max() < x[i][1].min())
00174 goto rewrite_lq;
00175
00176 if (x[i][0].min() > x[i][1].max()) {
00177
00178 for (int j=i; j<n; j++)
00179 x[j].cancel(home,this,PC_INT_BND);
00180 x.size(i);
00181 strict = true;
00182 }
00183
00184 return ES_FIX;
00185 }
00186
00187 if (x[1][0].min() >= x[1][1].max()) {
00188
00189
00190
00191
00192
00193
00194 int i = 2;
00195 int n = x.size();
00196
00197 while ((i < n) && (x[i][0].min() == x[i][1].max()))
00198
00199 i++;
00200
00201 if (i == n) {
00202 if (strict)
00203 goto rewrite_le;
00204 else
00205 return ES_FIX;
00206 }
00207
00208 if (x[i][0].min() > x[i][1].max())
00209 goto rewrite_le;
00210
00211 if (x[i][0].max() < x[i][1].min()) {
00212
00213 for (int j=i; j<n; j++)
00214 x[j].cancel(home,this,PC_INT_BND);
00215 x.size(i);
00216 strict = false;
00217 }
00218
00219 return ES_FIX;
00220 }
00221
00222 return ES_FIX;
00223
00224 rewrite_le:
00225 GECODE_REWRITE(this,Le<View>::post(home,x[0][0],x[0][1]));
00226 rewrite_lq:
00227 GECODE_REWRITE(this,Lq<View>::post(home,x[0][0],x[0][1]));
00228 }
00229
00230 template <class View>
00231 ExecStatus
00232 Lex<View>::post(Space* home,
00233 ViewArray<ViewTuple<View,2> >& xy, bool strict){
00234 if (xy.size() == 0)
00235 return strict ? ES_FAILED : ES_OK;
00236 if (xy.size() == 1)
00237 if (strict)
00238 return Le<View>::post(home,xy[0][0],xy[0][1]);
00239 else
00240 return Lq<View>::post(home,xy[0][0],xy[0][1]);
00241 (void) new (home) Lex<View>(home,xy,strict);
00242 return ES_OK;
00243 }
00244
00245 }}}
00246
00247
00248