Generated on Tue Apr 18 10:22:10 2017 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  *  Last modified:
00012  *     $Date: 2016-04-19 17:19:45 +0200 (Tue, 19 Apr 2016) $ by $Author: schulte $
00013  *     $Revision: 14967 $
00014  *
00015  *  This file is part of Gecode, the generic constraint
00016  *  development environment:
00017  *     http://www.gecode.org
00018  *
00019  *  Permission is hereby granted, free of charge, to any person obtaining
00020  *  a copy of this software and associated documentation files (the
00021  *  "Software"), to deal in the Software without restriction, including
00022  *  without limitation the rights to use, copy, modify, merge, publish,
00023  *  distribute, sublicense, and/or sell copies of the Software, and to
00024  *  permit persons to whom the Software is furnished to do so, subject to
00025  *  the following conditions:
00026  *
00027  *  The above copyright notice and this permission notice shall be
00028  *  included in all copies or substantial portions of the Software.
00029  *
00030  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00031  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00032  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00033  *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00034  *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00035  *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00036  *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
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 // STATISTICS: search-meta