Generated on Thu Apr 11 13:59:19 2019 for Gecode by doxygen 1.6.3

hull.cpp

Go to the documentation of this file.
00001 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
00002 /*
00003  *  Main authors:
00004  *     Guido Tack <tack@gecode.org>
00005  *     Christian Schulte <schulte@gecode.org>
00006  *
00007  *  Contributing authors:
00008  *     Gabor Szokoli <szokoli@gecode.org>
00009  *
00010  *  Copyright:
00011  *     Guido Tack, 2004
00012  *     Christian Schulte, 2004
00013  *     Gabor Szokoli, 2004
00014  *
00015  *  This file is part of Gecode, the generic constraint
00016  *  development environment:
00017  *     http://www.gecode.org
00018  *
00019  *  Permission is hereby granted, free of charge, to any person obtaining
00020  *  a copy of this software and associated documentation files (the
00021  *  "Software"), to deal in the Software without restriction, including
00022  *  without limitation the rights to use, copy, modify, merge, publish,
00023  *  distribute, sublicense, and/or sell copies of the Software, and to
00024  *  permit persons to whom the Software is furnished to do so, subject to
00025  *  the following conditions:
00026  *
00027  *  The above copyright notice and this permission notice shall be
00028  *  included in all copies or substantial portions of the Software.
00029  *
00030  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00031  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00032  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00033  *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00034  *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00035  *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00036  *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00037  *
00038  */
00039 
00040 #include <gecode/set/convex.hh>
00041 
00042 namespace Gecode { namespace Set { namespace Convex {
00043 
00044   Actor*
00045   ConvexHull::copy(Space& home) {
00046     return new (home) ConvexHull(home,*this);
00047   }
00048 
00049   ExecStatus
00050   ConvexHull::propagate(Space& home, const ModEventDelta&) {
00051     //x1 is the convex hull of x0
00052 
00053     GECODE_ME_CHECK( x1.cardMin(home,x0.cardMin()) );
00054     GECODE_ME_CHECK( x0.cardMax(home,x1.cardMax()) );
00055 
00056     do {
00057 
00058       //intersect x1 with (x0.lubMin(),x0.lubMax())
00059       //This empties x1 if x0.ub is empty. twice.
00060       GECODE_ME_CHECK( x1.exclude(home,Limits::min,
00061                                   x0.lubMin()-1) );
00062       GECODE_ME_CHECK( x1.exclude(home,x0.lubMax()+1,
00063                                   Limits::max) );
00064 
00065       int minElement = std::min(x1.glbMin(),x0.glbMin());
00066       int maxElement = std::max(x1.glbMax(),x0.glbMax());
00067 
00068       if (minElement<maxElement) {
00069         GECODE_ME_CHECK( x1.include(home, minElement, maxElement));
00070       }
00071 
00072       unsigned int cardMin = x1.cardMin();
00073 
00074       Region r;
00075       LubRanges<SetView> ubRangeIt(x1);
00076       Iter::Ranges::Cache ubRangeItC(r,ubRangeIt);
00077       for (;ubRangeItC();++ubRangeItC) {
00078         if (ubRangeItC.width() < cardMin
00079             || ubRangeItC.min() > minElement //No need to test for empty lb.
00080             || ubRangeItC.max() < maxElement
00081             ) {
00082           GECODE_ME_CHECK( x1.exclude(home,
00083                                       ubRangeItC.min(), ubRangeItC.max()) );
00084         }
00085       }
00086 
00087       LubRanges<SetView> ubRangeIt2(x1);
00088       GECODE_ME_CHECK(x0.intersectI(home,ubRangeIt2) );
00089 
00090       if (x1.lubMin()!=BndSet::MIN_OF_EMPTY) {
00091         if(x1.lubMin()==x1.glbMin()) {
00092               GECODE_ME_CHECK(x0.include(home,x1.lubMin()));
00093         }
00094         if(x1.lubMax()==x1.glbMax()) {
00095               GECODE_ME_CHECK(x0.include(home,x1.lubMax()));
00096         }
00097       }
00098     } while(x0.assigned()&&!x1.assigned());
00099 
00100     //If x0 is assigned, x1 should be too.
00101     assert(x1.assigned() || !x0.assigned());
00102 
00103     if (x1.assigned()) {
00104       return home.ES_SUBSUMED(*this);
00105     }
00106 
00107     return ES_NOFIX;
00108   }
00109 
00110 }}}
00111 
00112 // STATISTICS: set-prop