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 namespace Gecode { namespace CpltSet {
00039
00040 template <class View0, class View1>
00041 ExecStatus
00042 NaryTwoCpltSetPropagator<View0, View1>::divide_conquer(Space* home, bdd& p,
00043 int l, int r, int ypos, int zpos) {
00044 if (l == r) {
00045 ModEvent me = ME_CPLTSET_NONE;
00046 if (l == ypos) {
00047 me = y.intersect(home, p);
00048 } else {
00049 if (l == zpos) {
00050 me = z.intersect(home, p);
00051 } else {
00052 me = x[l].intersect(home, p);
00053 }
00054 }
00055 if (me_failed(me)) {
00056 return ES_FAILED;
00057 }
00058 return ES_OK;
00059 }
00060 int h = (r + l) / 2;
00061
00062
00063 bdd left = p;
00064 for (int i = r; i >= h + 1; i--) {
00065 if (i == zpos) {
00066 quantify(left, z);
00067 } else {
00068 if (i == ypos) {
00069 quantify(left, y);
00070 } else {
00071 quantify(left, x[i]);
00072 }
00073 }
00074 }
00075
00076 ExecStatus es = ES_OK;
00077 GECODE_ES_CHECK(es = divide_conquer(home, left, l, h, ypos, zpos));
00078
00079 bdd right = p;
00080 for (int i = h; i >= l; i-- ) {
00081 if (i == zpos) {
00082 quantify(right, z);
00083 } else {
00084 if (i == ypos) {
00085 quantify(right, y);
00086 } else {
00087 quantify(right, x[i]);
00088 }
00089 }
00090 }
00091
00092 GECODE_ES_CHECK(es = divide_conquer(home, right, h + 1, r , ypos, zpos));
00093 return es;
00094 }
00095
00096 template <class View0, class View1>
00097 forceinline
00098 NaryTwoCpltSetPropagator<View0, View1>
00099 ::NaryTwoCpltSetPropagator(Space* home, ViewArray<View0>& x0,
00100 View1& y0, View1& z0, bdd&)
00101 : Propagator(home), x(x0), y(y0), z(z0) {
00102 Propagator::force(home);
00103 x.subscribe(home, this, PC_CPLTSET_DOM);
00104 y.subscribe(home, this, PC_CPLTSET_DOM);
00105 z.subscribe(home, this, PC_CPLTSET_DOM);
00106 }
00107
00108 template <class View0, class View1>
00109 forceinline
00110 NaryTwoCpltSetPropagator<View0, View1>
00111 ::NaryTwoCpltSetPropagator(Space* home, bool share,
00112 NaryTwoCpltSetPropagator& p)
00113 : Propagator(home, share, p), d(p.d) {
00114 x.update(home,share,p.x);
00115 y.update(home,share,p.y);
00116 z.update(home,share,p.z);
00117 }
00118
00119 template <class View0, class View1>
00120 forceinline ExecStatus
00121 NaryTwoCpltSetPropagator<View0, View1>::post(Space* home, ViewArray<View0>& x,
00122 View1& y, View1& z, bdd& d0) {
00123 (void) new (home) NaryTwoCpltSetPropagator(home, x, y, z, d0);
00124 return ES_OK;
00125 }
00126
00127 template <class View0, class View1>
00128 Support::Symbol
00129 NaryTwoCpltSetPropagator<View0, View1>::ati(void) {
00130 return
00131 Reflection::mangle<View0,View1>("Gecode::CpltSet::NaryTwoCpltSetPropagator");
00132 }
00133
00134 template <class View0, class View1>
00135 Reflection::ActorSpec
00136 NaryTwoCpltSetPropagator<View0,View1>::spec(const Space*,
00137 Reflection::VarMap&) const {
00138 throw Reflection::ReflectionException("Not implemented");
00139 }
00140
00141 template <class View0, class View1>
00142 forceinline Actor*
00143 NaryTwoCpltSetPropagator<View0, View1>::copy(Space* home, bool share) {
00144 return new (home) NaryTwoCpltSetPropagator(home, share, *this);
00145 }
00146
00147 template <class View0, class View1>
00148 forceinline ExecStatus
00149 NaryTwoCpltSetPropagator<View0, View1>::propagate(Space* home, ModEventDelta) {
00150 bool assigned = true;
00151 int n = x.size();
00152 ExecStatus es = ES_OK;
00153 int ypos = n;
00154 int zpos = n + 1;
00155
00156 GECODE_ES_CHECK(es = divide_conquer(home, d, 0, n + 1, ypos, zpos));
00157
00158 assigned = true;
00159 for (int i = x.size(); i--; ) {
00160 assigned &= x[i].assigned();
00161 }
00162 if (assigned) {
00163 return ES_SUBSUMED(this, home);
00164 }
00165
00166 return ES_FIX;
00167 }
00168
00169 template <class View0, class View1>
00170 PropCost
00171 NaryTwoCpltSetPropagator<View0,View1>::cost(ModEventDelta) const {
00172 return cost_lo(x.size()+2, PC_LINEAR_LO);
00173 }
00174
00175 template <class View0, class View1>
00176 size_t
00177 NaryTwoCpltSetPropagator<View0, View1>::dispose(Space* home) {
00178 unforce(home);
00179 if (!home->failed()) {
00180 x.cancel(home, this, PC_CPLTSET_DOM);
00181 y.cancel(home, this, PC_CPLTSET_DOM);
00182 z.cancel(home, this, PC_CPLTSET_DOM);
00183 }
00184 manager.dispose(d);
00185 (void) Propagator::dispose(home);
00186 return sizeof(*this);
00187 }
00188
00189 }}
00190
00191