dom.hpp
Go to the documentation of this file.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 template<class View>
00079 ExecStatus
00080 Dom<View>::propagate(Space& home, const ModEventDelta& med) {
00081 if (View::me(med) == ME_INT_VAL) {
00082 ExecStatus es = prop_val<View,false>(home,x);
00083 GECODE_ES_CHECK(es);
00084 if (x.size() < 2)
00085 return home.ES_SUBSUMED(*this);
00086 if (es == ES_FIX)
00087 return home.ES_FIX_PARTIAL(*this,View::med(ME_INT_DOM));
00088 es = prop_bnd<View>(home,x);
00089 GECODE_ES_CHECK(es);
00090 if (x.size() < 2)
00091 return home.ES_SUBSUMED(*this);
00092 es = prop_val<View,true>(home,x);
00093 GECODE_ES_CHECK(es);
00094 if (x.size() < 2)
00095 return home.ES_SUBSUMED(*this);
00096 return home.ES_FIX_PARTIAL(*this,View::med(ME_INT_DOM));
00097 }
00098
00099 if (x.size() == 2)
00100 GECODE_REWRITE(*this,(Rel::Nq<View,View>::post(home(*this),x[0],x[1])));
00101 if (x.size() == 3)
00102 GECODE_REWRITE(*this,TerDom<View>::post(home(*this),x[0],x[1],x[2]));
00103
00104 if (dc.available()) {
00105 GECODE_ES_CHECK(dc.sync());
00106 } else {
00107 GECODE_ES_CHECK(dc.init(home,x));
00108 }
00109
00110 bool assigned;
00111 GECODE_ES_CHECK(dc.propagate(home,assigned));
00112
00113 return ES_FIX;
00114 }
00115
00116 }}}
00117
00118
00119