main page
modules
namespaces
classes
files
Gecode home
Generated on Mon Jul 27 2020 00:00:00 for Gecode by
doxygen
1.8.18
test
afc.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, 2009
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/kernel.hh
>
35
#include <
gecode/int.hh
>
36
37
#include "
test/test.hh
"
38
39
namespace
Test
{
40
42
class
AFC
:
public
Test::Base
{
43
protected
:
45
class
TestSpace
:
public
Gecode::Space
{
46
protected
:
48
Gecode::IntVar
x
,
y
;
49
public
:
51
TestSpace
(
void
) :
x
(*this,0,10),
y
(*this,0,10) {}
53
TestSpace
(
TestSpace
& s) :
Space
(s) {
54
x
.
update
(*
this
,s.
x
);
55
y
.
update
(*
this
,s.
y
);
56
}
58
void
post
(
void
) {
59
Gecode::rel
(*
this
,
x
,
Gecode::IRT_LE
,
y
);
60
}
62
virtual
Space
*
copy
(
void
) {
63
return
new
TestSpace
(*
this
);
64
}
65
};
67
static
const
int
n_ops
= 8 * 1024;
69
static
const
int
n
= 16;
71
int
space
(
TestSpace
* s[]) {
72
int
i
=
rand
(
n
);
73
while
(s[
i
] == NULL)
74
i
= (
i
+1) %
n
;
75
return
i
;
76
}
78
int
index
(
void
) {
79
return
rand
(
n
);
80
}
81
public
:
83
AFC
(
void
) :
Test
::
Base
(
"AFC"
) {}
85
bool
run
(
void
) {
86
// Array of spaces for tests
87
TestSpace
* s[
n
];
88
// How many spaces exist in s
89
int
n_s = 1;
90
91
for
(
int
i
=
n
;
i
--; )
92
s[
i
] = NULL;
93
s[0] =
new
TestSpace
;
94
95
for
(
int
o=
n_ops
; o--; )
96
switch
(
rand
(3)) {
97
case
0:
98
// clone space
99
{
100
int
i
=
index
();
101
if
((s[
i
] != NULL)) {
102
if
(n_s > 1) {
103
delete
s[
i
]; s[
i
]=NULL; n_s--;
104
}
else
{
105
break
;
106
}
107
}
108
int
j =
space
(s);
109
(void) s[j]->status();
110
s[
i
] =
static_cast<
TestSpace
*
>
(s[j]->
clone
());
111
n_s++;
112
}
113
break
;
114
case
1:
115
// delete space
116
if
(n_s > 1) {
117
int
i
=
space
(s);
118
delete
s[
i
]; s[
i
]=NULL; n_s--;
119
}
120
break
;
121
case
2:
122
// post propagator
123
s[
space
(s)]->
post
();
124
break
;
125
default
:
126
GECODE_NEVER
;
127
}
128
// Delete all remaining spaces
129
for
(
int
i
=
n
;
i
--; )
130
delete
s[
i
];
131
return
true
;
132
}
133
};
134
135
AFC
afc
;
136
137
}
138
139
// STATISTICS: test-core
Test::AFC::TestSpace::copy
virtual Space * copy(void)
Copy during cloning.
Definition:
afc.cpp:62
Test::AFC::TestSpace::x
Gecode::IntVar x
Two integer variables.
Definition:
afc.cpp:48
Test::AFC::space
int space(TestSpace *s[])
Return random index of non-null space.
Definition:
afc.cpp:71
kernel.hh
Test::AFC
Test for AFC infrastructure
Definition:
afc.cpp:42
Test::AFC::run
bool run(void)
Perform actual tests.
Definition:
afc.cpp:85
Test::AFC::index
int index(void)
Return random index.
Definition:
afc.cpp:78
int.hh
Gecode::IRT_LE
@ IRT_LE
Less ( )
Definition:
int.hh:929
Test::AFC::TestSpace::TestSpace
TestSpace(void)
Constructor for creation.
Definition:
afc.cpp:51
Gecode::Space
Computation spaces.
Definition:
core.hpp:1742
Test::Base::rand
static Gecode::Support::RandomGenerator rand
Random number generator.
Definition:
test.hh:134
Gecode::Space::clone
Space * clone(CloneStatistics &stat=unused_clone) const
Clone space.
Definition:
core.hpp:3224
Test::Base
Base class for all tests to be run
Definition:
test.hh:103
test.hh
Test::AFC::TestSpace::post
void post(void)
Post arbitrary propagator.
Definition:
afc.cpp:58
Test::AFC::AFC
AFC(void)
Initialize test.
Definition:
afc.cpp:83
Test::AFC::n_ops
static const int n_ops
How many test operations to be performed.
Definition:
afc.cpp:67
Gecode::IntVar
Integer variables.
Definition:
int.hh:371
Test::AFC::TestSpace::y
Gecode::IntVar y
Definition:
afc.cpp:48
GECODE_NEVER
#define GECODE_NEVER
Assert that this command is never executed.
Definition:
macros.hpp:56
Test::afc
AFC afc
Definition:
afc.cpp:135
Gecode::Space::Space
Space(void)
Default constructor.
Definition:
core.cpp:115
Gecode::rel
void rel(Home home, FloatVar x0, FloatRelType frt, FloatVal n)
Propagates .
Definition:
rel.cpp:43
Test::AFC::TestSpace
Test space.
Definition:
afc.cpp:45
Test
General test support.
Definition:
afc.cpp:39
Gecode::VarImpVar::update
void update(Space &home, VarImpVar< VarImp > &y)
Update this variable to be a clone of variable y.
Definition:
var.hpp:116
Test::AFC::n
static const int n
How many spaces to maintain.
Definition:
afc.cpp:69
Test::AFC::TestSpace::TestSpace
TestSpace(TestSpace &s)
Constructor for cloning s.
Definition:
afc.cpp:53
Test::Int::Basic::i
Gecode::IntArgs i({1, 2, 3, 4})