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
00043
00044 namespace Gecode { namespace Set { namespace RelOp {
00045
00046
00047
00048
00049
00050
00051 template<class View0, class View1>
00052 forceinline
00053 PartitionN<View0,View1>::PartitionN(Home home, ViewArray<View0>& x, View1 y)
00054 : MixNaryOnePropagator<View0,PC_SET_ANY,View1,PC_SET_ANY>(home, x, y) {
00055 shared = x.shared(home) || viewarrayshared(home,x,y);
00056 }
00057
00058 template<class View0, class View1>
00059 forceinline
00060 PartitionN<View0,View1>::PartitionN(Home home, ViewArray<View0>& x,
00061 const IntSet& z, View1 y)
00062 : MixNaryOnePropagator<View0,PC_SET_ANY,View1,PC_SET_ANY>(home, x, y) {
00063 shared = x.shared(home) || viewarrayshared(home,x,y);
00064 IntSetRanges rz(z);
00065 unionOfDets.includeI(home, rz);
00066 }
00067
00068 template<class View0, class View1>
00069 forceinline
00070 PartitionN<View0,View1>::PartitionN(Space& home, bool share, PartitionN& p)
00071 : MixNaryOnePropagator<View0,PC_SET_ANY,View1,PC_SET_ANY>(home,share,p),
00072 shared(p.shared) {
00073 unionOfDets.update(home,p.unionOfDets);
00074 }
00075
00076 template<class View0, class View1>
00077 Actor*
00078 PartitionN<View0,View1>::copy(Space& home, bool share) {
00079 return new (home) PartitionN(home,share,*this);
00080 }
00081
00082 template<class View0, class View1>
00083 ExecStatus PartitionN<View0,View1>::post(Home home, ViewArray<View0>& x,
00084 View1 y) {
00085 switch (x.size()) {
00086 case 0:
00087 GECODE_ME_CHECK(y.cardMax(home, 0));
00088 return ES_OK;
00089 case 1:
00090 return Rel::Eq<View0,View1>::post(home, x[0], y);
00091 default:
00092 (void) new (home) PartitionN<View0,View1>(home,x,y);
00093 return ES_OK;
00094 }
00095 }
00096
00097 template<class View0, class View1>
00098 ExecStatus PartitionN<View0,View1>::post(Home home, ViewArray<View0>& x,
00099 const IntSet& z, View1 y) {
00100 (void) new (home) PartitionN<View0,View1>(home,x,z,y);
00101 return ES_OK;
00102 }
00103
00104 template<class View0, class View1>
00105 PropCost PartitionN<View0,View1>::cost(const Space&, const ModEventDelta&) const {
00106 return PropCost::quadratic(PropCost::LO, x.size()+1);
00107 }
00108
00109 template<class View0, class View1>
00110 ExecStatus
00111 PartitionN<View0,View1>::propagate(Space& home, const ModEventDelta& med) {
00112
00113 ModEvent me0 = View0::me(med);
00114 ModEvent me1 = View1::me(med);
00115 bool ubevent = Rel::testSetEventUB(me0, me1);
00116 bool lbevent = Rel::testSetEventLB(me0, me1);
00117 bool anybevent = Rel::testSetEventAnyB(me0, me1);
00118 bool cardevent = Rel::testSetEventCard(me0, me1);
00119
00120 bool modified = false;
00121 bool oldModified = false;
00122
00123 do {
00124 oldModified = modified;
00125 modified = false;
00126 if (oldModified || anybevent)
00127 GECODE_ES_CHECK(partitionNXiUB(home,modified, x, y,unionOfDets));
00128 if (modified || oldModified || anybevent)
00129 GECODE_ES_CHECK(partitionNXiLB(home,modified, x, y,unionOfDets));
00130 if (modified || oldModified || ubevent)
00131 GECODE_ES_CHECK(partitionNYUB(home,modified, x, y,unionOfDets));
00132 if (modified || oldModified || lbevent)
00133 GECODE_ES_CHECK(partitionNYLB(home,modified, x, y,unionOfDets));
00134 if (modified || oldModified || ubevent)
00135 GECODE_ES_CHECK(unionNXiUB(home,modified, x, y,unionOfDets));
00136 if (modified || oldModified || cardevent)
00137 GECODE_ES_CHECK(partitionNCard(home,modified, x, y,unionOfDets));
00138 } while (modified);
00139
00140
00141 for(int i=0;i<x.size();i++){
00142
00143 while (i<x.size() && x[i].assigned()) {
00144 GlbRanges<View0> det(x[i]);
00145 unionOfDets.includeI(home,det);
00146 x.move_lst(i);
00147 }
00148 }
00149
00150 if (x.size()==0) {
00151 BndSetRanges all1(unionOfDets);
00152 GECODE_ME_CHECK( y.intersectI(home,all1) );
00153 BndSetRanges all2(unionOfDets);
00154 GECODE_ME_CHECK( y.includeI(home,all2) );
00155 unionOfDets.dispose(home);
00156 return home.ES_SUBSUMED(*this);
00157 }
00158
00159 return shared ? ES_NOFIX : ES_FIX;
00160 }
00161
00162 }}}
00163
00164