Generated on Mon Sep 17 2012 22:20:44 for Gecode by doxygen 1.8.1.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: 2011-08-09 02:04:53 +1000 (Tue, 09 Aug 2011) $ by $Author: schulte $
17  * $Revision: 12253 $
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