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

conv.cc

Go to the documentation of this file.
00001 /*
00002  *  Main authors:
00003  *     Guido Tack <tack@gecode.org>
00004  *     Christian Schulte <schulte@gecode.org>
00005  *     Gabor Szokoli <szokoli@gecode.org>
00006  *
00007  *  Copyright:
00008  *     Guido Tack, 2004
00009  *     Christian Schulte, 2004
00010  *     Gabor Szokoli, 2004
00011  *
00012  *  Last modified:
00013  *     $Date: 2006-04-11 15:58:37 +0200 (Tue, 11 Apr 2006) $ by $Author: tack $
00014  *     $Revision: 3188 $
00015  *
00016  *  This file is part of Gecode, the generic constraint
00017  *  development environment:
00018  *     http://www.gecode.org
00019  *
00020  *  See the file "LICENSE" for information on usage and
00021  *  redistribution of this file, and for a
00022  *     DISCLAIMER OF ALL WARRANTIES.
00023  *
00024  */
00025 
00026 #include "gecode/set.hh"
00027 #include "gecode/set/convex.hh"
00028 
00029 #include "gecode/iter.hh"
00030 
00031 namespace Gecode { namespace Set { namespace Convex {
00032 
00033   Actor*
00034   Convex::copy(Space* home, bool share) {
00035     return new (home) Convex(home,share,*this);
00036   }
00037 
00038   ExecStatus
00039   Convex::propagate(Space* home) {
00040     //I, drop ranges from UB that are shorter than cardMin
00041     //II, add range LB.smallest to LB.largest to LB
00042     //III, Drop ranges from UB that do not contain all elements of LB
00043     //that is: range.min()>LB.smallest or range.max()<LB.largest
00044     //This leaves only one range.
00045 
00046     //II
00047     if (x0.glbSize()>0) {
00048       GECODE_ME_CHECK( x0.include(home,x0.glbMin(),x0.glbMax()) );
00049     } else {
00050       //If lower bound is empty, we can still constrain the cardinality
00051       //maximum with the width of the longest range in UB.
00052       //No need to do this if there is anything in LB because UB
00053       //becomes a single range then.
00054        LubRanges<SetView> ubRangeIt(x0);
00055        unsigned int maxWidth = 0;
00056        for (;ubRangeIt();++ubRangeIt){
00057          maxWidth = std::max(maxWidth, ubRangeIt.width());
00058        }
00059         GECODE_ME_CHECK( x0.cardMax(home,maxWidth) );
00060     }
00061 
00062 
00063     //I + III
00064 
00065     LubRanges<SetView> ubRangeIt(x0);
00066     Iter::Ranges::Cache< LubRanges<SetView> > ubRangeItC(ubRangeIt);
00067     for (;ubRangeItC();++ubRangeItC){
00068       if (ubRangeItC.width() < (unsigned int) x0.cardMin()
00069           || ubRangeItC.min() > x0.glbMin() //No need to test for empty lb.
00070           || ubRangeItC.max() < x0.glbMax()
00071           ) {
00072         GECODE_ME_CHECK( x0.exclude(home,ubRangeItC.min(), ubRangeItC.max()) );
00073       }
00074     }
00075     if (x0.assigned()) {return ES_SUBSUMED;}
00076     return ES_FIX;
00077   }
00078 
00079 }}}
00080 
00081 // STATISTICS: set-prop