Generated on Wed Nov 1 15:04:45 2006 for Gecode by doxygen 1.4.5

partition.icc

Go to the documentation of this file.
00001 /*
00002  *  Main authors:
00003  *     Guido Tack <tack@gecode.org>
00004  *     Christian Schulte <schulte@gecode.org>
00005  *
00006  *  Contributing authors:
00007  *     Gabor Szokoli <szokoli@gecode.org>
00008  *
00009  *  Copyright:
00010  *     Guido Tack, 2004
00011  *     Christian Schulte, 2004
00012  *     Gabor Szokoli, 2004
00013  *
00014  *  Last modified:
00015  *     $Date: 2006-07-18 15:09:57 +0200 (Tue, 18 Jul 2006) $ by $Author: tack $
00016  *     $Revision: 3386 $
00017  *
00018  *  This file is part of Gecode, the generic constraint
00019  *  development environment:
00020  *     http://www.gecode.org
00021  *
00022  *  See the file "LICENSE" for information on usage and
00023  *  redistribution of this file, and for a
00024  *     DISCLAIMER OF ALL WARRANTIES.
00025  *
00026  */
00027 
00028 namespace Gecode { namespace Set { namespace RelOp {
00029 
00030   /*
00031    * "Nary partition" propagator
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     //removing assigned sets from x, accumulating the value:
00108     for(int i=0;i<x.size();i++){
00109       //Do not reverse! Eats away the end of the array!
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     // When we run out of variables, make a final check and disolve:
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 // STATISTICS: set-prop