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
00039
00040 namespace Gecode { namespace Set { namespace Rel {
00041
00042 template <class View0, class View1>
00043 forceinline
00044 ReSubset<View0,View1>::ReSubset(Space* home, View0 y0,
00045 View1 y1, Gecode::Int::BoolView y2)
00046 : Propagator(home), x0(y0), x1(y1), b(y2) {
00047 b.subscribe(home,this, Gecode::Int::PC_INT_VAL);
00048 x0.subscribe(home,this, PC_SET_ANY);
00049 x1.subscribe(home,this, PC_SET_ANY);
00050 }
00051
00052 template <class View0, class View1>
00053 forceinline
00054 ReSubset<View0,View1>::ReSubset(Space* home, bool share, ReSubset& p)
00055 : Propagator(home,share,p) {
00056 x0.update(home,share,p.x0);
00057 x1.update(home,share,p.x1);
00058 b.update(home,share,p.b);
00059 }
00060
00061 template <class View0, class View1>
00062 PropCost
00063 ReSubset<View0,View1>::cost(ModEventDelta) const {
00064 return PC_TERNARY_LO;
00065 }
00066
00067 template <class View0, class View1>
00068 Support::Symbol
00069 ReSubset<View0,View1>::ati(void) {
00070 return Reflection::mangle<View0,View1>("Gecode::Set::Rel::ReSubset");
00071 }
00072
00073 template <class View0, class View1>
00074 Reflection::ActorSpec
00075 ReSubset<View0,View1>::spec(const Space* home,
00076 Reflection::VarMap& m) const {
00077 Reflection::ActorSpec s(ati());
00078 return s << x0.spec(home, m)
00079 << x1.spec(home, m)
00080 << b.spec(home, m);
00081 }
00082
00083 template <class View0, class View1>
00084 void
00085 ReSubset<View0,View1>::post(Space* home, Reflection::VarMap& vars,
00086 const Reflection::ActorSpec& spec) {
00087 spec.checkArity(3);
00088 View0 x0(home, vars, spec[0]);
00089 View1 x1(home, vars, spec[1]);
00090 Gecode::Int::BoolView b(home, vars, spec[2]);
00091 (void) new (home) ReSubset(home,x0,x1,b);
00092 }
00093
00094 template <class View0, class View1>
00095 size_t
00096 ReSubset<View0,View1>::dispose(Space* home) {
00097 assert(!home->failed());
00098 b.cancel(home,this, Gecode::Int::PC_INT_VAL);
00099 x0.cancel(home,this, PC_SET_ANY);
00100 x1.cancel(home,this, PC_SET_ANY);
00101 (void) Propagator::dispose(home);
00102 return sizeof(*this);
00103 }
00104
00105 template <class View0, class View1>
00106 ExecStatus
00107 ReSubset<View0,View1>::post(Space* home, View0 x0, View1 x1,
00108 Gecode::Int::BoolView b) {
00109 (void) new (home) ReSubset<View0,View1>(home,x0,x1,b);
00110 return ES_OK;
00111 }
00112
00113 template <class View0, class View1>
00114 Actor*
00115 ReSubset<View0,View1>::copy(Space* home, bool share) {
00116 return new (home) ReSubset<View0,View1>(home,share,*this);
00117 }
00118
00119 template <class View0, class View1>
00120 ExecStatus
00121 ReSubset<View0,View1>::propagate(Space* home, ModEventDelta) {
00122 if (b.one())
00123 GECODE_REWRITE(this,(SubSet<View0,View1>::post(home,x0,x1)));
00124 if (b.zero())
00125 GECODE_REWRITE(this,(NoSubSet<View0,View1>::post(home,x0,x1)));
00126
00127
00128 if (x0.cardMin() > x1.cardMax()) {
00129 GECODE_ME_CHECK(b.zero_none(home));
00130 return ES_SUBSUMED(this,home);
00131 }
00132
00133
00134 LubRanges<View0> x0ub(x0);
00135 GlbRanges<View1> x1lb(x1);
00136 Iter::Ranges::Diff<LubRanges<View0>,GlbRanges<View1> > diff1(x0ub, x1lb);
00137 if ( !(diff1()) ) {
00138 GECODE_ME_CHECK(b.one_none(home));
00139 return ES_SUBSUMED(this,home);
00140 }
00141
00142
00143 {
00144 GlbRanges<View0> x0lb(x0);
00145 LubRanges<View1> x1ub(x1);
00146 Iter::Ranges::Diff<GlbRanges<View0>,LubRanges<View1> > diff2(x0lb, x1ub);
00147 if ( diff2() ) {
00148 GECODE_ME_CHECK(b.zero_none(home));
00149 return ES_SUBSUMED(this,home);
00150 } else if (x0.assigned() && x1.assigned()) {
00151 GECODE_ME_CHECK(b.one_none(home));
00152 return ES_SUBSUMED(this,home);
00153 }
00154 }
00155
00156 if (x0.cardMin() > 0) {
00157 LubRanges<View0> x0ub(x0);
00158 LubRanges<View1> x1ub(x1);
00159 Iter::Ranges::Inter<LubRanges<View0>,LubRanges<View1> >
00160 inter(x0ub, x1ub);
00161 if (!inter()) {
00162 GECODE_ME_CHECK(b.zero_none(home));
00163 return ES_SUBSUMED(this,home);
00164 }
00165 }
00166
00167 return ES_FIX;
00168 }
00169
00170 }}}
00171
00172