main page
modules
namespaces
classes
files
Gecode home
Generated on Tue Jan 28 2020 00:00:00 for Gecode by
doxygen
1.8.17
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 12:35:31 +0200 (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
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
Gecode::IntRelType
IntRelType
Relation types for integers.
Definition:
int.hh:906
Test::Int::IntRelTypes
Iterator for integer relation types.
Definition:
int.hh:370
Gecode::y
Post propagator for SetVar SetOpType SetVar y
Definition:
set.hh:784
minimodel.hh
Gecode::IRT_GQ
@ IRT_GQ
Greater or equal ( )
Definition:
int.hh:911
Gecode::IntVarArgs
Passing integer variables.
Definition:
int.hh:639
Test::Int::MiniModel::IntLex::IntLex
IntLex(Gecode::IntRelType irt0)
Create and register test.
Definition:
mm-rel.cpp:59
Gecode::z
Post propagator for SetVar SetOpType SetVar SetRelType SetVar z
Definition:
set.hh:784
Test::Int::Basic::i
Gecode::IntArgs i(4, 1, 2, 3, 4)
Gecode::Space
Computation spaces.
Definition:
core.hpp:1748
int.hh
Gecode::IntVarArray
Integer variable array.
Definition:
int.hh:744
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:279
Gecode
Gecode toplevel namespace
x
Node * x
Pointer to corresponding Boolean expression node.
Definition:
bool-expr.cpp:253
Gecode::BoolVarArgs
Passing Boolean variables.
Definition:
int.hh:693
Test::Int::MiniModel::IntLex::irt
Gecode::IntRelType irt
Integer relation type to propagate.
Definition:
mm-rel.cpp:56
Test::Int::MiniModel::IntLex::solution
virtual bool solution(const Assignment &x) const
Test whether x is solution
Definition:
mm-rel.cpp:62
GECODE_NEVER
#define GECODE_NEVER
Assert that this command is never executed.
Definition:
macros.hpp:60
Test::Int::MiniModel::BoolLex
Test for relation between arrays of Boolean variables
Definition:
mm-rel.cpp:85
Test::Int::Assignment
Base class for assignments
Definition:
int.hh:63
Gecode::lex
void lex(Home home, const IntVarArgs &x, IntRelType r, const IntVarArgs &y, IntPropLevel ipl=IPL_DEF)
Post lexical order between x and y.
Definition:
minimodel.hh:1854
Test::Int::MiniModel::BoolLex::irt
Gecode::IntRelType irt
Integer relation type to propagate.
Definition:
mm-rel.cpp:88
Test::Int::MiniModel::BoolLex::solution
virtual bool solution(const Assignment &x) const
Test whether x is solution
Definition:
mm-rel.cpp:94
Gecode::channel
void channel(Home home, FloatVar x0, IntVar x1)
Post propagator for channeling a float and an integer variable .
Definition:
channel.cpp:45
Test::Int::MiniModel::Create::Create
Create(void)
Perform creation and registration.
Definition:
mm-rel.cpp:120
Test::Int::MiniModel::Create
Help class to create and register tests.
Definition:
mm-rel.cpp:117
Test::Int::MiniModel::IntLex
Test for relation between arrays of integer variables
Definition:
mm-rel.cpp:53
Test
General test support.
Definition:
afc.cpp:43
Test::Int::MiniModel::BoolLex::BoolLex
BoolLex(Gecode::IntRelType irt0)
Create and register test.
Definition:
mm-rel.cpp:91
Gecode::IRT_EQ
@ IRT_EQ
Equality ( )
Definition:
int.hh:907
Test::Int::MiniModel::c
Create c
Definition:
mm-rel.cpp:129
n
int n
Number of negative literals for node type.
Definition:
bool-expr.cpp:238
Test::Int::MiniModel::BoolLex::post
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
Definition:
mm-rel.cpp:105
Test::Int::MiniModel::IntLex::post
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
Definition:
mm-rel.cpp:73
Gecode::IRT_LQ
@ IRT_LQ
Less or equal ( )
Definition:
int.hh:909
Test::Int::Test::str
static std::string str(Gecode::IntPropLevel ipl)
Map integer propagation level to string.
Definition:
int.hpp:212