main page
modules
namespaces
classes
files
Gecode home
Generated on Tue Jan 28 2020 00:00:00 for Gecode by
doxygen
1.8.17
gecode
set
convex
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
53
ExecStatus
54
ConvexHull::propagate
(
Space
& home,
const
ModEventDelta
&) {
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.
64
GECODE_ME_CHECK
(
x1
.
exclude
(home,
Limits::min
,
65
x0
.
lubMin
()-1) );
66
GECODE_ME_CHECK
(
x1
.
exclude
(home,
x0
.
lubMax
()+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
) {
86
GECODE_ME_CHECK
(
x1
.
exclude
(home,
87
ubRangeItC.
min
(), ubRangeItC.
max
()) );
88
}
89
}
90
91
LubRanges<SetView>
ubRangeIt2(
x1
);
92
GECODE_ME_CHECK
(
x0
.
intersectI
(home,ubRangeIt2) );
93
94
if
(
x1
.
lubMin
()!=
BndSet::MIN_OF_EMPTY
) {
95
if
(
x1
.
lubMin
()==
x1
.
glbMin
()) {
96
GECODE_ME_CHECK
(
x0
.
include
(home,
x1
.
lubMin
()));
97
}
98
if
(
x1
.
lubMax
()==
x1
.
glbMax
()) {
99
GECODE_ME_CHECK
(
x0
.
include
(home,
x1
.
lubMax
()));
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
Gecode::Set::SetView::cardMax
unsigned int cardMax(void) const
Return maximum cardinality.
Definition:
set.hpp:90
Gecode::VarImpView::assigned
bool assigned(void) const
Test whether view is assigned.
Gecode::Set::LubRanges< SetView >
Range iterator for least upper bound of set variable views
Definition:
set.hpp:205
Gecode::Space::ES_SUBSUMED
ExecStatus ES_SUBSUMED(Propagator &p)
Definition:
core.hpp:3614
Gecode::Set::Limits::min
const int min
Smallest allowed integer in integer set.
Definition:
set.hh:103
Gecode::Set::Convex::ConvexHull::ConvexHull
ConvexHull(Space &home, bool share, ConvexHull &)
Constructor for cloning p.
Definition:
hull.hpp:56
Gecode::Float::Limits::min
const FloatNum min
Smallest allowed float value.
Definition:
float.hh:850
Gecode::Space
Computation spaces.
Definition:
core.hpp:1748
Gecode::Set::BndSet::MIN_OF_EMPTY
static const int MIN_OF_EMPTY
Returned by empty sets when asked for their minimum element.
Definition:
var-imp.hpp:116
Gecode::Set::SetView::intersectI
ModEvent intersectI(Space &home, I &iter)
Intersect least upper bound with range sequence described by i.
Definition:
set.hpp:168
Gecode
Gecode toplevel namespace
Gecode::Set::SetView::glbMax
int glbMax(void) const
Return maximum of the greatest lower bound.
Definition:
set.hpp:110
Gecode::Set::Limits::max
const int max
Largest allowed integer in integer set.
Definition:
set.hh:101
Gecode::Set::SetView::cardMin
unsigned int cardMin(void) const
Return minimum cardinality.
Definition:
set.hpp:86
Gecode::Iter::Ranges::RangeListIter::max
int max(void) const
Return largest value of range.
Definition:
ranges-list.hpp:253
Gecode::Set::Convex::ConvexHull::copy
virtual Actor * copy(Space &home, bool)
Copy propagator during cloning.
Definition:
hull.cpp:49
Gecode::Region
Handle to region.
Definition:
region.hpp:61
Gecode::r
Post propagator for SetVar SetOpType SetVar SetRelType r
Definition:
set.hh:784
Gecode::BinaryPropagator< SetView, PC_SET_ANY >::x1
SetView x1
Definition:
propagator.hpp:92
convex.hh
Gecode::Set::SetView::exclude
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::Iter::Ranges::RangeListIter::min
int min(void) const
Return smallest value of range.
Definition:
ranges-list.hpp:249
Gecode::Iter::Ranges::Cache
Range iterator cache
Definition:
ranges-cache.hpp:49
Gecode::Set::Convex::ConvexHull::propagate
virtual ExecStatus propagate(Space &home, const ModEventDelta &med)
Perform propagation.
Definition:
hull.cpp:54
Gecode::Set::SetView::glbMin
int glbMin(void) const
Return minimum of the greatest lower bound.
Definition:
set.hpp:106
Gecode::Set::SetView::lubMax
int lubMax(void) const
Return maximum of the least upper bound.
Definition:
set.hpp:98
GECODE_ME_CHECK
#define GECODE_ME_CHECK(me)
Check whether modification event me is failed, and forward failure.
Definition:
macros.hpp:56
Gecode::Set::SetView::lubMin
int lubMin(void) const
Return minimum of the least upper bound.
Definition:
set.hpp:94
Gecode::ModEventDelta
int ModEventDelta
Modification event deltas.
Definition:
core.hpp:169
Gecode::ES_NOFIX
@ ES_NOFIX
Propagation has not computed fixpoint.
Definition:
core.hpp:543
Gecode::BinaryPropagator< SetView, PC_SET_ANY >::x0
SetView x0
Two views.
Definition:
propagator.hpp:92
Gecode::Float::Limits::max
const FloatNum max
Largest allowed float value.
Definition:
float.hh:848
Gecode::Iter::Ranges::RangeListIter::width
unsigned int width(void) const
Return width of range (distance between minimum and maximum)
Definition:
ranges-list.hpp:257
Gecode::Set::SetView::include
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
Gecode::ExecStatus
ExecStatus
Definition:
core.hpp:540