Generated on Tue Feb 11 2025 17:33:26 for Gecode by doxygen 1.12.0
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
38
39namespace Gecode { namespace Search { namespace Seq {
40
43 rbsstop(Stop* so);
44
47 rbsengine(Space* master, Stop* stop, Engine* slave,
48 const Search::Statistics& stat, const Options& opt,
49 bool best);
50
51}}}
52
53namespace 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
69 : Builder(opt,E<T>::best) {}
70
71 template<class T, template<class> class E>
72 Engine*
74 return build<T,RBS<T,E> >(s,opt);
75 }
76
77}}
78
79namespace 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());
88 e_opt.clone = false;
89 e_opt.stop = Search::Seq::rbsstop(m_opt.stop);
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
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
Information passed by meta search engines.
Definition core.hpp:1613
static NoGoods eng
Empty no-goods.
Definition core.hpp:1606
Meta-engine performing restart-based search.
Definition search.hh:1152
RBS(T *s, const Search::Options &o)
Initialize engine for space s and options o.
Definition rbs.hpp:83
@ RBS
Engine is a RBS engine.
Definition search.hh:197
A class for building search engines.
Definition search.hh:965
Options opt
Stored and already expanded options.
Definition search.hh:968
Search engine implementation interface
Definition search.hh:899
Search engine options
Definition search.hh:746
bool clone
Whether engines create a clone when being initialized.
Definition search.hh:749
Cutoff * cutoff
Cutoff for restart-based search.
Definition search.hh:767
Options expand(void) const
Expand with real number of threads.
Definition options.cpp:43
Stop * stop
Stop object for stopping search.
Definition search.hh:765
SearchTracer * tracer
Tracer object for tracing search.
Definition search.hh:769
A RBS engine builder.
Definition rbs.hpp:57
virtual Engine * operator()(Space *s) const
The actual build function.
Definition rbs.hpp:73
RbsBuilder(const Options &opt)
The constructor.
Definition rbs.hpp:68
Search engine statistics
Definition search.hh:147
unsigned long int fail
Number of failed nodes in search tree.
Definition search.hh:150
Exception: Uninitialized cutoff for restart-based search
Definition exception.hpp:42
static void engine(SearchTracer *tracer, SearchTracer::EngineType t, unsigned int n)
Register engine.
Computation spaces.
Definition core.hpp:1742
virtual bool slave(const MetaInfo &mi)
Slave configuration function for meta search engines.
Definition core.cpp:863
T * rbs(T *s, const Search::Options &o)
Perform restart-based search.
Definition rbs.hpp:111
Space * clone(CloneStatistics &stat=unused_clone) const
Clone space.
Definition core.hpp:3224
@ SS_FAILED
Space is failed
Definition core.hpp:1682
Engine * dead(const Options &o, const Statistics &stat)
Definition dead.cpp:90
Stop * rbsstop(Stop *stop)
Create stop object.
Definition rbs.cpp:39
Engine * rbsengine(Space *master, Stop *stop, Engine *slave, const Search::Statistics &stat, const Options &opt, bool best)
Create restart engine.
Definition rbs.cpp:44
Engine * build(Space *s, const Options &opt)
Build an engine of type E for a script T.
Definition build.hpp:58
Gecode toplevel namespace
Search::Builder * SEB
Type for a search engine builder.
Definition search.hh:993
Post propagator for SetVar SetOpType SetVar SetRelType r
Definition set.hh:767
#define GECODE_SEARCH_EXPORT
Definition search.hh:67