main page
modules
namespaces
classes
files
Gecode home
Generated on Mon Feb 8 2021 00:00:00 for Gecode by
doxygen
1.8.20
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
* This file is part of Gecode, the generic constraint
10
* development environment:
11
* http://www.gecode.org
12
*
13
* Permission is hereby granted, free of charge, to any person obtaining
14
* a copy of this software and associated documentation files (the
15
* "Software"), to deal in the Software without restriction, including
16
* without limitation the rights to use, copy, modify, merge, publish,
17
* distribute, sublicense, and/or sell copies of the Software, and to
18
* permit persons to whom the Software is furnished to do so, subject to
19
* the following conditions:
20
*
21
* The above copyright notice and this permission notice shall be
22
* included in all copies or substantial portions of the Software.
23
*
24
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
29
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31
*
32
*/
33
34
#include "
test/int.hh
"
35
36
#include <
gecode/minimodel.hh
>
37
38
namespace
Test
{
namespace
Int {
39
41
namespace
MiniModel {
42
48
class
IntLex
:
public
Test
{
50
protected
:
52
Gecode::IntRelType
irt
;
53
public
:
55
IntLex
(
Gecode::IntRelType
irt0)
56
:
Test
(
"MiniModel::Lex::Int::"
+
str
(irt0),6,-2,2),
irt
(irt0) {}
58
virtual
bool
solution
(
const
Assignment
&
x
)
const
{
59
int
n
=
x
.size() >> 1;
60
for
(
int
i
=0;
i
<
n
;
i
++)
61
if
(
x
[
i
] !=
x
[
n
+
i
])
62
return
cmp
(
x
[
i
],
irt
,
x
[
n
+
i
]);
63
return
((
irt
==
Gecode::IRT_LQ
) || (
irt
==
Gecode::IRT_GQ
) ||
64
(
irt
==
Gecode::IRT_EQ
));
65
GECODE_NEVER
;
66
return
false
;
67
}
69
virtual
void
post
(
Gecode::Space
& home,
Gecode::IntVarArray
&
x
) {
70
using namespace
Gecode
;
71
int
n
=
x
.size() >> 1;
72
IntVarArgs
y
(
n
);
IntVarArgs
z
(
n
);
73
for
(
int
i
=0;
i
<
n
;
i
++) {
74
y
[
i
]=
x
[
i
];
z
[
i
]=
x
[
n
+
i
];
75
}
76
lex
(home,
y
,
irt
,
z
);
77
}
78
};
79
81
class
BoolLex
:
public
Test
{
82
protected
:
84
Gecode::IntRelType
irt
;
85
public
:
87
BoolLex
(
Gecode::IntRelType
irt0)
88
:
Test
(
"MiniModel::Lex::Bool::"
+
str
(irt0),10,0,1),
irt
(irt0) {}
90
virtual
bool
solution
(
const
Assignment
&
x
)
const
{
91
int
n
=
x
.size() >> 1;
92
for
(
int
i
=0;
i
<
n
;
i
++)
93
if
(
x
[
i
] !=
x
[
n
+
i
])
94
return
cmp
(
x
[
i
],
irt
,
x
[
n
+
i
]);
95
return
((
irt
==
Gecode::IRT_LQ
) || (
irt
==
Gecode::IRT_GQ
) ||
96
(
irt
==
Gecode::IRT_EQ
));
97
GECODE_NEVER
;
98
return
false
;
99
}
101
virtual
void
post
(
Gecode::Space
& home,
Gecode::IntVarArray
&
x
) {
102
using namespace
Gecode
;
103
int
n
=
x
.size() >> 1;
104
BoolVarArgs
y
(
n
);
BoolVarArgs
z
(
n
);
105
for
(
int
i
=0;
i
<
n
;
i
++) {
106
y
[
i
]=
channel
(home,
x
[
i
]);
z
[
i
]=
channel
(home,
x
[
n
+
i
]);
107
}
108
lex
(home,
y
,
irt
,
z
);
109
}
110
};
111
113
class
Create
{
114
public
:
116
Create
(
void
) {
117
using namespace
Gecode
;
118
for
(
IntRelTypes
irts; irts(); ++irts) {
119
(void)
new
IntLex
(irts.irt());
120
(void)
new
BoolLex
(irts.irt());
121
}
122
}
123
};
124
125
Create
c
;
127
128
}
129
130
}}
131
132
// STATISTICS: test-minimodel
Gecode::IntRelType
IntRelType
Relation types for integers.
Definition:
int.hh:925
Test::Int::IntRelTypes
Iterator for integer relation types.
Definition:
int.hh:368
Gecode::y
Post propagator for SetVar SetOpType SetVar y
Definition:
set.hh:767
minimodel.hh
Gecode::IRT_GQ
@ IRT_GQ
Greater or equal ( )
Definition:
int.hh:930
Gecode::IntVarArgs
Passing integer variables.
Definition:
int.hh:656
Test::Int::MiniModel::IntLex::IntLex
IntLex(Gecode::IntRelType irt0)
Create and register test.
Definition:
mm-rel.cpp:55
Gecode::z
Post propagator for SetVar SetOpType SetVar SetRelType SetVar z
Definition:
set.hh:767
Gecode::Space
Computation spaces.
Definition:
core.hpp:1742
int.hh
Gecode::IntVarArray
Integer variable array.
Definition:
int.hh:763
Test::Int::Test::cmp
static bool cmp(T x, Gecode::IntRelType r, T y)
Compare x and y with respect to r.
Definition:
int.hpp:285
Gecode
Gecode toplevel namespace
x
Node * x
Pointer to corresponding Boolean expression node.
Definition:
bool-expr.cpp:249
Gecode::BoolVarArgs
Passing Boolean variables.
Definition:
int.hh:712
Test::Int::MiniModel::IntLex::irt
Gecode::IntRelType irt
Integer relation type to propagate.
Definition:
mm-rel.cpp:52
Test::Int::MiniModel::IntLex::solution
virtual bool solution(const Assignment &x) const
Test whether x is solution
Definition:
mm-rel.cpp:58
GECODE_NEVER
#define GECODE_NEVER
Assert that this command is never executed.
Definition:
macros.hpp:56
Test::Int::MiniModel::BoolLex
Test for relation between arrays of Boolean variables
Definition:
mm-rel.cpp:81
Test::Int::Assignment
Base class for assignments
Definition:
int.hh:59
Gecode::lex
void lex(Home home, const IntVarArgs &x, IntRelType r, const IntVarArgs &y, IntPropLevel ipl)
Post lexical order between x and y.
Definition:
aliases.hpp:132
Test::Int::MiniModel::BoolLex::irt
Gecode::IntRelType irt
Integer relation type to propagate.
Definition:
mm-rel.cpp:84
Test::Int::MiniModel::BoolLex::solution
virtual bool solution(const Assignment &x) const
Test whether x is solution
Definition:
mm-rel.cpp:90
Gecode::channel
void channel(Home home, FloatVar x0, IntVar x1)
Post propagator for channeling a float and an integer variable .
Definition:
channel.cpp:41
Test::Int::MiniModel::Create::Create
Create(void)
Perform creation and registration.
Definition:
mm-rel.cpp:116
Test::Int::MiniModel::Create
Help class to create and register tests.
Definition:
mm-rel.cpp:113
Test::Int::MiniModel::IntLex
Test for relation between arrays of integer variables
Definition:
mm-rel.cpp:49
Test
General test support.
Definition:
afc.cpp:39
Test::Int::MiniModel::BoolLex::BoolLex
BoolLex(Gecode::IntRelType irt0)
Create and register test.
Definition:
mm-rel.cpp:87
Gecode::IRT_EQ
@ IRT_EQ
Equality ( )
Definition:
int.hh:926
Test::Int::MiniModel::c
Create c
Definition:
mm-rel.cpp:125
n
int n
Number of negative literals for node type.
Definition:
bool-expr.cpp:234
Test::Int::Basic::i
Gecode::IntArgs i({1, 2, 3, 4})
Test::Int::MiniModel::BoolLex::post
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
Definition:
mm-rel.cpp:101
Test::Int::MiniModel::IntLex::post
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
Definition:
mm-rel.cpp:69
Gecode::IRT_LQ
@ IRT_LQ
Less or equal ( )
Definition:
int.hh:928
Test::Int::Test::str
static std::string str(Gecode::IntPropLevel ipl)
Map integer propagation level to string.
Definition:
int.hpp:209