main page
modules
namespaces
classes
files
Gecode home
Generated on Tue Mar 24 2020 14:04:04 for Gecode by
doxygen
1.8.17
test
set
convex.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
*
6
* Copyright:
7
* Guido Tack, 2005
8
*
9
* This file is part of Gecode, the generic constraint
10
* development environment:
11
* http://www.gecode.org
12
*
13
* Permission is hereby granted, free of charge, to any person obtaining
14
* a copy of this software and associated documentation files (the
15
* "Software"), to deal in the Software without restriction, including
16
* without limitation the rights to use, copy, modify, merge, publish,
17
* distribute, sublicense, and/or sell copies of the Software, and to
18
* permit persons to whom the Software is furnished to do so, subject to
19
* the following conditions:
20
*
21
* The above copyright notice and this permission notice shall be
22
* included in all copies or substantial portions of the Software.
23
*
24
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
29
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31
*
32
*/
33
34
#include "
test/set.hh
"
35
36
using namespace
Gecode
;
37
38
namespace
Test
{
namespace
Set {
39
41
namespace
Convex
{
42
48
49
static
IntSet
ds_33(-4,4);
50
52
class
Convex
:
public
SetTest
{
53
public
:
55
Convex
(
const
char
*
t
)
56
:
SetTest
(
t
,1,ds_33,false) {}
58
virtual
bool
solution
(
const
SetAssignment
&
x
)
const
{
59
CountableSetRanges
xr0(
x
.lub,
x
[0]);
60
if
(!xr0())
61
return
true
;
62
++xr0;
63
if
(!xr0())
64
return
true
;
65
return
false
;
66
}
68
virtual
void
post
(
Space
& home,
SetVarArray
&
x
,
IntVarArray
&) {
69
Gecode::convex
(home,
x
[0]);
70
}
71
};
72
Convex
_convex
(
"Convex::Convex"
);
73
75
class
ConvexHull
:
public
SetTest
{
76
public
:
78
ConvexHull
(
const
char
*
t
)
79
:
SetTest
(
t
,2,ds_33,false) {}
81
virtual
bool
solution
(
const
SetAssignment
&
x
)
const
{
82
CountableSetRanges
xr0(
x
.lub,
x
[0]);
83
CountableSetRanges
xr1(
x
.lub,
x
[1]);
84
85
if
(!xr0())
86
return
!xr1();
87
88
int
x0min = xr0.
min
();
89
int
x0max = xr0.
max
();
90
++xr0;
91
if
(!xr0()) {
92
if
(!xr1())
return
false
;
93
if
(x0min != xr1.
min
())
return
false
;
94
int
x1max =
Gecode::Set::Limits::min
;
95
while
(xr1()) { x1max = xr1.
max
(); ++xr1;}
96
if
(x0max != x1max)
return
false
;
97
return
true
;
98
}
99
return
false
;
100
}
102
virtual
void
post
(
Space
& home,
SetVarArray
&
x
,
IntVarArray
&) {
103
Gecode::convex
(home,
x
[1],
x
[0]);
104
}
105
};
106
ConvexHull
_convexhull
(
"Convex::ConvexHull"
);
107
109
class
ConvexHullS
:
public
SetTest
{
110
public
:
112
ConvexHullS
(
const
char
*
t
)
113
:
SetTest
(
t
,1,ds_33,false) {}
115
virtual
bool
solution
(
const
SetAssignment
&
x
)
const
{
116
CountableSetRanges
xr0(
x
.lub,
x
[0]);
117
if
(!xr0())
118
return
true
;
119
++xr0;
120
if
(!xr0())
121
return
true
;
122
return
false
;
123
}
125
virtual
void
post
(
Space
& home,
SetVarArray
&
x
,
IntVarArray
&) {
126
Gecode::convex
(home,
x
[0],
x
[0]);
127
}
128
};
129
ConvexHullS
_convexhulls
(
"Convex::Sharing::ConvexHullS"
);
130
132
133
}}}
134
135
// STATISTICS: test-set
Gecode::x
Post propagator for SetVar x
Definition:
set.hh:767
Test::Set::Convex::Convex::Convex
Convex(const char *t)
Create and register test.
Definition:
convex.cpp:55
Test::Set::Convex::ConvexHull
Test for convex hull propagator
Definition:
convex.cpp:75
Test::Set::Convex::ConvexHull::solution
virtual bool solution(const SetAssignment &x) const
Test whether x is solution
Definition:
convex.cpp:81
Gecode::Set::Limits::min
const int min
Smallest allowed integer in integer set.
Definition:
set.hh:99
t
NodeType t
Type of node.
Definition:
bool-expr.cpp:230
Gecode::Space
Computation spaces.
Definition:
core.hpp:1742
Gecode::IntVarArray
Integer variable array.
Definition:
int.hh:763
Test::Set::Convex::ConvexHullS::solution
virtual bool solution(const SetAssignment &x) const
Test whether x is solution
Definition:
convex.cpp:115
set.hh
Test::Set::SetAssignment
Generate all set assignments.
Definition:
set.hh:142
Test::Set::Convex::ConvexHullS::post
virtual void post(Space &home, SetVarArray &x, IntVarArray &)
Post constraint on x.
Definition:
convex.cpp:125
Gecode
Gecode toplevel namespace
Gecode::IntSet
Integer sets.
Definition:
int.hh:174
Test::Set::Convex::_convexhulls
ConvexHullS _convexhulls("Convex::Sharing::ConvexHullS")
Gecode::Iter::Ranges::MinMax::min
int min(void) const
Return smallest value of range.
Definition:
ranges-minmax.hpp:99
Test::Set::Convex::ConvexHullS::ConvexHullS
ConvexHullS(const char *t)
Create and register test.
Definition:
convex.cpp:112
Test::Set::Convex::ConvexHull::post
virtual void post(Space &home, SetVarArray &x, IntVarArray &)
Post constraint on x.
Definition:
convex.cpp:102
Test::Set::Convex::ConvexHullS
Sharing test for convex hull propagator.
Definition:
convex.cpp:109
Test::Set::Convex::_convex
Convex _convex("Convex::Convex")
Test::Set::SetTest
Base class for tests with set constraints
Definition:
set.hh:273
Test::Set::Convex::Convex::solution
virtual bool solution(const SetAssignment &x) const
Test whether x is solution
Definition:
convex.cpp:58
Test::Set::Convex::Convex
Test for convexity propagator
Definition:
convex.cpp:52
Test::Set::Convex::Convex::post
virtual void post(Space &home, SetVarArray &x, IntVarArray &)
Post constraint on x.
Definition:
convex.cpp:68
Gecode::Iter::Ranges::MinMax::max
int max(void) const
Return largest value of range.
Definition:
ranges-minmax.hpp:103
Test
General test support.
Definition:
afc.cpp:39
Test::Set::CountableSetRanges
Range iterator producing subsets of an IntSet.
Definition:
set.hh:98
Gecode::SetVarArray
Set variable array
Definition:
set.hh:570
Gecode::convex
void convex(Home home, SetVar x)
Definition:
convex.cpp:41
Test::Set::Convex::ConvexHull::ConvexHull
ConvexHull(const char *t)
Create and register test.
Definition:
convex.cpp:78
Test::Set::Convex::_convexhull
ConvexHull _convexhull("Convex::ConvexHull")