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