main page
modules
namespaces
classes
files
Gecode home
Generated on Tue Mar 5 2013 22:37:31 for Gecode by
doxygen
1.8.3.1
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
* 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 <
gecode/kernel.hh
>
39
#include <
gecode/int.hh
>
40
41
#include "
test/test.hh
"
42
43
namespace
Test {
44
46
class
AFC
:
public
Test::Base
{
47
protected
:
49
class
TestSpace
:
public
Gecode::Space
{
50
protected
:
52
Gecode::IntVar
x
,
y
;
53
public
:
55
TestSpace
(
void
) :
x
(*this,0,10),
y
(*this,0,10) {}
57
TestSpace
(
bool
share,
TestSpace
& s) :
Space
(share,s) {
58
x
.
update
(*
this
,share,s.
x
);
59
y
.
update
(*
this
,share,s.
y
);
60
}
62
void
post
(
void
) {
63
Gecode::rel
(*
this
,
x
,
Gecode::IRT_LE
,
y
);
64
}
66
virtual
Space
*
copy
(
bool
share) {
67
return
new
TestSpace
(share,*
this
);
68
}
69
};
71
static
const
int
n_ops
= 8 * 1024;
73
static
const
int
n
= 16;
75
int
space
(
TestSpace
* s[]) {
76
int
i
=
rand
(
n
);
77
while
(s[i] == NULL)
78
i = (i+1) %
n
;
79
return
i
;
80
}
82
int
index
(
void
) {
83
return
rand
(
n
);
84
}
85
public
:
87
AFC
(
void
) : Test::
Base
(
"AFC"
) {}
89
bool
run
(
void
) {
90
// Array of spaces for tests
91
TestSpace
* s[
n
];
92
// How many spaces exist in s
93
int
n_s = 1;
94
95
for
(
int
i
=
n
;
i
--; )
96
s[
i
] = NULL;
97
s[0] =
new
TestSpace
;
98
99
for
(
int
o=
n_ops
; o--; )
100
switch
(
rand
(3)) {
101
case
0:
102
// clone space
103
{
104
int
i
=
index
();
105
if
((s[i] != NULL)) {
106
if
(n_s > 1) {
107
delete
s[
i
]; s[
i
]=NULL; n_s--;
108
}
else
{
109
break
;
110
}
111
}
112
int
j =
space
(s);
113
(void) s[j]->status();
114
s[
i
] =
static_cast<
TestSpace
*
>
(s[j]->
clone
());
115
n_s++;
116
}
117
break
;
118
case
1:
119
// delete space
120
if
(n_s > 1) {
121
int
i
=
space
(s);
122
delete
s[
i
]; s[
i
]=NULL; n_s--;
123
}
124
break
;
125
case
2:
126
// post propagator
127
s[
space
(s)]->
post
();
128
break
;
129
default
:
130
GECODE_NEVER
;
131
}
132
// Delete all remaining spaces
133
for
(
int
i
=
n
;
i
--; )
134
delete
s[
i
];
135
return
true
;
136
}
137
};
138
139
AFC
afc
;
140
141
}
142
143
// STATISTICS: test-kernel