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
00037
00038
00039
00040 #include <gecode/search/support.hh>
00041 #include <gecode/search/meta/dead.hh>
00042
00043 namespace Gecode { namespace Search { namespace Meta {
00044
00046 GECODE_SEARCH_EXPORT Stop*
00047 stop(Stop* so);
00048
00050 GECODE_SEARCH_EXPORT Engine*
00051 engine(Space* master, Stop* stop, Engine* slave,
00052 const Search::Statistics& stat, const Options& opt,
00053 bool best);
00054
00055 }}}
00056
00057 namespace Gecode { namespace Search {
00058
00060 template<class T, template<class> class E>
00061 class RbsBuilder : public Builder {
00062 using Builder::opt;
00063 public:
00065 RbsBuilder(const Options& opt);
00067 virtual Engine* operator() (Space* s) const;
00068 };
00069
00070 template<class T, template<class> class E>
00071 inline
00072 RbsBuilder<T,E>::RbsBuilder(const Options& opt)
00073 : Builder(opt,E<T>::best) {}
00074
00075 template<class T, template<class> class E>
00076 Engine*
00077 RbsBuilder<T,E>::operator() (Space* s) const {
00078 return build<T,RBS<T,E> >(s,opt);
00079 }
00080
00081 }}
00082
00083 namespace Gecode {
00084
00085 template<class T, template<class> class E>
00086 inline
00087 RBS<T,E>::RBS(T* s, const Search::Options& m_opt) {
00088 if (m_opt.cutoff == NULL)
00089 throw Search::UninitializedCutoff("RBS::RBS");
00090 Search::Options e_opt(m_opt.expand());
00091 Search::Statistics stat;
00092 e_opt.clone = false;
00093 e_opt.stop = Search::Meta::stop(m_opt.stop);
00094 Space* master;
00095 Space* slave;
00096 if (s->status(stat) == SS_FAILED) {
00097 stat.fail++;
00098 master = NULL;
00099 slave = NULL;
00100 e = new Search::Meta::Dead(stat);
00101 } else {
00102 master = m_opt.clone ? s->clone() : s;
00103 slave = master->clone(true,m_opt.share_rbs);
00104 MetaInfo mi(0,0,0,NULL,NoGoods::eng);
00105 slave->slave(mi);
00106 e = Search::Meta::engine(master,e_opt.stop,Search::build<T,E>(slave,e_opt),
00107 stat,m_opt,E<T>::best);
00108 }
00109 }
00110
00111
00112 template<class T, template<class> class E>
00113 inline T*
00114 rbs(T* s, const Search::Options& o) {
00115 RBS<T,E> r(s,o);
00116 return r.next();
00117 }
00118
00119 template<class T, template<class> class E>
00120 SEB
00121 rbs(const Search::Options& o) {
00122 if (o.cutoff == NULL)
00123 throw Search::UninitializedCutoff("rbs");
00124 return new Search::RbsBuilder<T,E>(o);
00125 }
00126
00127
00128 }
00129
00130