main page
modules
namespaces
classes
files
Gecode home
Generated on Sat Nov 9 2013 19:18:31 for Gecode by
doxygen
1.8.4
test
brancher-handle.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, 2013
8
*
9
* Last modified:
10
* $Date: 2013-02-25 21:43:24 +0100 (Mon, 25 Feb 2013) $ by $Author: schulte $
11
* $Revision: 13406 $
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
BrancherHandle
:
public
Test::Base
{
47
protected
:
49
class
TestSpace
:
public
Gecode::Space
{
50
protected
:
52
Gecode::IntVarArray
x
;
53
public
:
55
TestSpace
(
void
) :
x
(*this,2,0,10) {}
57
TestSpace
(
bool
share,
TestSpace
& s) :
Space
(share,s) {
58
x
.
update
(*
this
,share,s.
x
);
59
}
61
Gecode::BrancherHandle
post
(
void
) {
62
using namespace
Gecode;
63
return
Gecode::branch
(*
this
,
x
,
INT_VAR_NONE
(),
INT_VAL_MIN
());
64
}
66
virtual
Space
*
copy
(
bool
share) {
67
return
new
TestSpace
(share,*
this
);
68
}
69
};
71
static
const
int
n_b
= 1024;
73
int
index
(
void
) {
74
// return rand(n);
75
return
4;
76
}
77
public
:
79
BrancherHandle
(
void
) : Test::
Base
(
"BrancherHandle"
) {}
81
bool
run
(
void
) {
82
using namespace
Gecode;
83
TestSpace
* s =
new
TestSpace
;
84
85
// Create and immediately delete
86
for
(
int
i
=0;
i
<
n_b
;
i
++) {
87
Gecode::BrancherHandle
b
(s->post());
88
if
(!
b
(*s))
return
false
;
89
b
.kill(*s);
90
if
(
b
(*s))
return
false
;
91
}
92
93
if
(s->status() !=
SS_SOLVED
)
94
return
false
;
95
96
// Array of handles for tests
97
Gecode::BrancherHandle
bs[
n_b
];
98
99
// Create and delete
100
for
(
int
i
=0;
i
<
n_b
;
i
++) {
101
Gecode::BrancherHandle
b
(s->post());
102
if
(!
b
(*s))
return
false
;
103
bs[
i
] =
b
;
104
}
105
for
(
int
i
=0;
i
<
n_b
;
i
++) {
106
bs[
i
].kill(*s);
107
if
(bs[
i
](*s))
return
false
;
108
}
109
if
(s->status() !=
SS_SOLVED
)
110
return
false
;
111
112
// Create and delete in inverse order
113
for
(
int
i
=0;
i
<
n_b
;
i
++) {
114
Gecode::BrancherHandle
b
(s->post());
115
if
(!
b
(*s))
return
false
;
116
bs[
i
] =
b
;
117
}
118
for
(
int
i
=
n_b
;
i
--; ) {
119
bs[
i
].kill(*s);
120
if
(bs[
i
](*s))
return
false
;
121
}
122
if
(s->status() !=
SS_SOLVED
)
123
return
false
;
124
125
// Create and delete randomly
126
for
(
int
i
=0;
i
<
n_b
;
i
++) {
127
Gecode::BrancherHandle
b
(s->post());
128
if
(!
b
(*s))
return
false
;
129
bs[
i
] =
b
;
130
}
131
int
a
=
n_b
;
132
while
(
a
> 0) {
133
int
i
=
rand
(
n_b
);
134
if
(bs[i](*s)) {
135
bs[
i
].kill(*s);
a
--;
136
}
137
}
138
if
(s->status() !=
SS_SOLVED
)
139
return
false
;
140
141
return
true
;
142
}
143
};
144
145
BrancherHandle
bh
;
146
147
}
148
149
// STATISTICS: test-core