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 namespace Gecode { namespace Set { namespace RelOp {
00029
00030
00031
00032
00033
00034
00035 template <class View0, class View1>
00036 forceinline
00037 PartitionN<View0,View1>::PartitionN(Space* home, ViewArray<View0>& x, View1 y)
00038 : InhomNaryOnePropagator<View0,PC_SET_ANY,View1,PC_SET_ANY>(home, x, y) {
00039 shared = x.shared() || viewarrayshared(x,y);
00040 }
00041
00042 template <class View0, class View1>
00043 forceinline
00044 PartitionN<View0,View1>::PartitionN(Space* home, bool share, PartitionN& p)
00045 : InhomNaryOnePropagator<View0,PC_SET_ANY,View1,PC_SET_ANY>(home,share,p),
00046 shared(p.shared) {
00047 unionOfDets.update(home,p.unionOfDets);
00048 }
00049
00050 template <class View0, class View1>
00051 Actor*
00052 PartitionN<View0,View1>::copy(Space* home, bool share) {
00053 return new (home) PartitionN(home,share,*this);
00054 }
00055
00056 template <class View0, class View1>
00057 ExecStatus PartitionN<View0,View1>::post(Space* home, ViewArray<View0>& x,
00058 View1 y) {
00059 switch (x.size()) {
00060 case 0:
00061 GECODE_ME_CHECK(y.cardMax(home, 0));
00062 return ES_OK;
00063 case 1:
00064 return Rel::Eq<View0,View1>::post(home, x[0], y);
00065 default:
00066 (void) new (home) PartitionN<View0,View1>(home,x,y);
00067 return ES_OK;
00068 }
00069 }
00070
00071 template <class View0, class View1>
00072 PropCost PartitionN<View0,View1>::cost(void) const {
00073 return PC_QUADRATIC_LO;
00074 }
00075
00076 template <class View0, class View1>
00077 ExecStatus
00078 PartitionN<View0,View1>::propagate(Space* home) {
00079
00080 ModEvent me0 = View0::pme(this);
00081 ModEvent me1 = View1::pme(this);
00082 bool ubevent = Rel::testSetEventUB(me0, me1);
00083 bool lbevent = Rel::testSetEventLB(me0, me1);
00084 bool anybevent = Rel::testSetEventAnyB(me0, me1);
00085 bool cardevent = Rel::testSetEventCard(me0, me1);
00086
00087 bool modified = false;
00088 bool oldModified = false;
00089
00090 do {
00091 oldModified = modified;
00092 modified = false;
00093 if (oldModified || anybevent)
00094 GECODE_ME_CHECK(partitionNXiUB(home,modified, x, y,unionOfDets));
00095 if (modified || oldModified || anybevent)
00096 GECODE_ME_CHECK(partitionNXiLB(home,modified, x, y,unionOfDets));
00097 if (modified || oldModified || ubevent)
00098 GECODE_ME_CHECK(partitionNYUB(home,modified, x, y,unionOfDets));
00099 if (modified || oldModified || lbevent)
00100 GECODE_ME_CHECK(partitionNYLB(home,modified, x, y,unionOfDets));
00101 if (modified || oldModified || ubevent)
00102 GECODE_ME_CHECK(unionNXiUB(home,modified, x, y,unionOfDets));
00103 if (modified || oldModified || cardevent)
00104 GECODE_ME_CHECK(partitionNCard(home,modified, x, y,unionOfDets));
00105 } while (modified);
00106
00107
00108 for(int i=0;i<x.size();i++){
00109
00110 while (i<x.size() && x[i].assigned()) {
00111 GlbRanges<View0> det(x[i]);
00112 unionOfDets.includeI(home,det);
00113 x.move_lst(i);
00114 }
00115 }
00116
00117 if (x.size()==0) {
00118 BndSetRanges all1(unionOfDets);
00119 GECODE_ME_CHECK( y.intersectI(home,all1) );
00120 BndSetRanges all2(unionOfDets);
00121 GECODE_ME_CHECK( y.includeI(home,all2) );
00122 unionOfDets.dispose(home);
00123 return ES_SUBSUMED;
00124 }
00125
00126 return shared ? ES_NOFIX : ES_FIX;
00127 }
00128
00129 }}}
00130
00131