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 Distinct<View0,View1>::Distinct(Home home, View0 x, View1 y)
00045 : MixBinaryPropagator<View0, PC_SET_VAL, View1, PC_SET_VAL>(home,x,y) {}
00046
00047 template<class View0, class View1>
00048 forceinline
00049 Distinct<View0,View1>::Distinct(Space& home, Distinct& p)
00050 : MixBinaryPropagator<View0, PC_SET_VAL, View1, PC_SET_VAL>
00051 (home,p) {}
00052
00053 template<class View0, class View1>
00054 ExecStatus
00055 Distinct<View0,View1>::post(Home home, View0 x, View1 y) {
00056 if (same(x,y))
00057 return ES_FAILED;
00058 if (x.assigned()) {
00059 GlbRanges<View0> xr(x);
00060 IntSet xs(xr);
00061 ConstSetView cv(home, xs);
00062 GECODE_ES_CHECK((DistinctDoit<View1>::post(home,y,cv)));
00063 }
00064 if (y.assigned()) {
00065 GlbRanges<View1> yr(y);
00066 IntSet ys(yr);
00067 ConstSetView cv(home, ys);
00068 GECODE_ES_CHECK((DistinctDoit<View0>::post(home,x,cv)));
00069 }
00070 (void) new (home) Distinct<View0,View1>(home,x,y);
00071 return ES_OK;
00072 }
00073
00074 template<class View0, class View1>
00075 Actor*
00076 Distinct<View0,View1>::copy(Space& home) {
00077 return new (home) Distinct<View0,View1>(home,*this);
00078 }
00079
00080 template<class View0, class View1>
00081 ExecStatus
00082 Distinct<View0,View1>::propagate(Space& home, const ModEventDelta&) {
00083 assert(x0.assigned()||x1.assigned());
00084 if (x0.assigned()) {
00085 GlbRanges<View0> xr(x0);
00086 IntSet xs(xr);
00087 ConstSetView cv(home, xs);
00088 GECODE_REWRITE(*this,(DistinctDoit<View1>::post(home(*this),x1,cv)));
00089 } else {
00090 GlbRanges<View1> yr(x1);
00091 IntSet ys(yr);
00092 ConstSetView cv(home, ys);
00093 GECODE_REWRITE(*this,(DistinctDoit<View0>::post(home(*this),x0,cv)));
00094 }
00095 }
00096
00097 template<class View0>
00098 ExecStatus
00099 DistinctDoit<View0>::post(Home home, View0 x, ConstSetView y) {
00100 (void) new (home) DistinctDoit<View0>(home,x,y);
00101 return ES_OK;
00102 }
00103
00104 template<class View0>
00105 Actor*
00106 DistinctDoit<View0>::copy(Space& home) {
00107 return new (home) DistinctDoit<View0>(home,*this);
00108 }
00109
00110 template<class View0>
00111 ExecStatus
00112 DistinctDoit<View0>::propagate(Space& home, const ModEventDelta&) {
00113 if (x0.assigned()) {
00114 GlbRanges<View0> xi(x0);
00115 GlbRanges<ConstSetView> yi(y);
00116 if (Iter::Ranges::equal(xi,yi)) { return ES_FAILED; }
00117 else { return home.ES_SUBSUMED(*this); }
00118 }
00119 assert(x0.lubSize()-x0.glbSize() >0);
00120 if (x0.cardMin()>y.cardMax()) { return home.ES_SUBSUMED(*this); }
00121 if (x0.cardMax()<y.cardMin()) { return home.ES_SUBSUMED(*this); }
00122
00123
00124 GlbRanges<View0> xi1(x0);
00125 LubRanges<ConstSetView> yi1(y);
00126 if (!Iter::Ranges::subset(xi1,yi1)) { return home.ES_SUBSUMED(*this); }
00127 LubRanges<View0> xi2(x0);
00128 GlbRanges<ConstSetView> yi2(y);
00129 if (!Iter::Ranges::subset(yi2,xi2)) { return home.ES_SUBSUMED(*this); }
00130
00131
00132 if (x0.lubSize() == y.cardMin() && x0.lubSize() > 0) {
00133 GECODE_ME_CHECK(x0.cardMax(home, x0.lubSize() - 1));
00134 return home.ES_SUBSUMED(*this);
00135 }
00136 if (x0.glbSize() == y.cardMin()) {
00137 GECODE_ME_CHECK(x0.cardMin(home, x0.glbSize() + 1));
00138 return home.ES_SUBSUMED(*this);
00139 }
00140 return ES_FIX;
00141 }
00142
00143 template<class View0>
00144 forceinline
00145 DistinctDoit<View0>::DistinctDoit(Home home, View0 _x, ConstSetView _y)
00146 : UnaryPropagator<View0, PC_SET_ANY>(home,_x), y(_y) {}
00147
00148 template<class View0>
00149 forceinline
00150 DistinctDoit<View0>::DistinctDoit(Space& home, DistinctDoit<View0>& p)
00151 : UnaryPropagator<View0, PC_SET_ANY>(home,p) {
00152 y.update(home,p.y);
00153 }
00154
00155 }}}
00156
00157