this repo has no description
1/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */ 2/* 3 * Main authors: 4 * Christian Schulte <schulte@gecode.org> 5 * Guido Tack <tack@gecode.org> 6 * 7 * Copyright: 8 * Christian Schulte, 2014 9 * Guido Tack, 2012 10 * 11 * This file is part of Gecode, the generic constraint 12 * development environment: 13 * http://www.gecode.org 14 * 15 * Permission is hereby granted, free of charge, to any person obtaining 16 * a copy of this software and associated documentation files (the 17 * "Software"), to deal in the Software without restriction, including 18 * without limitation the rights to use, copy, modify, merge, publish, 19 * distribute, sublicense, and/or sell copies of the Software, and to 20 * permit persons to whom the Software is furnished to do so, subject to 21 * the following conditions: 22 * 23 * The above copyright notice and this permission notice shall be 24 * included in all copies or substantial portions of the Software. 25 * 26 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 27 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 28 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 29 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 30 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 31 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 32 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 33 * 34 */ 35 36#include <gecode/search/support.hh> 37#include <gecode/search/seq/dead.hh> 38 39namespace Gecode { namespace Search { namespace Seq { 40 41 /// Create stop object 42 GECODE_SEARCH_EXPORT Stop* 43 rbsstop(Stop* so); 44 45 /// Create restart engine 46 GECODE_SEARCH_EXPORT Engine* 47 rbsengine(Space* master, Stop* stop, Engine* slave, 48 const Search::Statistics& stat, const Options& opt, 49 bool best); 50 51}}} 52 53namespace Gecode { namespace Search { 54 55 /// A RBS engine builder 56 template<class T, template<class> class E> 57 class RbsBuilder : public Builder { 58 using Builder::opt; 59 public: 60 /// The constructor 61 RbsBuilder(const Options& opt); 62 /// The actual build function 63 virtual Engine* operator() (Space* s) const; 64 }; 65 66 template<class T, template<class> class E> 67 inline 68 RbsBuilder<T,E>::RbsBuilder(const Options& opt) 69 : Builder(opt,E<T>::best) {} 70 71 template<class T, template<class> class E> 72 Engine* 73 RbsBuilder<T,E>::operator() (Space* s) const { 74 return build<T,RBS<T,E> >(s,opt); 75 } 76 77}} 78 79namespace Gecode { 80 81 template<class T, template<class> class E> 82 inline 83 RBS<T,E>::RBS(T* s, const Search::Options& m_opt) { 84 if (m_opt.cutoff == nullptr) 85 throw Search::UninitializedCutoff("RBS::RBS"); 86 Search::Options e_opt(m_opt.expand()); 87 Search::Statistics stat; 88 e_opt.clone = false; 89 e_opt.stop = Search::Seq::rbsstop(m_opt.stop); 90 Search::WrapTraceRecorder::engine(e_opt.tracer, 91 SearchTracer::EngineType::RBS, 1U); 92 if (s->status(stat) == SS_FAILED) { 93 stat.fail++; 94 if (!m_opt.clone) 95 delete s; 96 e = Search::Seq::dead(e_opt, stat); 97 } else { 98 Space* master = m_opt.clone ? s->clone() : s; 99 Space* slave = master->clone(); 100 MetaInfo mi(0,0,0,nullptr,NoGoods::eng); 101 slave->slave(mi); 102 e = Search::Seq::rbsengine(master,e_opt.stop, 103 Search::build<T,E>(slave,e_opt), 104 stat,m_opt,E<T>::best); 105 } 106 } 107 108 109 template<class T, template<class> class E> 110 inline T* 111 rbs(T* s, const Search::Options& o) { 112 RBS<T,E> r(s,o); 113 return r.next(); 114 } 115 116 template<class T, template<class> class E> 117 SEB 118 rbs(const Search::Options& o) { 119 if (o.cutoff == nullptr) 120 throw Search::UninitializedCutoff("rbs"); 121 return new Search::RbsBuilder<T,E>(o); 122 } 123 124 125} 126 127// STATISTICS: search-seq