Generated on Sat Oct 20 2018 12:43:45 for Gecode by doxygen 1.8.13
rbs.hpp
Go to the documentation of this file.
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>
38 
39 namespace Gecode { namespace Search { namespace Seq {
40 
43  rbsstop(Stop* so);
44 
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 
53 namespace Gecode { namespace Search {
54 
56  template<class T, template<class> class E>
57  class RbsBuilder : public Builder {
58  using Builder::opt;
59  public:
61  RbsBuilder(const Options& opt);
63  virtual Engine* operator() (Space* s) const;
64  };
65 
66  template<class T, template<class> class E>
67  inline
69  : Builder(opt,E<T>::best) {}
70 
71  template<class T, template<class> class E>
72  Engine*
74  return build<T,RBS<T,E> >(s,opt);
75  }
76 
77 }}
78 
79 namespace 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 == NULL)
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);
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,NULL,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 == NULL)
120  throw Search::UninitializedCutoff("rbs");
121  return new Search::RbsBuilder<T,E>(o);
122  }
123 
124 
125 }
126 
127 // STATISTICS: search-seq
A RBS engine builder.
Definition: rbs.hpp:57
Search engine implementation interface
Definition: search.hh:899
Search engine statistics
Definition: search.hh:147
RBS(T *s, const Search::Options &o)
Initialize engine for space s and options o.
Definition: rbs.hpp:83
Meta-engine performing restart-based search.
Definition: search.hh:1152
#define GECODE_SEARCH_EXPORT
Definition: search.hh:67
Search engine options
Definition: search.hh:746
A class for building search engines.
Definition: search.hh:965
Options opt
Stored and already expanded options.
Definition: search.hh:968
void stop(Support::Timer &timer, std::ostream &os)
Get time since start of timer and print user friendly time information.
Definition: script.cpp:42
virtual T * next(void)
Return next solution (NULL, if none exists or search has been stopped)
Definition: base.hpp:46
Engine * dead(const Options &o, const Statistics &stat)
Definition: dead.cpp:90
Engine * rbsengine(Space *master, Stop *stop, Engine *slave, const Search::Statistics &stat, const Options &opt, bool best)
Create restart engine.
Definition: rbs.cpp:44
virtual Engine * operator()(Space *s) const
The actual build function.
Definition: rbs.hpp:73
Computation spaces.
Definition: core.hpp:1701
Options expand(void) const
Expand with real number of threads.
Definition: options.cpp:43
RbsBuilder(const Options &opt)
The constructor.
Definition: rbs.hpp:68
Cutoff * cutoff
Cutoff for restart-based search.
Definition: search.hh:767
Options opt
The options.
Definition: test.cpp:97
Space * clone(CloneStatistics &stat=unused_clone) const
Clone space.
Definition: core.hpp:3181
bool clone
Whether engines create a clone when being initialized.
Definition: search.hh:749
virtual bool slave(const MetaInfo &mi)
Slave configuration function for meta search engines.
Definition: core.cpp:835
Post propagator for SetVar SetOpType SetVar SetRelType r
Definition: set.hh:767
static void engine(SearchTracer *tracer, SearchTracer::EngineType t, unsigned int n)
Register engine.
Stop * rbsstop(Stop *stop)
Create stop object.
Definition: rbs.cpp:39
Exception: Uninitialized cutoff for restart-based search
Definition: exception.hpp:42
static NoGoods eng
Empty no-goods.
Definition: core.hpp:1565
Stop * stop
Stop object for stopping search.
Definition: search.hh:765
Gecode toplevel namespace
Information passed by meta search engines.
Definition: core.hpp:1572
Space is failed
Definition: core.hpp:1641
T * rbs(T *s, const Search::Options &o)
Perform restart-based search.
Definition: rbs.hpp:111