main page
modules
namespaces
classes
files
Gecode home
Generated on Thu Mar 13 2014 04:39:30 for Gecode by
doxygen
1.8.1.2
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 20:35:31 +1000 (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