3
* Guido Tack <tack@gecode.org>
4
* Christian Schulte <schulte@gecode.org>
6
* Contributing authors:
7
* Gabor Szokoli <szokoli@gecode.org>
11
* Christian Schulte, 2004
15
* $Date: 2005-11-24 18:03:01 +0100 (Thu, 24 Nov 2005) $ by $Author: tack $
18
* This file is part of Gecode, the generic constraint
19
* development environment:
20
* http://www.gecode.org
22
* See the file "LICENSE" for information on usage and
23
* redistribution of this file, and for a
24
* DISCLAIMER OF ALL WARRANTIES.
29
#include "set/convex.hh"
31
namespace Gecode { namespace Set { namespace Convex {
34
ConvexHull::copy(Space* home, bool share) {
35
return new (home) ConvexHull(home,share,*this);
39
ConvexHull::cost(void) const {
43
ConvexHull::~ConvexHull(void) {
44
x0.cancel(this,PC_SET_CGLB);
45
x1.cancel(this,PC_SET_ANY);
49
ConvexHull::propagate(Space* home) {
50
//x1 is the convex hull of x0
52
GECODE_ME_CHECK( x1.cardMin(home,x0.cardMin()) );
53
GECODE_ME_CHECK( x0.cardMax(home,x1.cardMax()) );
57
//intersect x1 with (x0.lubMin(),x0.lubMax())
58
//This empties x1 if x0.ub is empty. twice.
59
GECODE_ME_CHECK( x1.exclude(home,Limits::Set::int_min,
61
GECODE_ME_CHECK( x1.exclude(home,x0.lubMax()+1,
62
Limits::Set::int_max) );
64
int minElement = std::min(x1.glbMin(),x0.glbMin());
65
int maxElement = std::max(x1.glbMax(),x0.glbMax());
67
if (minElement<maxElement) {
68
GECODE_ME_CHECK( x1.include(home, minElement, maxElement));
71
unsigned int cardMin = x1.cardMin();
73
LubRanges<SetView> ubRangeIt(x1);
74
Iter::Ranges::Cache< LubRanges<SetView> > ubRangeItC(ubRangeIt);
75
for (;ubRangeItC();++ubRangeItC){
76
if (ubRangeItC.width() < cardMin
77
|| ubRangeItC.min() > minElement //No need to test for empty lb.
78
|| ubRangeItC.max() < maxElement
80
GECODE_ME_CHECK( x1.exclude(home,
81
ubRangeItC.min(), ubRangeItC.max()) );
85
LubRanges<SetView> ubRangeIt2(x1);
86
GECODE_ME_CHECK(x0.intersectI(home,ubRangeIt2) );
88
if (x1.lubMin()!=BndSet::MIN_OF_EMPTY) {
89
if(x1.lubMin()==x1.glbMin()) {
90
GECODE_ME_CHECK(x0.include(home,x1.lubMin()));
92
if(x1.lubMax()==x1.glbMax()) {
93
GECODE_ME_CHECK(x0.include(home,x1.lubMax()));
96
} while(x0.assigned()&&!x1.assigned());
98
//If x0 is assigned, x1 should be too.
99
assert(x1.assigned() || !x0.assigned());
105
return shared(x0,x1) ? ES_NOFIX : ES_FIX;
110
// STATISTICS: set-prop