main page
modules
namespaces
classes
files
Gecode home
Generated on Fri Aug 24 2012 04:52:08 for Gecode by
doxygen
1.8.1.2
test
int
channel.cpp
Go to the documentation of this file.
1
/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2
/*
3
* Main authors:
4
* Christian Schulte <schulte@gecode.org>
5
*
6
* Copyright:
7
* Christian Schulte, 2006
8
*
9
* Last modified:
10
* $Date: 2012-02-22 16:04:20 +1100 (Wed, 22 Feb 2012) $ by $Author: tack $
11
* $Revision: 12537 $
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/int.hh
"
39
40
#include <
gecode/minimodel.hh
>
41
42
namespace
Test {
namespace
Int {
43
45
namespace
Channel {
46
52
53
class
ChannelFull
:
public
Test
{
54
private
:
55
int
xoff;
//< Offset for the x variables
56
int
yoff;
//< Offset for the y variables
57
public
:
59
ChannelFull
(
int
xoff0,
int
yoff0,
Gecode::IntConLevel
icl
)
60
:
Test
(
"Channel::Full::"
+
str
(xoff0)+
"::"
+
str
(yoff0)+
"::"
+
str
(icl),
61
8,0,3,false,icl),
62
xoff(xoff0), yoff(yoff0) {
63
contest
=
CTL_NONE
;
64
}
66
virtual
bool
solution
(
const
Assignment
& x)
const
{
67
for
(
int
i
=0;
i
<4;
i
++)
68
if
(x[4+x[
i
]] !=
i
)
69
return
false
;
70
return
true
;
71
}
73
virtual
void
post
(
Gecode::Space
& home,
Gecode::IntVarArray
& x) {
74
using namespace
Gecode;
75
IntVarArgs
xa(4);
IntVarArgs
ya(4);
76
for
(
int
i
=4;
i
--; ) {
77
if
(xoff != 0) {
78
IntVar
xo(home, xoff, 3+xoff);
79
Gecode::rel
(home, x[
i
] == xo-xoff);
80
xa[
i
] = xo;
81
}
else
{
82
xa[
i
] = x[
i
];
83
}
84
if
(yoff != 0) {
85
IntVar
yo(home, yoff, 3+yoff);
86
Gecode::rel
(home, x[4+
i
] == yo-yoff);
87
ya[
i
] = yo;
88
}
else
{
89
ya[
i
] = x[4+
i
];
90
}
91
}
92
channel
(home, xa, xoff, ya, yoff,
icl
);
93
}
94
};
95
97
class
ChannelHalf
:
public
Test
{
98
public
:
100
ChannelHalf
(
Gecode::IntConLevel
icl
)
101
:
Test
(
"Channel::Half::"
+
str
(icl),6,0,5,false,icl) {
102
contest
=
CTL_NONE
;
103
}
105
virtual
bool
solution
(
const
Assignment
& x)
const
{
106
for
(
int
i
=0;
i
<6;
i
++)
107
for
(
int
j=
i
+1; j<6; j++)
108
if
(x[
i
] == x[j])
109
return
false
;
110
return
true
;
111
}
113
virtual
void
post
(
Gecode::Space
& home,
Gecode::IntVarArray
& x) {
114
using namespace
Gecode;
115
Gecode::IntVarArgs
y(home,6,
dom
);
116
for
(
int
i
=0;
i
<6;
i
++)
117
for
(
int
j=0; j<6; j++) {
118
Gecode::BoolVar
b
(home,0,1);
119
rel
(home, x[
i
],
Gecode::IRT_EQ
, j, b);
120
rel
(home, y[j],
Gecode::IRT_EQ
, i, b);
121
}
122
channel
(home, x, y,
icl
);
123
}
124
};
125
127
class
ChannelShared
:
public
Test
{
128
public
:
130
ChannelShared
(
Gecode::IntConLevel
icl
)
131
:
Test
(
"Channel::Shared::"
+
str
(icl),6,0,5,false,icl) {
132
contest
=
CTL_NONE
;
133
}
135
virtual
bool
solution
(
const
Assignment
& x)
const
{
136
for
(
int
i
=0;
i
<6;
i
++)
137
if
(x[x[
i
]] !=
i
)
138
return
false
;
139
return
true
;
140
}
142
virtual
void
post
(
Gecode::Space
& home,
Gecode::IntVarArray
& x) {
143
using namespace
Gecode;
144
channel
(home, x, x,
icl
);
145
}
146
};
147
149
class
ChannelLinkSingle
:
public
Test
{
150
public
:
152
ChannelLinkSingle
(
void
)
153
:
Test
(
"Channel::Bool::Single"
,2,-1,2) {
154
contest
=
CTL_NONE
;
155
}
157
virtual
bool
solution
(
const
Assignment
& x)
const
{
158
return
((x[0]==0) || (x[0]==1)) && (x[0]==x[1]);
159
}
161
virtual
void
post
(
Gecode::Space
& home,
Gecode::IntVarArray
& x) {
162
using namespace
Gecode;
163
Gecode::BoolVar
b
(home,0,1);
164
channel
(home, x[0], b);
165
channel
(home, x[1], b);
166
}
167
};
168
170
class
ChannelLinkMulti
:
public
Test
{
171
private
:
172
int
o;
173
public
:
175
ChannelLinkMulti
(
const
std::string& s,
int
min
,
int
max
,
int
o0)
176
:
Test
(
"Channel::Bool::Multi::"
+s,7,min,max), o(o0) {
177
}
179
virtual
bool
solution
(
const
Assignment
& x)
const
{
180
int
n = x.
size
()-1;
181
for
(
int
i
=n;
i
--; )
182
if
((x[
i
] != 0) && (x[
i
] != 1))
183
return
false
;
184
int
k=x[n]-o;
185
if
((k<0) || (k>=n))
186
return
false
;
187
for
(
int
i
=0;
i
<k;
i
++)
188
if
(x[
i
] != 0)
189
return
false
;
190
for
(
int
i
=k+1;
i
<n;
i
++)
191
if
(x[
i
] != 0)
192
return
false
;
193
return
x[k] == 1;
194
}
196
virtual
void
post
(
Gecode::Space
& home,
Gecode::IntVarArray
& x) {
197
using namespace
Gecode;
198
int
n=x.
size
()-1;
199
Gecode::BoolVarArgs
b
(n);
200
for
(
int
i
=n;
i
--; )
201
b[
i
]=
channel
(home,x[
i
]);
202
channel
(home, b, x[n], o);
203
}
204
};
205
206
207
208
ChannelFull
cfd
(0,0,
Gecode::ICL_DOM
);
209
ChannelFull
cfv
(0,0,
Gecode::ICL_VAL
);
210
211
ChannelFull
cfd11
(1,1,
Gecode::ICL_DOM
);
212
ChannelFull
cfv11
(1,1,
Gecode::ICL_VAL
);
213
214
ChannelFull
cfd35
(3,5,
Gecode::ICL_DOM
);
215
ChannelFull
cfv35
(3,5,
Gecode::ICL_VAL
);
216
217
ChannelHalf
chd
(
Gecode::ICL_DOM
);
218
ChannelHalf
chv
(
Gecode::ICL_VAL
);
219
220
ChannelShared
csd
(
Gecode::ICL_DOM
);
221
ChannelShared
csv
(
Gecode::ICL_VAL
);
222
223
ChannelLinkSingle
cls
;
224
225
ChannelLinkMulti
clma
(
"A"
, 0, 5, 0);
226
ChannelLinkMulti
clmb
(
"B"
, 1, 6, 1);
227
ChannelLinkMulti
clmc
(
"C"
,-1, 4,-1);
229
230
}
231
}}
232
233
// STATISTICS: test-int
234