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