Generated on Sat Feb 7 2015 02:01:29 for Gecode by doxygen 1.8.9.1
hull.cpp
Go to the documentation of this file.
1 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2 /*
3  * Main authors:
4  * Guido Tack <tack@gecode.org>
5  * Christian Schulte <schulte@gecode.org>
6  *
7  * Contributing authors:
8  * Gabor Szokoli <szokoli@gecode.org>
9  *
10  * Copyright:
11  * Guido Tack, 2004
12  * Christian Schulte, 2004
13  * Gabor Szokoli, 2004
14  *
15  * Last modified:
16  * $Date: 2012-09-07 17:31:22 +0200 (Fri, 07 Sep 2012) $ by $Author: schulte $
17  * $Revision: 13068 $
18  *
19  * This file is part of Gecode, the generic constraint
20  * development environment:
21  * http://www.gecode.org
22  *
23  * Permission is hereby granted, free of charge, to any person obtaining
24  * a copy of this software and associated documentation files (the
25  * "Software"), to deal in the Software without restriction, including
26  * without limitation the rights to use, copy, modify, merge, publish,
27  * distribute, sublicense, and/or sell copies of the Software, and to
28  * permit persons to whom the Software is furnished to do so, subject to
29  * the following conditions:
30  *
31  * The above copyright notice and this permission notice shall be
32  * included in all copies or substantial portions of the Software.
33  *
34  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
35  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
36  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
37  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
38  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
39  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
40  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
41  *
42  */
43 
44 #include <gecode/set/convex.hh>
45 
46 namespace Gecode { namespace Set { namespace Convex {
47 
48  Actor*
49  ConvexHull::copy(Space& home, bool share) {
50  return new (home) ConvexHull(home,share,*this);
51  }
52 
55  //x1 is the convex hull of x0
56 
57  GECODE_ME_CHECK( x1.cardMin(home,x0.cardMin()) );
58  GECODE_ME_CHECK( x0.cardMax(home,x1.cardMax()) );
59 
60  do {
61 
62  //intersect x1 with (x0.lubMin(),x0.lubMax())
63  //This empties x1 if x0.ub is empty. twice.
65  x0.lubMin()-1) );
67  Limits::max) );
68 
69  int minElement = std::min(x1.glbMin(),x0.glbMin());
70  int maxElement = std::max(x1.glbMax(),x0.glbMax());
71 
72  if (minElement<maxElement) {
73  GECODE_ME_CHECK( x1.include(home, minElement, maxElement));
74  }
75 
76  unsigned int cardMin = x1.cardMin();
77 
78  Region r(home);
79  LubRanges<SetView> ubRangeIt(x1);
80  Iter::Ranges::Cache ubRangeItC(r,ubRangeIt);
81  for (;ubRangeItC();++ubRangeItC){
82  if (ubRangeItC.width() < cardMin
83  || ubRangeItC.min() > minElement //No need to test for empty lb.
84  || ubRangeItC.max() < maxElement
85  ) {
87  ubRangeItC.min(), ubRangeItC.max()) );
88  }
89  }
90 
91  LubRanges<SetView> ubRangeIt2(x1);
92  GECODE_ME_CHECK(x0.intersectI(home,ubRangeIt2) );
93 
95  if(x1.lubMin()==x1.glbMin()) {
97  }
98  if(x1.lubMax()==x1.glbMax()) {
100  }
101  }
102  } while(x0.assigned()&&!x1.assigned());
103 
104  //If x0 is assigned, x1 should be too.
105  assert(x1.assigned() || !x0.assigned());
106 
107  if (x1.assigned()) {
108  return home.ES_SUBSUMED(*this);
109  }
110 
111  return ES_NOFIX;
112  }
113 
114 }}}
115 
116 // STATISTICS: set-prop
unsigned int cardMin(void) const
Return minimum cardinality.
Definition: set.hpp:86
ModEvent include(Space &home, int i, int j)
Update greatest lower bound to include all elements between and including i and j.
Definition: set.hpp:130
const int min
Smallest allowed integer in integer set.
Definition: set.hh:101
ExecStatus ES_SUBSUMED(Propagator &p)
Definition: core.hpp:2973
const FloatNum max
Largest allowed float value.
Definition: float.hh:831
int min(void) const
Return smallest value of range.
ConvexHull(Space &home, bool share, ConvexHull &)
Constructor for cloning p.
Definition: hull.hpp:56
int glbMin(void) const
Return minimum of the greatest lower bound.
Definition: set.hpp:106
unsigned int cardMax(void) const
Return maximum cardinality.
Definition: set.hpp:90
Handle to region.
Definition: region.hpp:61
static const int MIN_OF_EMPTY
Returned by empty sets when asked for their minimum element.
Definition: var-imp.hpp:116
const int max
Largest allowed integer in integer set.
Definition: set.hh:99
Computation spaces.
Definition: core.hpp:1362
const FloatNum min
Smallest allowed float value.
Definition: float.hh:833
Range iterator for least upper bound of set variable views
Definition: set.hpp:205
int lubMin(void) const
Return minimum of the least upper bound.
Definition: set.hpp:94
NNF * r
Right subtree.
Definition: bool-expr.cpp:246
int glbMax(void) const
Return maximum of the greatest lower bound.
Definition: set.hpp:110
virtual Actor * copy(Space &home, bool)
Copy propagator during cloning.
Definition: hull.cpp:49
#define GECODE_ME_CHECK(me)
Check whether modification event me is failed, and forward failure.
Definition: macros.hpp:45
int lubMax(void) const
Return maximum of the least upper bound.
Definition: set.hpp:98
ModEvent intersectI(Space &home, I &iter)
Intersect least upper bound with range sequence described by i.
Definition: set.hpp:168
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition: hull.cpp:54
Range iterator cache
ExecStatus
Definition: core.hpp:523
bool assigned(void) const
Test whether view is assigned.
Definition: view.hpp:448
int max(void) const
Return largest value of range.
unsigned int width(void) const
Return width of range (distance between minimum and maximum)
Propagation has not computed fixpoint.
Definition: core.hpp:526
ModEvent exclude(Space &home, int i, int j)
Restrict least upper bound to not contain all elements between and including i and j...
Definition: set.hpp:160
Gecode toplevel namespace
int ModEventDelta
Modification event deltas.
Definition: core.hpp:173