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 #include <climits>
00035
00036 namespace Gecode { namespace Int { namespace Distinct {
00037
00038 template<class View>
00039 forceinline
00040 Dom<View>::Dom(Home home, ViewArray<View>& x)
00041 : NaryPropagator<View,PC_INT_DOM>(home,x) {}
00042
00043 template<class View>
00044 ExecStatus
00045 Dom<View>::post(Home home, ViewArray<View>& x) {
00046 if (x.size() == 2)
00047 return Rel::Nq<View,View>::post(home,x[0],x[1]);
00048 if (x.size() == 3)
00049 return TerDom<View>::post(home,x[0],x[1],x[2]);
00050 if (x.size() > 3) {
00051
00052 GECODE_ES_CHECK(prop_bnd<View>(home,x));
00053 (void) new (home) Dom<View>(home,x);
00054 }
00055 return ES_OK;
00056 }
00057
00058 template<class View>
00059 forceinline
00060 Dom<View>::Dom(Space& home, Dom<View>& p)
00061 : NaryPropagator<View,PC_INT_DOM>(home,p) {}
00062
00063 template<class View>
00064 PropCost
00065 Dom<View>::cost(const Space&, const ModEventDelta& med) const {
00066 if (View::me(med) == ME_INT_VAL)
00067 return PropCost::linear(PropCost::LO, x.size());
00068 else
00069 return PropCost::quadratic(PropCost::HI, x.size());
00070 }
00071
00072 template<class View>
00073 Actor*
00074 Dom<View>::copy(Space& home) {
00075 return new (home) Dom<View>(home,*this);
00076 }
00077
00078 #ifdef GECODE_HAS_CBS
00079 template<class View>
00080 void
00081 Dom<View>::solndistrib(Space& home, Propagator::SendMarginal send) const {
00082 cbsdistinct(home,this->id(),x,send);
00083 }
00084
00085 template<class View>
00086 void
00087 Dom<View>::domainsizesum(Propagator::InDecision in, unsigned int& size,
00088 unsigned int& size_b) const {
00089 cbssize(x,in,size,size_b);
00090 }
00091 #endif
00092
00093
00094 template<class View>
00095 ExecStatus
00096 Dom<View>::propagate(Space& home, const ModEventDelta& med) {
00097 if (View::me(med) == ME_INT_VAL) {
00098 ExecStatus es = prop_val<View,false>(home,x);
00099 GECODE_ES_CHECK(es);
00100 if (x.size() < 2)
00101 return home.ES_SUBSUMED(*this);
00102 if (es == ES_FIX)
00103 return home.ES_FIX_PARTIAL(*this,View::med(ME_INT_DOM));
00104 es = prop_bnd<View>(home,x);
00105 GECODE_ES_CHECK(es);
00106 if (x.size() < 2)
00107 return home.ES_SUBSUMED(*this);
00108 es = prop_val<View,true>(home,x);
00109 GECODE_ES_CHECK(es);
00110 if (x.size() < 2)
00111 return home.ES_SUBSUMED(*this);
00112 return home.ES_FIX_PARTIAL(*this,View::med(ME_INT_DOM));
00113 }
00114
00115 if (x.size() == 2)
00116 GECODE_REWRITE(*this,(Rel::Nq<View,View>::post(home(*this),x[0],x[1])));
00117 if (x.size() == 3)
00118 GECODE_REWRITE(*this,TerDom<View>::post(home(*this),x[0],x[1],x[2]));
00119
00120 if (dc.available()) {
00121 GECODE_ES_CHECK(dc.sync());
00122 } else {
00123 GECODE_ES_CHECK(dc.init(home,x));
00124 }
00125
00126 bool assigned;
00127 GECODE_ES_CHECK(dc.propagate(home,assigned));
00128
00129 return ES_FIX;
00130 }
00131
00132 }}}
00133
00134
00135