basic.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
00039
00040
00041
00042 namespace Gecode { namespace Int { namespace Extensional {
00043
00044
00045
00046
00047
00048
00049 template<class View, bool shared>
00050 forceinline
00051 Basic<View,shared>::Basic(Home home, ViewArray<View>& x,
00052 const TupleSet& t)
00053 : Base<View>(home,x,t) {
00054 }
00055
00056 template<class View, bool shared>
00057 forceinline ExecStatus
00058 Basic<View,shared>::post(Home home, ViewArray<View>& x,
00059 const TupleSet& t) {
00060
00061 for (int i = x.size(); i--; ) {
00062 GECODE_ME_CHECK(x[i].gq(home, t.min()));
00063 GECODE_ME_CHECK(x[i].lq(home, t.max()));
00064 }
00065 (void) new (home) Basic<View,shared>(home,x,t);
00066 return ES_OK;
00067 }
00068
00069 template<class View, bool shared>
00070 forceinline
00071 Basic<View,shared>::Basic(Space& home, bool share, Basic<View,shared>& p)
00072 : Base<View>(home,share,p) {
00073 }
00074
00075 template<class View, bool shared>
00076 PropCost
00077 Basic<View,shared>::cost(const Space&, const ModEventDelta& med) const {
00078 if (View::me(med) == ME_INT_VAL)
00079 return PropCost::quadratic(PropCost::HI,x.size());
00080 else
00081 return PropCost::cubic(PropCost::HI,x.size());
00082 }
00083
00084 template<class View, bool shared>
00085 Actor*
00086 Basic<View,shared>::copy(Space& home, bool share) {
00087 return new (home) Basic<View,shared>(home,share,*this);
00088 }
00089
00090 template<class View, bool shared>
00091 ExecStatus
00092 Basic<View,shared>::propagate(Space& home, const ModEventDelta&) {
00093
00094
00095
00096 Region r(home);
00097 BitSet* dom = r.alloc<BitSet>(x.size());
00098 init_dom(home, dom);
00099
00100
00101 BitSet* has_support = r.alloc<BitSet>(x.size());
00102 for (int i = x.size(); i--; )
00103 has_support[i].init(home, ts()->domsize);
00104
00105
00106
00107 Support::StaticStack<int,Region> nq(r,static_cast<int>(ts()->domsize));
00108
00109
00110
00111
00112 for (int i = x.size(); i--; ) {
00113 for (ViewValues<View> vv(x[i]); vv(); ++vv) {
00114
00115 int val = vv.val() - ts()->min;
00116 if (!has_support[i].get(static_cast<unsigned int>(val))) {
00117
00118 Tuple l = find_support(dom, i, val);
00119 if (l == NULL) {
00120
00121 nq.push(vv.val());
00122 } else {
00123
00124
00125
00126 for (int j = i; j--; ) {
00127 has_support[j].set(static_cast<unsigned int>(l[j]- ts()->min));
00128 assert(has_support[j].get(l[j] - ts()->min));
00129 }
00130 }
00131 }
00132 }
00133
00134
00135 while (!nq.empty())
00136 GECODE_ME_CHECK(x[i].nq(home,nq.pop()));
00137 }
00138
00139 for (int i = x.size(); i--; )
00140 if (!x[i].assigned())
00141 return shared ? ES_NOFIX : ES_FIX;
00142 return home.ES_SUBSUMED(*this);
00143 }
00144
00145 }}}
00146
00147
00148