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