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 namespace Gecode { namespace Int { namespace Circuit {
00035
00036
00037
00038
00039
00040 template<class View, class Offset>
00041 forceinline
00042 Dom<View,Offset>::Dom(Home home, ViewArray<View>& x, Offset& o)
00043 : Base<View,Offset>(home,x,o) {}
00044
00045 template<class View, class Offset>
00046 forceinline
00047 Dom<View,Offset>::Dom(Space& home, Dom<View,Offset>& p)
00048 : Base<View,Offset>(home,p) {}
00049
00050 template<class View, class Offset>
00051 Actor*
00052 Dom<View,Offset>::copy(Space& home) {
00053 return new (home) Dom<View,Offset>(home,*this);
00054 }
00055
00056 template<class View, class Offset>
00057 PropCost
00058 Dom<View,Offset>::cost(const Space&, const ModEventDelta& med) const {
00059 if (View::me(med) == Int::ME_INT_VAL)
00060 return PropCost::linear(PropCost::LO, x.size());
00061 else
00062 return PropCost::quadratic(PropCost::HI, x.size());
00063 }
00064
00065 template<class View, class Offset>
00066 void
00067 Dom<View,Offset>::reschedule(Space& home) {
00068 for (int i=y.size(); i--; )
00069 if (y[i].assigned()) {
00070 View::schedule(home, *this, ME_INT_VAL);
00071 return;
00072 }
00073 View::schedule(home, *this, ME_INT_DOM);
00074 }
00075
00076 template<class View, class Offset>
00077 ExecStatus
00078 Dom<View,Offset>::propagate(Space& home, const ModEventDelta& med) {
00079 if (View::me(med) == Int::ME_INT_VAL) {
00080 GECODE_ES_CHECK((Int::Distinct::prop_val<View,true>(home,y)));
00081 ExecStatus escv = connected(home);
00082 if (escv != ES_FIX)
00083 return escv;
00084 if (y.size() < 2)
00085 return home.ES_SUBSUMED(*this);
00086 return home.ES_FIX_PARTIAL(*this,View::med(Int::ME_INT_DOM));
00087 }
00088
00089 if (dc.available()) {
00090 GECODE_ES_CHECK(dc.sync());
00091 } else {
00092 GECODE_ES_CHECK(dc.init(home,y));
00093 }
00094 bool assigned;
00095 GECODE_ES_CHECK(dc.propagate(home,assigned));
00096
00097 ExecStatus esc = connected(home);
00098 if (esc != ES_FIX)
00099 return esc;
00100
00101
00102
00103
00104 if (assigned)
00105 for (int i=y.size(); i--; )
00106 if (y[i].assigned())
00107 y.move_lst(i);
00108
00109 return path(home);
00110 }
00111
00112 template<class View, class Offset>
00113 ExecStatus
00114 Dom<View,Offset>::post(Home home, ViewArray<View>& x, Offset& o) {
00115 int n = x.size();
00116 if (n == 1) {
00117 GECODE_ME_CHECK(o(x[0]).eq(home,0));
00118 } else if (n == 2) {
00119 GECODE_ME_CHECK(o(x[0]).eq(home,1));
00120 GECODE_ME_CHECK(o(x[1]).eq(home,0));
00121 } else {
00122 for (int i=n; i--; ) {
00123 GECODE_ME_CHECK(o(x[i]).gq(home,0));
00124 GECODE_ME_CHECK(o(x[i]).le(home,n));
00125 GECODE_ME_CHECK(o(x[i]).nq(home,i));
00126 }
00127 (void) new (home) Dom<View,Offset>(home,x,o);
00128 }
00129 return ES_OK;
00130 }
00131
00132 }}}
00133
00134
00135