Generated on Tue May 22 09:40:13 2018 for Gecode by doxygen 1.6.3

rbs.hpp

Go to the documentation of this file.
00001 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
00002 /*
00003  *  Main authors:
00004  *     Christian Schulte <schulte@gecode.org>
00005  *     Guido Tack <tack@gecode.org>
00006  *
00007  *  Copyright:
00008  *     Christian Schulte, 2014
00009  *     Guido Tack, 2012
00010  *
00011  *  This file is part of Gecode, the generic constraint
00012  *  development environment:
00013  *     http://www.gecode.org
00014  *
00015  *  Permission is hereby granted, free of charge, to any person obtaining
00016  *  a copy of this software and associated documentation files (the
00017  *  "Software"), to deal in the Software without restriction, including
00018  *  without limitation the rights to use, copy, modify, merge, publish,
00019  *  distribute, sublicense, and/or sell copies of the Software, and to
00020  *  permit persons to whom the Software is furnished to do so, subject to
00021  *  the following conditions:
00022  *
00023  *  The above copyright notice and this permission notice shall be
00024  *  included in all copies or substantial portions of the Software.
00025  *
00026  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00027  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00028  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00029  *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00030  *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00031  *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00032  *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
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 // STATISTICS: search-seq