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
distinct.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
Distinct
{
42
48
49
static
IntSet
ds_33(-2,2);
50
static
IntSet
ds_44(-4,4);
51
53
class
AtmostOne
:
public
SetTest
{
54
public
:
56
AtmostOne
(
const
char
*
t
)
57
:
SetTest
(
t
,3,ds_33,false) {}
59
virtual
bool
solution
(
const
SetAssignment
&
x
)
const
{
60
{
61
CountableSetRanges
xr0(
x
.lub,
x
[0]);
62
CountableSetRanges
xr1(
x
.lub,
x
[1]);
63
Iter::Ranges::Inter<CountableSetRanges,CountableSetRanges>
64
i
(xr0,xr1);
65
if
(
Iter::Ranges::size
(
i
)>1)
66
return
false
;
67
}
68
{
69
CountableSetRanges
xr0(
x
.lub,
x
[0]);
70
CountableSetRanges
xr2(
x
.lub,
x
[2]);
71
Iter::Ranges::Inter<CountableSetRanges,CountableSetRanges>
72
i
(xr0,xr2);
73
if
(
Iter::Ranges::size
(
i
)>1)
74
return
false
;
75
}
76
{
77
CountableSetRanges
xr1(
x
.lub,
x
[1]);
78
CountableSetRanges
xr2(
x
.lub,
x
[2]);
79
Iter::Ranges::Inter<CountableSetRanges,CountableSetRanges>
80
i
(xr1,xr2);
81
if
(
Iter::Ranges::size
(
i
)>1)
82
return
false
;
83
}
84
{
85
CountableSetRanges
xr0(
x
.lub,
x
[0]);
86
CountableSetRanges
xr1(
x
.lub,
x
[1]);
87
CountableSetRanges
xr2(
x
.lub,
x
[2]);
88
if
(
Iter::Ranges::size
(xr0)!=3 ||
89
Iter::Ranges::size
(xr1)!=3 ||
90
Iter::Ranges::size
(xr2)!=3)
91
return
false
;
92
}
93
return
true
;
94
}
96
virtual
void
post
(
Space
& home,
SetVarArray
&
x
,
IntVarArray
&) {
97
SetVar
s1(home,
IntSet::empty
, -2, 2, 0U, 1U);
98
Gecode::rel
(home,
x
[0],
SOT_INTER
,
x
[1],
SRT_EQ
, s1);
99
SetVar
s2(home,
IntSet::empty
, -2, 2, 0U, 1U);
100
Gecode::rel
(home,
x
[0],
SOT_INTER
,
x
[2],
SRT_EQ
, s2);
101
SetVar
s3(home,
IntSet::empty
, -2, 2, 0U, 1U);
102
Gecode::rel
(home,
x
[1],
SOT_INTER
,
x
[2],
SRT_EQ
, s3);
103
Gecode::atmostOne
(home,
x
, 3);
104
}
105
};
106
AtmostOne
_atmostone
(
"Distinct::AtmostOne"
);
107
109
110
}}}
111
112
// STATISTICS: test-set
Gecode::x
Post propagator for SetVar x
Definition:
set.hh:767
Test::Set::Distinct::AtmostOne
Test for the atmostone propagator
Definition:
distinct.cpp:53
Gecode::Iter::Ranges::size
unsigned int size(I &i)
Size of all ranges of range iterator i.
Definition:
ranges-operations.hpp:74
Gecode::IntSet::empty
static const IntSet empty
Empty set.
Definition:
int.hh:283
t
NodeType t
Type of node.
Definition:
bool-expr.cpp:230
Gecode::Space
Computation spaces.
Definition:
core.hpp:1742
Test::Set::Distinct::AtmostOne::post
virtual void post(Space &home, SetVarArray &x, IntVarArray &)
Post constraint on x.
Definition:
distinct.cpp:96
Gecode::IntVarArray
Integer variable array.
Definition:
int.hh:763
Test::Set::Distinct::AtmostOne::solution
virtual bool solution(const SetAssignment &x) const
Test whether x is solution
Definition:
distinct.cpp:59
set.hh
Test::Set::SetAssignment
Generate all set assignments.
Definition:
set.hh:142
Gecode::SOT_INTER
@ SOT_INTER
Intersection
Definition:
set.hh:663
Gecode
Gecode toplevel namespace
Gecode::atmostOne
void atmostOne(Home home, const SetVarArgs &xa, unsigned int c)
Definition:
distinct.cpp:41
Gecode::IntSet
Integer sets.
Definition:
int.hh:174
Gecode::SRT_EQ
@ SRT_EQ
Equality ( )
Definition:
set.hh:644
Gecode::Iter::Ranges::Inter
Range iterator for computing intersection (binary)
Definition:
ranges-inter.hpp:44
Gecode::SetVar
Set variables
Definition:
set.hh:127
Test::Set::SetTest
Base class for tests with set constraints
Definition:
set.hh:273
Test::Set::Distinct::_atmostone
AtmostOne _atmostone("Distinct::AtmostOne")
Gecode::rel
void rel(Home home, FloatVar x0, FloatRelType frt, FloatVal n)
Propagates .
Definition:
rel.cpp:43
Gecode::Set::Rel::Distinct
Propagator for negated equality
Definition:
rel.hh:267
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
Test::Int::Basic::i
Gecode::IntArgs i({1, 2, 3, 4})
Test::Set::Distinct::AtmostOne::AtmostOne
AtmostOne(const char *t)
Create and register test.
Definition:
distinct.cpp:56