rbs.hpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 #include <gecode/search/support.hh>
00037 #include <gecode/search/seq/dead.hh>
00038
00039 namespace Gecode { namespace Search { namespace Seq {
00040
00042 GECODE_SEARCH_EXPORT Stop*
00043 rbsstop(Stop* so);
00044
00046 GECODE_SEARCH_EXPORT Engine*
00047 rbsengine(Space* master, Stop* stop, Engine* slave,
00048 const Search::Statistics& stat, const Options& opt,
00049 bool best);
00050
00051 }}}
00052
00053 namespace Gecode { namespace Search {
00054
00056 template<class T, template<class> class E>
00057 class RbsBuilder : public Builder {
00058 using Builder::opt;
00059 public:
00061 RbsBuilder(const Options& opt);
00063 virtual Engine* operator() (Space* s) const;
00064 };
00065
00066 template<class T, template<class> class E>
00067 inline
00068 RbsBuilder<T,E>::RbsBuilder(const Options& opt)
00069 : Builder(opt,E<T>::best) {}
00070
00071 template<class T, template<class> class E>
00072 Engine*
00073 RbsBuilder<T,E>::operator() (Space* s) const {
00074 return build<T,RBS<T,E> >(s,opt);
00075 }
00076
00077 }}
00078
00079 namespace Gecode {
00080
00081 template<class T, template<class> class E>
00082 inline
00083 RBS<T,E>::RBS(T* s, const Search::Options& m_opt) {
00084 if (m_opt.cutoff == NULL)
00085 throw Search::UninitializedCutoff("RBS::RBS");
00086 Search::Options e_opt(m_opt.expand());
00087 Search::Statistics stat;
00088 e_opt.clone = false;
00089 e_opt.stop = Search::Seq::rbsstop(m_opt.stop);
00090 Search::WrapTraceRecorder::engine(e_opt.tracer,
00091 SearchTracer::EngineType::RBS, 1U);
00092 if (s->status(stat) == SS_FAILED) {
00093 stat.fail++;
00094 if (!m_opt.clone)
00095 delete s;
00096 e = Search::Seq::dead(e_opt, stat);
00097 } else {
00098 Space* master = m_opt.clone ? s->clone() : s;
00099 Space* slave = master->clone();
00100 MetaInfo mi(0,0,0,NULL,NoGoods::eng);
00101 slave->slave(mi);
00102 e = Search::Seq::rbsengine(master,e_opt.stop,
00103 Search::build<T,E>(slave,e_opt),
00104 stat,m_opt,E<T>::best);
00105 }
00106 }
00107
00108
00109 template<class T, template<class> class E>
00110 inline T*
00111 rbs(T* s, const Search::Options& o) {
00112 RBS<T,E> r(s,o);
00113 return r.next();
00114 }
00115
00116 template<class T, template<class> class E>
00117 SEB
00118 rbs(const Search::Options& o) {
00119 if (o.cutoff == NULL)
00120 throw Search::UninitializedCutoff("rbs");
00121 return new Search::RbsBuilder<T,E>(o);
00122 }
00123
00124
00125 }
00126
00127