main page
modules
namespaces
classes
files
Gecode home
Generated on Wed Sep 5 2012 18:52:08 for Gecode by
doxygen
1.8.1.1
test
int
mm-rel.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, 2008
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/int.hh
"
39
40
#include <
gecode/minimodel.hh
>
41
42
namespace
Test {
namespace
Int {
43
45
namespace
MiniModel {
46
52
53
class
IntLex
:
public
Test
{
54
protected
:
56
Gecode::IntRelType
irt
;
57
public
:
59
IntLex
(
Gecode::IntRelType
irt0)
60
:
Test
(
"MiniModel::Lex::Int::"
+
str
(irt0),6,-2,2),
irt
(irt0) {}
62
virtual
bool
solution
(
const
Assignment
& x)
const
{
63
int
n=x.
size
() >> 1;
64
for
(
int
i
=0;
i
<n;
i
++)
65
if
(x[
i
] != x[n+
i
])
66
return
cmp
(x[
i
],
irt
,x[n+i]);
67
return
((
irt
==
Gecode::IRT_LQ
) || (
irt
==
Gecode::IRT_GQ
) ||
68
(
irt
==
Gecode::IRT_EQ
));
69
GECODE_NEVER
;
70
return
false
;
71
}
73
virtual
void
post
(
Gecode::Space
& home,
Gecode::IntVarArray
& x) {
74
using namespace
Gecode;
75
int
n=x.
size
() >> 1;
76
IntVarArgs
y(n);
IntVarArgs
z(n);
77
for
(
int
i
=0;
i
<n;
i
++) {
78
y[
i
]=x[
i
]; z[
i
]=x[n+
i
];
79
}
80
lex
(home, y,
irt
, z);
81
}
82
};
83
85
class
BoolLex
:
public
Test
{
86
protected
:
88
Gecode::IntRelType
irt
;
89
public
:
91
BoolLex
(
Gecode::IntRelType
irt0)
92
:
Test
(
"MiniModel::Lex::Bool::"
+
str
(irt0),10,0,1),
irt
(irt0) {}
94
virtual
bool
solution
(
const
Assignment
& x)
const
{
95
int
n=x.
size
() >> 1;
96
for
(
int
i
=0;
i
<n;
i
++)
97
if
(x[
i
] != x[n+
i
])
98
return
cmp
(x[
i
],
irt
,x[n+i]);
99
return
((
irt
==
Gecode::IRT_LQ
) || (
irt
==
Gecode::IRT_GQ
) ||
100
(
irt
==
Gecode::IRT_EQ
));
101
GECODE_NEVER
;
102
return
false
;
103
}
105
virtual
void
post
(
Gecode::Space
& home,
Gecode::IntVarArray
& x) {
106
using namespace
Gecode;
107
int
n=x.
size
() >> 1;
108
BoolVarArgs
y(n);
BoolVarArgs
z(n);
109
for
(
int
i
=0;
i
<n;
i
++) {
110
y[
i
]=
channel
(home,x[
i
]); z[
i
]=
channel
(home,x[n+i]);
111
}
112
lex
(home, y,
irt
, z);
113
}
114
};
115
117
class
Create
{
118
public
:
120
Create
(
void
) {
121
using namespace
Gecode;
122
for
(
IntRelTypes
irts; irts(); ++irts) {
123
(void)
new
IntLex
(irts.irt());
124
(void)
new
BoolLex
(irts.irt());
125
}
126
}
127
};
128
129
Create
c
;
131
132
}
133
134
}}
135
136
// STATISTICS: test-minimodel