main page
modules
namespaces
classes
files
Gecode home
Generated on Tue Jan 28 2020 00:00:00 for Gecode by
doxygen
1.8.17
gecode
search
rbs.hpp
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
* Guido Tack <tack@gecode.org>
6
*
7
* Copyright:
8
* Christian Schulte, 2014
9
* Guido Tack, 2012
10
*
11
* Last modified:
12
* $Date: 2016-04-19 17:19:45 +0200 (Tue, 19 Apr 2016) $ by $Author: schulte $
13
* $Revision: 14967 $
14
*
15
* This file is part of Gecode, the generic constraint
16
* development environment:
17
* http://www.gecode.org
18
*
19
* Permission is hereby granted, free of charge, to any person obtaining
20
* a copy of this software and associated documentation files (the
21
* "Software"), to deal in the Software without restriction, including
22
* without limitation the rights to use, copy, modify, merge, publish,
23
* distribute, sublicense, and/or sell copies of the Software, and to
24
* permit persons to whom the Software is furnished to do so, subject to
25
* the following conditions:
26
*
27
* The above copyright notice and this permission notice shall be
28
* included in all copies or substantial portions of the Software.
29
*
30
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
31
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
32
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
33
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
34
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
35
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
36
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
37
*
38
*/
39
40
#include <
gecode/search/support.hh
>
41
#include <
gecode/search/meta/dead.hh
>
42
43
namespace
Gecode
{
namespace
Search {
namespace
Meta {
44
46
GECODE_SEARCH_EXPORT
Stop*
47
stop
(Stop* so);
48
50
GECODE_SEARCH_EXPORT
Engine*
51
engine
(Space* master, Stop*
stop
, Engine* slave,
52
const
Search::Statistics& stat,
const
Options&
opt
,
53
bool
best);
54
55
}}}
56
57
namespace
Gecode
{
namespace
Search {
58
60
template
<
class
T,
template
<
class
>
class
E>
61
class
RbsBuilder
:
public
Builder
{
62
using
Builder::opt
;
63
public
:
65
RbsBuilder
(
const
Options
&
opt
);
67
virtual
Engine
*
operator()
(
Space
* s)
const
;
68
};
69
70
template
<
class
T,
template
<
class
>
class
E>
71
inline
72
RbsBuilder<T,E>::RbsBuilder
(
const
Options
&
opt
)
73
:
Builder
(
opt
,E<T>::best) {}
74
75
template
<
class
T,
template
<
class
>
class
E>
76
Engine
*
77
RbsBuilder<T,E>::operator()
(
Space
* s)
const
{
78
return
build<T,RBS<T,E> >(s,
opt
);
79
}
80
81
}}
82
83
namespace
Gecode
{
84
85
template
<
class
T,
template
<
class
>
class
E>
86
inline
87
RBS<T,E>::RBS
(T* s,
const
Search::Options
& m_opt) {
88
if
(m_opt.
cutoff
== NULL)
89
throw
Search::UninitializedCutoff
(
"RBS::RBS"
);
90
Search::Options
e_opt(m_opt.
expand
());
91
Search::Statistics
stat;
92
e_opt.
clone
=
false
;
93
e_opt.
stop
=
Search::Meta::stop
(m_opt.
stop
);
94
Space
* master;
95
Space
* slave;
96
if
(s->status(stat) ==
SS_FAILED
) {
97
stat.
fail
++;
98
master = NULL;
99
slave = NULL;
100
e =
new
Search::Meta::Dead
(stat);
101
}
else
{
102
master = m_opt.
clone
? s->clone() : s;
103
slave = master->
clone
(
true
,m_opt.
share_rbs
);
104
MetaInfo
mi(0,0,0,NULL,
NoGoods::eng
);
105
slave->
slave
(mi);
106
e =
Search::Meta::engine
(master,e_opt.
stop
,Search::build<T,E>(slave,e_opt),
107
stat,m_opt,E<T>::best);
108
}
109
}
110
111
112
template
<
class
T,
template
<
class
>
class
E>
113
inline
T*
114
rbs
(T* s,
const
Search::Options
& o) {
115
RBS<T,E>
r
(s,o);
116
return
r
.next();
117
}
118
119
template
<
class
T,
template
<
class
>
class
E>
120
SEB
121
rbs
(
const
Search::Options
& o) {
122
if
(o.
cutoff
== NULL)
123
throw
Search::UninitializedCutoff
(
"rbs"
);
124
return
new
Search::RbsBuilder<T,E>
(o);
125
}
126
127
128
}
129
130
// STATISTICS: search-meta
Gecode::Search::Meta::Dead
A dead engine (failed root)
Definition:
dead.hh:44
Gecode::Search::RbsBuilder
A RBS engine builder.
Definition:
rbs.hpp:61
GECODE_SEARCH_EXPORT
#define GECODE_SEARCH_EXPORT
Definition:
search.hh:63
Gecode::Space::clone
Space * clone(bool share_data=true, bool share_info=true, CloneStatistics &stat=unused_clone) const
Clone space.
Definition:
core.hpp:3326
Gecode::Search::Options
Search engine options
Definition:
search.hh:446
Gecode::Search::Builder
A class for building search engines.
Definition:
search.hh:667
Gecode::Search::Statistics::fail
unsigned long int fail
Number of failed nodes in search tree.
Definition:
search.hh:143
dead.hh
Gecode::Space
Computation spaces.
Definition:
core.hpp:1748
support.hh
Gecode::Search::Meta::stop
Stop * stop(Stop *stop)
Create stop object.
Definition:
rbs.cpp:43
Gecode::Search::Meta::engine
Engine * engine(Space *master, Stop *stop, Engine *slave, const Search::Statistics &stat, const Options &opt, bool best)
Create restart engine.
Definition:
rbs.cpp:48
Gecode
Gecode toplevel namespace
Gecode::SEB
Search::Builder * SEB
Type for a search engine builder.
Definition:
search.hh:695
Gecode::Search::Options::cutoff
Cutoff * cutoff
Cutoff for restart-based search.
Definition:
search.hh:471
Gecode::RBS
Meta-engine performing restart-based search.
Definition:
search.hh:855
Test::opt
Options opt
The options.
Definition:
test.cpp:101
Gecode::Search::Options::stop
Stop * stop
Stop object for stopping search.
Definition:
search.hh:469
Gecode::Search::RbsBuilder::RbsBuilder
RbsBuilder(const Options &opt)
The constructor.
Definition:
rbs.hpp:72
Gecode::Search::Engine
Search engine implementation interface
Definition:
search.hh:601
Gecode::r
Post propagator for SetVar SetOpType SetVar SetRelType r
Definition:
set.hh:784
Gecode::Search::Options::expand
Options expand(void) const
Expand with real number of threads.
Definition:
options.cpp:47
Gecode::RBS::RBS
RBS(T *s, const Search::Options &o)
Initialize engine for space s and options o.
Definition:
rbs.hpp:87
Gecode::Search::Options::share_rbs
bool share_rbs
Whether to share AFC information between restarts.
Definition:
search.hh:459
Gecode::Space::slave
virtual bool slave(const MetaInfo &mi)
Slave configuration function for meta search engines.
Definition:
core.cpp:841
Gecode::NoGoods::eng
static NoGoods eng
Empty no-goods.
Definition:
core.hpp:1613
Gecode::Search::RbsBuilder::operator()
virtual Engine * operator()(Space *s) const
The actual build function.
Definition:
rbs.hpp:77
Gecode::MetaInfo
Information passed by meta search engines.
Definition:
core.hpp:1620
Gecode::Search::Builder::opt
Options opt
Stored and already expanded options.
Definition:
search.hh:670
Gecode::Search::UninitializedCutoff
Exception: Uninitialized cutoff for restart-based search
Definition:
exception.hpp:46
Gecode::Search::Options::clone
bool clone
Whether engines create a clone when being initialized.
Definition:
search.hh:449
Gecode::Search::Statistics
Search engine statistics
Definition:
search.hh:140
Gecode::SS_FAILED
@ SS_FAILED
Space is failed
Definition:
core.hpp:1689
Gecode::rbs
T * rbs(T *s, const Search::Options &o)
Perform restart-based search.
Definition:
rbs.hpp:114