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