rbs.hpp
Go to the documentation of this file.
/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
/*
* Main authors:
* Christian Schulte <schulte@gecode.org>
* Guido Tack <tack@gecode.org>
*
* Copyright:
* Christian Schulte, 2014
* Guido Tack, 2012
*
* This file is part of Gecode, the generic constraint
* development environment:
* http://www.gecode.org
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
#include <gecode/search/support.hh>
#include <gecode/search/seq/dead.hh>
namespace Gecode { namespace Search { namespace Seq {
GECODE_SEARCH_EXPORT Stop*
rbsstop(Stop* so);
GECODE_SEARCH_EXPORT Engine*
rbsengine(Space* master, Stop* stop, Engine* slave,
const Search::Statistics& stat, const Options& opt,
bool best);
}}}
namespace Gecode { namespace Search {
template<class T, template<class> class E>
class RbsBuilder : public Builder {
using Builder::opt;
public:
RbsBuilder(const Options& opt);
virtual Engine* operator() (Space* s) const;
};
template<class T, template<class> class E>
inline
RbsBuilder<T,E>::RbsBuilder(const Options& opt)
: Builder(opt,E<T>::best) {}
template<class T, template<class> class E>
Engine*
RbsBuilder<T,E>::operator() (Space* s) const {
return build<T,RBS<T,E> >(s,opt);
}
}}
namespace Gecode {
template<class T, template<class> class E>
inline
RBS<T,E>::RBS(T* s, const Search::Options& m_opt) {
if (m_opt.cutoff == NULL)
throw Search::UninitializedCutoff("RBS::RBS");
Search::Options e_opt(m_opt.expand());
Search::Statistics stat;
e_opt.clone = false;
e_opt.stop = Search::Seq::rbsstop(m_opt.stop);
Search::WrapTraceRecorder::engine(e_opt.tracer,
SearchTracer::EngineType::RBS, 1U);
if (s->status(stat) == SS_FAILED) {
stat.fail++;
if (!m_opt.clone)
delete s;
e = Search::Seq::dead(e_opt, stat);
} else {
Space* master = m_opt.clone ? s->clone() : s;
Space* slave = master->clone();
MetaInfo mi(0,0,0,NULL,NoGoods::eng);
slave->slave(mi);
e = Search::Seq::rbsengine(master,e_opt.stop,
Search::build<T,E>(slave,e_opt),
stat,m_opt,E<T>::best);
}
}
template<class T, template<class> class E>
inline T*
rbs(T* s, const Search::Options& o) {
RBS<T,E> r(s,o);
return r.next();
}
template<class T, template<class> class E>
SEB
rbs(const Search::Options& o) {
if (o.cutoff == NULL)
throw Search::UninitializedCutoff("rbs");
return new Search::RbsBuilder<T,E>(o);
}
}
// STATISTICS: search-seq
Gecode::MetaInfo
Information passed by meta search engines.
Definition core.hpp:1613
Gecode::NoGoods::eng
static NoGoods eng
Empty no-goods.
Definition core.hpp:1606
Gecode::RBS
Meta-engine performing restart-based search.
Definition search.hh:1152
Gecode::RBS::RBS
RBS(T *s, const Search::Options &o)
Initialize engine for space s and options o.
Definition rbs.hpp:83
Gecode::SearchTracer::RBS
@ RBS
Engine is a RBS engine.
Definition search.hh:197
Gecode::Search::Base::e
Engine * e
The actual search engine.
Definition search.hh:932
Gecode::Search::Builder::opt
Options opt
Stored and already expanded options.
Definition search.hh:968
Gecode::Search::Builder::Builder
Builder(const Options &opt, bool best)
Initialize with options opt and best solution search support.
Definition build.hpp:37
Gecode::Search::Builder::best
bool best(void) const
Whether engine is a best solution search engine.
Definition build.hpp:48
Gecode::Search::Engine
Search engine implementation interface
Definition search.hh:899
Gecode::Search::Options
Search engine options
Definition search.hh:746
Gecode::Search::Options::clone
bool clone
Whether engines create a clone when being initialized.
Definition search.hh:749
Gecode::Search::Options::cutoff
Cutoff * cutoff
Cutoff for restart-based search.
Definition search.hh:767
Gecode::Search::Options::expand
Options expand(void) const
Expand with real number of threads.
Definition options.cpp:43
Gecode::Search::Options::stop
Stop * stop
Stop object for stopping search.
Definition search.hh:765
Gecode::Search::Options::tracer
SearchTracer * tracer
Tracer object for tracing search.
Definition search.hh:769
Gecode::Search::RbsBuilder
A RBS engine builder.
Definition rbs.hpp:57
Gecode::Search::RbsBuilder::operator()
virtual Engine * operator()(Space *s) const
The actual build function.
Definition rbs.hpp:73
Gecode::Search::RbsBuilder::RbsBuilder
RbsBuilder(const Options &opt)
The constructor.
Definition rbs.hpp:68
Gecode::Search::Statistics
Search engine statistics
Definition search.hh:147
Gecode::Search::Statistics::fail
unsigned long int fail
Number of failed nodes in search tree.
Definition search.hh:150
Gecode::Search::UninitializedCutoff
Exception: Uninitialized cutoff for restart-based search
Definition exception.hpp:42
Gecode::Search::WrapTraceRecorder::engine
static void engine(SearchTracer *tracer, SearchTracer::EngineType t, unsigned int n)
Register engine.
Definition trace-recorder.hpp:152
Gecode::Space
Computation spaces.
Definition core.hpp:1742
dead.hh
Gecode::Space::slave
virtual bool slave(const MetaInfo &mi)
Slave configuration function for meta search engines.
Definition core.cpp:863
Gecode::rbs
T * rbs(T *s, const Search::Options &o)
Perform restart-based search.
Definition rbs.hpp:111
Gecode::Space::clone
Space * clone(CloneStatistics &stat=unused_clone) const
Clone space.
Definition core.hpp:3224
Gecode::SS_FAILED
@ SS_FAILED
Space is failed
Definition core.hpp:1682
Gecode::Search::Seq
Definition pbs.cpp:36
Gecode::Search::Seq::dead
Engine * dead(const Options &o, const Statistics &stat)
Definition dead.cpp:90
Gecode::Search::Seq::rbsstop
Stop * rbsstop(Stop *stop)
Create stop object.
Definition rbs.cpp:39
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
Search engines
Gecode::Search::build
Engine * build(Space *s, const Options &opt)
Build an engine of type E for a script T.
Definition build.hpp:58
Gecode
Gecode toplevel namespace
Gecode::SEB
Search::Builder * SEB
Type for a search engine builder.
Definition search.hh:993
support.hh
GECODE_SEARCH_EXPORT
#define GECODE_SEARCH_EXPORT
Definition search.hh:67