main page
modules
namespaces
classes
files
Gecode home
Generated on Thu Mar 7 2013 10:21:32 for Gecode by
doxygen
1.8.3.1
test
set
precede.cpp
Go to the documentation of this file.
1
/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2
/*
3
* Main authors:
4
* Christopher Mears <Chris.Mears@monash.edu>
5
*
6
* Contributing authors:
7
* Christian Schulte <schulte@gecode.org>
8
* Guido Tack <tack@gecode.org>
9
*
10
* Copyright:
11
* Christopher Mears, 2011
12
* Christian Schulte, 2011
13
* Guido Tack, 2011
14
*
15
* Last modified:
16
* $Date: 2011-07-12 20:49:06 +1000 (Tue, 12 Jul 2011) $ by $Author: tack $
17
* $Revision: 12172 $
18
*
19
* This file is part of Gecode, the generic constraint
20
* development environment:
21
* http://www.gecode.org
22
*
23
* Permission is hereby granted, free of charge, to any person obtaining
24
* a copy of this software and associated documentation files (the
25
* "Software"), to deal in the Software without restriction, including
26
* without limitation the rights to use, copy, modify, merge, publish,
27
* distribute, sublicense, and/or sell copies of the Software, and to
28
* permit persons to whom the Software is furnished to do so, subject to
29
* the following conditions:
30
*
31
* The above copyright notice and this permission notice shall be
32
* included in all copies or substantial portions of the Software.
33
*
34
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
35
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
36
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
37
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
38
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
39
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
40
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
41
*
42
*/
43
44
#include "
test/set.hh
"
45
46
using namespace
Gecode;
47
48
namespace
Test {
namespace
Set {
49
51
namespace
Precede {
52
53
static
IntSet
ds(-1,3);
54
56
class
Single
:
public
SetTest
{
57
private
:
59
int
s, t;
60
62
bool
in(
int
i
,
int
x)
const
{
63
CountableSetRanges
xr(ds,x);
64
Iter::Ranges::Singleton
ir(i,i);
65
return
Iter::Ranges::subset
(ir,xr);
66
}
67
68
public
:
70
Single
(
int
s0,
int
t0)
71
:
SetTest
(
"Precede::Single::"
+str(s0)+
"<"
+str(t0),4,ds,false),
72
s(s0), t(t0) {}
74
virtual
bool
solution
(
const
SetAssignment
& x)
const
{
75
int
n = x.
size
();
76
for
(
int
i = 0 ; i < n ; i++) {
77
if
(!in(s,x[i]) && in(t,x[i]))
78
return
false
;
79
if
(in(s,x[i]) && !in(t,x[i]))
80
return
true
;
81
}
82
return
true
;
83
}
85
virtual
void
post
(
Gecode::Space
& home,
Gecode::SetVarArray
& x,
86
Gecode::IntVarArray
&) {
87
Gecode::precede
(home, x, s, t);
88
}
89
};
90
92
class
Multi
:
public
SetTest
{
93
private
:
95
Gecode::IntArgs
c
;
96
98
bool
in(
int
i
,
int
x)
const
{
99
CountableSetRanges
xr(ds,x);
100
Iter::Ranges::Singleton
ir(i,i);
101
return
Iter::Ranges::subset
(ir,xr);
102
}
103
public
:
105
Multi
(
const
Gecode::IntArgs
& c0)
106
:
SetTest
(
"Precede::Multi::"
+str(c0),4,ds,false),
c
(c0) {}
108
virtual
bool
solution
(
const
SetAssignment
& x)
const
{
109
for
(
int
j=0; j<
c
.
size
()-1; j++)
110
for
(
int
i=0; i<x.
size
(); i++) {
111
if
(!in(
c
[j],x[i]) && in(
c
[j+1],x[i]))
112
return
false
;
113
if
(in(
c
[j],x[i]) && !in(
c
[j+1],x[i]))
114
break
;
115
}
116
return
true
;
117
}
119
virtual
void
post
(
Gecode::Space
& home,
Gecode::SetVarArray
& x,
120
Gecode::IntVarArray
&) {
121
Gecode::precede
(home, x,
c
);
122
}
123
};
124
125
Single
_a
(2, 3);
126
Single
_b
(0, 3);
127
128
Multi
_c
(
Gecode::IntArgs
(3, 1,2,3));
129
Multi
_d
(
Gecode::IntArgs
(3, 3,2,1));
130
Multi
_e
(
Gecode::IntArgs
(4, 4,2,3,1));
131
132
}
133
134
}}
135
136
// STATISTICS: test-set