main page
modules
namespaces
classes
files
Gecode home
Generated on Sun Aug 9 2020 05:34:08 for Gecode by
doxygen
1.8.18
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
* This file is part of Gecode, the generic constraint
12
* development environment:
13
* http://www.gecode.org
14
*
15
* Permission is hereby granted, free of charge, to any person obtaining
16
* a copy of this software and associated documentation files (the
17
* "Software"), to deal in the Software without restriction, including
18
* without limitation the rights to use, copy, modify, merge, publish,
19
* distribute, sublicense, and/or sell copies of the Software, and to
20
* permit persons to whom the Software is furnished to do so, subject to
21
* the following conditions:
22
*
23
* The above copyright notice and this permission notice shall be
24
* included in all copies or substantial portions of the Software.
25
*
26
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
27
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
28
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
29
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
30
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
31
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
32
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33
*
34
*/
35
36
#include <
gecode/search/support.hh
>
37
#include <
gecode/search/seq/dead.hh
>
38
39
namespace
Gecode
{
namespace
Search {
namespace
Seq {
40
42
GECODE_SEARCH_EXPORT
Stop*
43
rbsstop
(Stop* so);
44
46
GECODE_SEARCH_EXPORT
Engine*
47
rbsengine
(Space* master, Stop*
stop
, Engine* slave,
48
const
Search::Statistics& stat,
const
Options&
opt
,
49
bool
best);
50
51
}}}
52
53
namespace
Gecode
{
namespace
Search {
54
56
template
<
class
T,
template
<
class
>
class
E>
57
class
RbsBuilder
:
public
Builder
{
58
using
Builder::opt
;
59
public
:
61
RbsBuilder
(
const
Options
&
opt
);
63
virtual
Engine
*
operator()
(
Space
* s)
const
;
64
};
65
66
template
<
class
T,
template
<
class
>
class
E>
67
inline
68
RbsBuilder<T,E>::RbsBuilder
(
const
Options
&
opt
)
69
:
Builder
(
opt
,E<T>::best) {}
70
71
template
<
class
T,
template
<
class
>
class
E>
72
Engine
*
73
RbsBuilder<T,E>::operator()
(
Space
* s)
const
{
74
return
build<T,RBS<T,E> >(s,
opt
);
75
}
76
77
}}
78
79
namespace
Gecode
{
80
81
template
<
class
T,
template
<
class
>
class
E>
82
inline
83
RBS<T,E>::RBS
(T* s,
const
Search::Options
& m_opt) {
84
if
(m_opt.
cutoff
== NULL)
85
throw
Search::UninitializedCutoff
(
"RBS::RBS"
);
86
Search::Options
e_opt(m_opt.
expand
());
87
Search::Statistics
stat;
88
e_opt.
clone
=
false
;
89
e_opt.
stop
=
Search::Seq::rbsstop
(m_opt.
stop
);
90
Search::WrapTraceRecorder::engine
(e_opt.
tracer
,
91
SearchTracer::EngineType::RBS, 1U);
92
if
(s->status(stat) ==
SS_FAILED
) {
93
stat.
fail
++;
94
if
(!m_opt.
clone
)
95
delete
s;
96
e =
Search::Seq::dead
(e_opt, stat);
97
}
else
{
98
Space
* master = m_opt.
clone
? s->clone() : s;
99
Space
* slave = master->
clone
();
100
MetaInfo
mi(0,0,0,NULL,
NoGoods::eng
);
101
slave->
slave
(mi);
102
e =
Search::Seq::rbsengine
(master,e_opt.
stop
,
103
Search::build<T,E>(slave,e_opt),
104
stat,m_opt,E<T>::best);
105
}
106
}
107
108
109
template
<
class
T,
template
<
class
>
class
E>
110
inline
T*
111
rbs
(T* s,
const
Search::Options
& o) {
112
RBS<T,E>
r
(s,o);
113
return
r
.next();
114
}
115
116
template
<
class
T,
template
<
class
>
class
E>
117
SEB
118
rbs
(
const
Search::Options
& o) {
119
if
(o.
cutoff
== NULL)
120
throw
Search::UninitializedCutoff
(
"rbs"
);
121
return
new
Search::RbsBuilder<T,E>
(o);
122
}
123
124
125
}
126
127
// STATISTICS: search-seq
Gecode::Search::RbsBuilder
A RBS engine builder.
Definition:
rbs.hpp:57
GECODE_SEARCH_EXPORT
#define GECODE_SEARCH_EXPORT
Definition:
search.hh:67
Gecode::Search::Options
Search engine options
Definition:
search.hh:746
Gecode::Search::Builder
A class for building search engines.
Definition:
search.hh:965
Gecode::Search::Seq::dead
Engine * dead(const Options &o, const Statistics &stat)
Definition:
dead.cpp:90
Gecode::Search::Statistics::fail
unsigned long int fail
Number of failed nodes in search tree.
Definition:
search.hh:150
dead.hh
Gecode::Space
Computation spaces.
Definition:
core.hpp:1742
support.hh
Gecode
Gecode toplevel namespace
Gecode::SEB
Search::Builder * SEB
Type for a search engine builder.
Definition:
search.hh:993
Gecode::Space::clone
Space * clone(CloneStatistics &stat=unused_clone) const
Clone space.
Definition:
core.hpp:3224
Gecode::Search::Options::cutoff
Cutoff * cutoff
Cutoff for restart-based search.
Definition:
search.hh:767
Gecode::RBS
Meta-engine performing restart-based search.
Definition:
search.hh:1152
Test::opt
Options opt
The options.
Definition:
test.cpp:97
Gecode::Driver::stop
void stop(Support::Timer &timer, std::ostream &os)
Get time since start of timer and print user friendly time information.
Definition:
script.cpp:42
Gecode::Search::Options::stop
Stop * stop
Stop object for stopping search.
Definition:
search.hh:765
Gecode::Search::RbsBuilder::RbsBuilder
RbsBuilder(const Options &opt)
The constructor.
Definition:
rbs.hpp:68
Gecode::Search::Engine
Search engine implementation interface
Definition:
search.hh:899
Gecode::r
Post propagator for SetVar SetOpType SetVar SetRelType r
Definition:
set.hh:767
Gecode::Search::Seq::rbsengine
Engine * rbsengine(Space *master, Stop *stop, Engine *slave, const Search::Statistics &stat, const Options &opt, bool best)
Create restart engine.
Definition:
rbs.cpp:44
Gecode::Search::Seq::rbsstop
Stop * rbsstop(Stop *stop)
Create stop object.
Definition:
rbs.cpp:39
Gecode::Search::Options::expand
Options expand(void) const
Expand with real number of threads.
Definition:
options.cpp:43
Gecode::RBS::RBS
RBS(T *s, const Search::Options &o)
Initialize engine for space s and options o.
Definition:
rbs.hpp:83
Gecode::Space::slave
virtual bool slave(const MetaInfo &mi)
Slave configuration function for meta search engines.
Definition:
core.cpp:863
Gecode::NoGoods::eng
static NoGoods eng
Empty no-goods.
Definition:
core.hpp:1606
Gecode::Search::RbsBuilder::operator()
virtual Engine * operator()(Space *s) const
The actual build function.
Definition:
rbs.hpp:73
Gecode::MetaInfo
Information passed by meta search engines.
Definition:
core.hpp:1613
Gecode::Search::Builder::opt
Options opt
Stored and already expanded options.
Definition:
search.hh:968
Gecode::Search::UninitializedCutoff
Exception: Uninitialized cutoff for restart-based search
Definition:
exception.hpp:42
Gecode::Search::Options::clone
bool clone
Whether engines create a clone when being initialized.
Definition:
search.hh:749
Gecode::Search::Statistics
Search engine statistics
Definition:
search.hh:147
Gecode::SS_FAILED
@ SS_FAILED
Space is failed
Definition:
core.hpp:1682
Gecode::Search::WrapTraceRecorder::engine
static void engine(SearchTracer *tracer, SearchTracer::EngineType t, unsigned int n)
Register engine.
Definition:
trace-recorder.hpp:152
Gecode::Search::Options::tracer
SearchTracer * tracer
Tracer object for tracing search.
Definition:
search.hh:769
Gecode::rbs
T * rbs(T *s, const Search::Options &o)
Perform restart-based search.
Definition:
rbs.hpp:111