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
member.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, 2011
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 <
gecode/minimodel.hh
>
35
#include "
test/int.hh
"
36
37
namespace
Test
{
namespace
Int {
38
40
namespace
Member {
41
47
class
Int
:
public
Test
{
49
public
:
51
Int
(
int
n
) :
Test
(
"Member::Int::"
+
str
(
n
),
n
+1,0,
n
,true) {}
53
virtual
bool
solution
(
const
Assignment
&
x
)
const
{
54
int
n
=
x
.size() - 1;
55
for
(
int
i
=
n
;
i
--; )
56
if
(
x
[
i
] ==
x
[
n
])
57
return
true
;
58
return
false
;
59
}
61
virtual
void
post
(
Gecode::Space
& home,
Gecode::IntVarArray
&
x
) {
62
using namespace
Gecode
;
63
int
n
=
x
.size() - 1;
64
IntVarArgs
y
(
n
);
65
for
(
int
i
=
n
;
i
--; )
66
y
[
i
] =
x
[
i
];
67
member
(home,
y
,
x
[
n
]);
68
}
70
virtual
void
post
(
Gecode::Space
& home,
Gecode::IntVarArray
&
x
,
71
Gecode::Reify
r
) {
72
using namespace
Gecode
;
73
int
n
=
x
.size() - 1;
74
IntVarArgs
y
(
n
);
75
for
(
int
i
=
n
;
i
--; )
76
y
[
i
] =
x
[
i
];
77
member
(home,
y
,
x
[
n
],
r
);
78
}
79
};
80
82
class
Bool
:
public
Test
{
83
public
:
85
Bool
(
int
n
) :
Test
(
"Member::Bool::"
+
str
(
n
),
n
+1,0,1,true) {}
87
virtual
bool
solution
(
const
Assignment
&
x
)
const
{
88
int
n
=
x
.size() - 1;
89
for
(
int
i
=
n
;
i
--; )
90
if
(
x
[
i
] ==
x
[
n
])
91
return
true
;
92
return
false
;
93
}
95
virtual
void
post
(
Gecode::Space
& home,
Gecode::IntVarArray
&
x
) {
96
using namespace
Gecode
;
97
int
n
=
x
.size() - 1;
98
BoolVarArgs
y
(
n
);
99
for
(
int
i
=
n
;
i
--; )
100
y
[
i
] =
channel
(home,
x
[
i
]);
101
member
(home,
y
,
channel
(home,
x
[
n
]));
102
}
104
virtual
void
post
(
Gecode::Space
& home,
Gecode::IntVarArray
&
x
,
105
Gecode::Reify
r
) {
106
using namespace
Gecode
;
107
int
n
=
x
.size() - 1;
108
BoolVarArgs
y
(
n
);
109
for
(
int
i
=
n
;
i
--; )
110
y
[
i
] =
channel
(home,
x
[
i
]);
111
member
(home,
y
,
channel
(home,
x
[
n
]),
r
);
112
}
113
};
114
116
class
Create
{
117
public
:
119
Create
(
void
) {
120
for
(
int
i
=0;
i
<=4;
i
++) {
121
(void)
new
Int
(
i
);
122
(void)
new
Bool
(
i
);
123
}
124
}
125
};
126
127
Create
c
;
129
130
}
131
}}
132
133
// STATISTICS: test-int
134
Test::Int::Member::Bool::post
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
Definition:
member.cpp:95
Test::r
Region r
Definition:
region.cpp:65
Gecode::y
Post propagator for SetVar SetOpType SetVar y
Definition:
set.hh:767
minimodel.hh
Test::Int::Member::Int::post
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x, Gecode::Reify r)
Post reified constraint on x for r.
Definition:
member.cpp:70
Gecode::IntVarArgs
Passing integer variables.
Definition:
int.hh:656
Gecode::Space
Computation spaces.
Definition:
core.hpp:1742
Test::Int::Member::Bool
Test membership for Boolean variables
Definition:
member.cpp:82
int.hh
Gecode::IntVarArray
Integer variable array.
Definition:
int.hh:763
Test::Int::Member::Int::solution
virtual bool solution(const Assignment &x) const
Test whether x is solution
Definition:
member.cpp:53
Gecode
Gecode toplevel namespace
Test::Int::Member::Create::Create
Create(void)
Perform creation and registration.
Definition:
member.cpp:119
Test::Int::Member::Int::post
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x)
Post constraint on x.
Definition:
member.cpp:61
x
Node * x
Pointer to corresponding Boolean expression node.
Definition:
bool-expr.cpp:249
Gecode::Reify
Reification specification.
Definition:
int.hh:876
Gecode::BoolVarArgs
Passing Boolean variables.
Definition:
int.hh:712
Test::Int::Member::c
Create c
Definition:
member.cpp:127
Test::Int::Member::Create
Help class to create and register tests.
Definition:
member.cpp:116
Test::Int::Assignment
Base class for assignments
Definition:
int.hh:59
Test::Int::Member::Bool::solution
virtual bool solution(const Assignment &x) const
Test whether x is solution
Definition:
member.cpp:87
Gecode::member
void member(Home home, const BoolVarArgs &x, BoolVar y, Reify r, IntPropLevel)
Post domain consistent propagator for .
Definition:
member.cpp:84
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::Member::Bool::Bool
Bool(int n)
Create and register test.
Definition:
member.cpp:85
Test::Int::Member::Int
Test membership for integer variables
Definition:
member.cpp:48
Test
General test support.
Definition:
afc.cpp:39
Test::Int::Member::Bool::post
virtual void post(Gecode::Space &home, Gecode::IntVarArray &x, Gecode::Reify r)
Post reified constraint on x for r.
Definition:
member.cpp:104
n
int n
Number of negative literals for node type.
Definition:
bool-expr.cpp:234
Test::Int::Member::Int::Int
Int(int n)
Create and register test.
Definition:
member.cpp:51
Test::Int::Basic::i
Gecode::IntArgs i({1, 2, 3, 4})
Test::Int::Test::str
static std::string str(Gecode::IntPropLevel ipl)
Map integer propagation level to string.
Definition:
int.hpp:209