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 Set { namespace Rel {
00039
00040 template<class View0, class View1, ReifyMode rm, bool strict>
00041 forceinline
00042 ReLq<View0,View1,rm,strict>::ReLq(Home home, View0 y0, View1 y1,
00043 Gecode::Int::BoolView y2)
00044 : Propagator(home), x0(y0), x1(y1), b(y2) {
00045 b.subscribe(home,*this, Gecode::Int::PC_INT_VAL);
00046 x0.subscribe(home,*this, PC_SET_ANY);
00047 x1.subscribe(home,*this, PC_SET_ANY);
00048 }
00049
00050 template<class View0, class View1, ReifyMode rm, bool strict>
00051 forceinline
00052 ReLq<View0,View1,rm,strict>::ReLq(Space& home, bool share, ReLq& p)
00053 : Propagator(home,share,p) {
00054 x0.update(home,share,p.x0);
00055 x1.update(home,share,p.x1);
00056 b.update(home,share,p.b);
00057 }
00058
00059 template<class View0, class View1, ReifyMode rm, bool strict>
00060 PropCost
00061 ReLq<View0,View1,rm,strict>::cost(const Space&, const ModEventDelta&) const
00062 {
00063 return PropCost::ternary(PropCost::LO);
00064 }
00065
00066 template<class View0, class View1, ReifyMode rm, bool strict>
00067 forceinline size_t
00068 ReLq<View0,View1,rm,strict>::dispose(Space& home) {
00069 b.cancel(home,*this, Gecode::Int::PC_INT_VAL);
00070 x0.cancel(home,*this, PC_SET_ANY);
00071 x1.cancel(home,*this, PC_SET_ANY);
00072 (void) Propagator::dispose(home);
00073 return sizeof(*this);
00074 }
00075
00076 template<class View0, class View1, ReifyMode rm, bool strict>
00077 ExecStatus
00078 ReLq<View0,View1,rm,strict>::post(Home home, View0 x0, View1 x1,
00079 Gecode::Int::BoolView b) {
00080 (void) new (home) ReLq<View0,View1,rm,strict>(home,x0,x1,b);
00081 return ES_OK;
00082 }
00083
00084 template<class View0, class View1, ReifyMode rm, bool strict>
00085 Actor*
00086 ReLq<View0,View1,rm,strict>::copy(Space& home, bool share) {
00087 return new (home) ReLq<View0,View1,rm,strict>(home,share,*this);
00088 }
00089
00090 template<class View0, class View1, ReifyMode rm, bool strict>
00091 ExecStatus
00092 ReLq<View0,View1,rm,strict>::propagate(Space& home, const ModEventDelta&) {
00093 if (b.one()) {
00094 if (rm == RM_PMI)
00095 return home.ES_SUBSUMED(*this);
00096 GECODE_REWRITE(*this,(Lq<View0,View1,strict>::post(home(*this),x0,x1)));
00097 }
00098 if (b.zero()) {
00099 if (rm == RM_IMP)
00100 return home.ES_SUBSUMED(*this);
00101 GECODE_REWRITE(*this,
00102 (Lq<View1,View0,!strict>::post(home(*this),x1,x0)));
00103 }
00104 if (x0.cardMax() == 0) {
00105 if ( (!strict) || x1.cardMin() > 0) {
00106 if (rm != RM_IMP)
00107 GECODE_ME_CHECK(b.one_none(home));
00108 return home.ES_SUBSUMED(*this);
00109 }
00110 if (strict && x1.cardMax() == 0) {
00111 if (rm != RM_PMI)
00112 GECODE_ME_CHECK(b.zero_none(home));
00113 return home.ES_SUBSUMED(*this);
00114 }
00115 }
00116
00117 if (x0.assigned() && x1.assigned()) {
00118
00119 int min01;
00120 {
00121 GlbRanges<View0> x0l(x0);
00122 GlbRanges<View1> x1l(x1);
00123 Iter::Ranges::Diff<GlbRanges<View1>,GlbRanges<View0> > d(x1l,x0l);
00124 if (!d()) {
00125 if ((!strict) && x0.cardMax() == x1.cardMax()) {
00126
00127 if (rm != RM_IMP)
00128 GECODE_ME_CHECK(b.one_none(home));
00129 } else {
00130
00131 if (rm != RM_PMI)
00132 GECODE_ME_CHECK(b.zero_none(home));
00133 }
00134 return home.ES_SUBSUMED(*this);
00135 }
00136 min01 = d.min();
00137 }
00138 int min10;
00139 {
00140 GlbRanges<View0> x0l(x0);
00141 GlbRanges<View1> x1l(x1);
00142 Iter::Ranges::Diff<GlbRanges<View0>,GlbRanges<View1> > d(x0l,x1l);
00143 if (!d()) {
00144 if (strict && x0.cardMax() == x1.cardMax()) {
00145
00146 if (rm != RM_PMI)
00147 GECODE_ME_CHECK(b.zero_none(home));
00148 } else {
00149
00150 if (rm != RM_IMP)
00151 GECODE_ME_CHECK(b.one_none(home));
00152 }
00153 return home.ES_SUBSUMED(*this);
00154 }
00155 min10 = d.min();
00156 }
00157
00158 assert(min01 != min10);
00159 if (min01<min10) {
00160 if (rm != RM_IMP)
00161 GECODE_ME_CHECK(b.one_none(home));
00162 } else {
00163 if (rm != RM_PMI)
00164 GECODE_ME_CHECK(b.zero_none(home));
00165 }
00166 return home.ES_SUBSUMED(*this);
00167 }
00168
00169
00170 if (x1.cardMax() > 0) {
00171 GlbRanges<View0> x0l(x0);
00172 LubRanges<View1> x1u(x1);
00173 int x1umin=x1u.min();
00174 Iter::Ranges::Diff<GlbRanges<View0>,LubRanges<View1> > d(x0l,x1u);
00175 if (d() && d.min() < x1umin) {
00176 if (rm != RM_PMI)
00177 GECODE_ME_CHECK(b.zero_none(home));
00178 return home.ES_SUBSUMED(*this);
00179 }
00180 }
00181
00182 if (x0.cardMax() > 0) {
00183 LubRanges<View0> x0u(x0);
00184 GlbRanges<View1> x1l(x1);
00185 int x0umin=x0u.min();
00186 Iter::Ranges::Diff<GlbRanges<View1>,LubRanges<View0> > d(x1l,x0u);
00187 if (d() && d.min() < x0umin) {
00188 if (rm != RM_IMP)
00189 GECODE_ME_CHECK(b.one_none(home));
00190 return home.ES_SUBSUMED(*this);
00191 }
00192 }
00193
00194 return ES_FIX;
00195 }
00196
00197 }}}
00198
00199