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(Space* 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(Space* home, View0 x, View1 y) {
00060 if (x.assigned()) {
00061 GlbRanges<View0> xr(x);
00062 IntSet xs(xr);
00063 ConstantView 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 ConstantView 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 Support::Symbol
00084 Distinct<View0,View1>::ati(void) {
00085 return Reflection::mangle<View0,View1>("Gecode::Set::Rel::Distinct");
00086 }
00087
00088 template <class View0, class View1>
00089 Reflection::ActorSpec
00090 Distinct<View0,View1>::spec(const Space* home,
00091 Reflection::VarMap& m) const {
00092 return MixBinaryPropagator<View0, PC_SET_VAL, View1, PC_SET_VAL>
00093 ::spec(home, m, ati());
00094 }
00095
00096 template <class View0, class View1>
00097 void
00098 Distinct<View0,View1>::post(Space* home, Reflection::VarMap& vars,
00099 const Reflection::ActorSpec& spec) {
00100 spec.checkArity(2);
00101 View0 x0(home, vars, spec[0]);
00102 View1 x1(home, vars, spec[1]);
00103 (void) new (home) Distinct(home,x0,x1);
00104 }
00105
00106 template <class View0, class View1>
00107 ExecStatus
00108 Distinct<View0,View1>::propagate(Space* home, ModEventDelta) {
00109 assert(x0.assigned()||x1.assigned());
00110 if (x0.assigned()) {
00111 GlbRanges<View0> xr(x0);
00112 IntSet xs(xr);
00113 ConstantView cv(home, xs);
00114 GECODE_REWRITE(this,(DistinctDoit<View1>::post(home,x1,cv)));
00115 } else {
00116 GlbRanges<View1> yr(x1);
00117 IntSet ys(yr);
00118 ConstantView cv(home, ys);
00119 GECODE_REWRITE(this,(DistinctDoit<View0>::post(home,x0,cv)));
00120 }
00121 }
00122
00123 template <class View0>
00124 ExecStatus
00125 DistinctDoit<View0>::post(Space* home, View0 x, ConstantView y) {
00126 (void) new (home) DistinctDoit<View0>(home,x,y);
00127 return ES_OK;
00128 }
00129
00130 template <class View0>
00131 Actor*
00132 DistinctDoit<View0>::copy(Space* home, bool share) {
00133 return new (home) DistinctDoit<View0>(home,share,*this);
00134 }
00135
00136 template <class View0>
00137 Support::Symbol
00138 DistinctDoit<View0>::ati(void) {
00139 return Reflection::mangle<View0>("Gecode::Set::Rel::DistinctDoit");
00140 }
00141
00142 template <class View0>
00143 Reflection::ActorSpec
00144 DistinctDoit<View0>::spec(const Space* home, Reflection::VarMap& m) const {
00145 Reflection::ActorSpec s =
00146 UnaryPropagator<View0,PC_SET_ANY>::spec(home, m, ati());
00147 return s << y.spec(home, m);
00148 }
00149
00150 template <class View0>
00151 void
00152 DistinctDoit<View0>::post(Space* home, Reflection::VarMap& vars,
00153 const Reflection::ActorSpec& spec) {
00154 spec.checkArity(2);
00155 View0 x0(home, vars, spec[0]);
00156 ConstantView x1(home, vars, spec[1]);
00157 (void) new (home) DistinctDoit(home,x0,x1);
00158 }
00159
00160 template <class View0>
00161 ExecStatus
00162 DistinctDoit<View0>::propagate(Space* home, ModEventDelta) {
00163 if (x0.assigned()) {
00164 GlbRanges<View0> xi(x0);
00165 GlbRanges<ConstantView> yi(y);
00166 if (Iter::Ranges::equal(xi,yi)) { return ES_FAILED; }
00167 else { return ES_SUBSUMED(this,home); }
00168 }
00169 assert(x0.lubSize()-x0.glbSize() >0);
00170 if (x0.cardMin()>y.cardMax()) { return ES_SUBSUMED(this,home); }
00171 if (x0.cardMax()<y.cardMin()) { return ES_SUBSUMED(this,home); }
00172
00173
00174 GlbRanges<View0> xi1(x0);
00175 LubRanges<ConstantView> yi1(y);
00176 if (!Iter::Ranges::subset(xi1,yi1)){ return ES_SUBSUMED(this,home); }
00177 LubRanges<View0> xi2(x0);
00178 GlbRanges<ConstantView> yi2(y);
00179 if (!Iter::Ranges::subset(yi2,xi2)){ return ES_SUBSUMED(this,home); }
00180
00181
00182 if (x0.lubSize() == y.cardMin() && x0.lubSize() > 0) {
00183 GECODE_ME_CHECK(x0.cardMax(home, x0.lubSize() - 1));
00184 return ES_SUBSUMED(this,home);
00185 }
00186 if (x0.glbSize() == y.cardMin()) {
00187 GECODE_ME_CHECK(x0.cardMin(home, x0.glbSize() + 1));
00188 return ES_SUBSUMED(this,home);
00189 }
00190 return ES_FIX;
00191 }
00192
00193 template <class View0>
00194 forceinline
00195 DistinctDoit<View0>::DistinctDoit(Space* home, View0 _x, ConstantView _y)
00196 : UnaryPropagator<View0, PC_SET_ANY>(home,_x), y(_y) {}
00197
00198 template <class View0>
00199 forceinline
00200 DistinctDoit<View0>::DistinctDoit(Space* home, bool share,
00201 DistinctDoit<View0>& p)
00202 : UnaryPropagator<View0, PC_SET_ANY>(home,share,p) {
00203 y.update(home,share,p.y);
00204 }
00205
00206 }}}
00207
00208