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