main page
modules
namespaces
classes
files
Gecode home
Generated on Tue Oct 22 2013 00:49:07 for Gecode by
doxygen
1.8.4
gecode
search
meta
rbs.cpp
Go to the documentation of this file.
1
/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2
/*
3
* Main authors:
4
* Guido Tack <tack@gecode.org>
5
*
6
* Copyright:
7
* Guido Tack, 2012
8
*
9
* Last modified:
10
* $Date: 2013-07-11 12:30:18 +0200 (Thu, 11 Jul 2013) $ by $Author: schulte $
11
* $Revision: 13840 $
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
39
#include <
gecode/search/meta/rbs.hh
>
40
41
namespace
Gecode {
namespace
Search {
namespace
Meta {
42
43
Space*
44
RBS::next
(
void
) {
45
while
(
true
) {
46
Space
*
n
= e->
next
();
47
unsigned
long
int
i
= stop->m_stat.
restart
;
48
if
(n != NULL) {
49
NoGoods
& ng = e->
nogoods
();
50
ng.
ng
(0);
51
master->
constrain
(*n);
52
master->
master
(i,n,ng);
53
stop->m_stat.
nogood
+= ng.
ng
();
54
if
(master->
status
(stop->m_stat) ==
SS_FAILED
) {
55
delete
master;
56
master = NULL;
57
e->
reset
(NULL);
58
}
else
{
59
Space
* slave = master;
60
master = master->
clone
(shared);
61
slave->
slave
(i,n);
62
e->
reset
(slave);
63
}
64
return
n
;
65
}
else
if
(e->
stopped
() && stop->
enginestopped
()) {
66
NoGoods
& ng = e->
nogoods
();
67
ng.
ng
(0);
68
master->
master
(i,NULL,ng);
69
stop->m_stat.
nogood
+= ng.
ng
();
70
long
unsigned
int
nl = (*co)();
71
stop->
limit
(e->
statistics
(),nl);
72
if
(master->
status
(stop->m_stat) ==
SS_FAILED
)
73
return
NULL;
74
Space
* slave = master;
75
master = master->
clone
(shared);
76
slave->
slave
(i,n);
77
e->
reset
(slave);
78
}
else
{
79
return
NULL;
80
}
81
}
82
GECODE_NEVER
;
83
return
NULL;
84
}
85
86
Search::Statistics
87
RBS::statistics
(
void
)
const
{
88
return
stop->
metastatistics
()+e->
statistics
();
89
}
90
91
bool
92
RBS::stopped
(
void
)
const
{
93
/*
94
* What might happen during parallel search is that the
95
* engine has been stopped but the meta engine has not, so
96
* the meta engine does not perform a restart. However the
97
* invocation of next will do so and no restart will be
98
* missed.
99
*/
100
return
e->
stopped
();
101
}
102
103
void
104
RBS::reset
(
Space
*) {
105
}
106
107
NoGoods
RBS::eng;
108
109
NoGoods
&
110
RBS::nogoods
(
void
) {
111
return
eng;
112
}
113
114
RBS::~RBS
(
void
) {
115
// Deleting e also deletes stop
116
delete
e;
117
delete
master;
118
delete
co;
119
}
120
121
}}}
122
123
// STATISTICS: search-other