Generated on Thu Apr 5 2018 19:44:19 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  * Last modified:
12  * $Date$ by $Author$
13  * $Revision$
14  *
15  * This file is part of Gecode, the generic constraint
16  * development environment:
17  * http://www.gecode.org
18  *
19  * Permission is hereby granted, free of charge, to any person obtaining
20  * a copy of this software and associated documentation files (the
21  * "Software"), to deal in the Software without restriction, including
22  * without limitation the rights to use, copy, modify, merge, publish,
23  * distribute, sublicense, and/or sell copies of the Software, and to
24  * permit persons to whom the Software is furnished to do so, subject to
25  * the following conditions:
26  *
27  * The above copyright notice and this permission notice shall be
28  * included in all copies or substantial portions of the Software.
29  *
30  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
31  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
32  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
33  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
34  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
35  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
36  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
37  *
38  */
39 
40 #include <gecode/search/support.hh>
42 
43 namespace Gecode { namespace Search { namespace Seq {
44 
47  rbsstop(Stop* so);
48 
50  GECODE_SEARCH_EXPORT Engine*
51  rbsengine(Space* master, Stop* stop, Engine* slave,
52  const Search::Statistics& stat, const Options& opt,
53  bool best);
54 
55 }}}
56 
57 namespace Gecode { namespace Search {
58 
60  template<class T, template<class> class E>
61  class RbsBuilder : public Builder {
62  using Builder::opt;
63  public:
65  RbsBuilder(const Options& opt);
67  virtual Engine* operator() (Space* s) const;
68  };
69 
70  template<class T, template<class> class E>
71  inline
73  : Builder(opt,E<T>::best) {}
74 
75  template<class T, template<class> class E>
76  Engine*
78  return build<T,RBS<T,E> >(s,opt);
79  }
80 
81 }}
82 
83 namespace Gecode {
84 
85  template<class T, template<class> class E>
86  inline
87  RBS<T,E>::RBS(T* s, const Search::Options& m_opt) {
88  if (m_opt.cutoff == NULL)
89  throw Search::UninitializedCutoff("RBS::RBS");
90  Search::Options e_opt(m_opt.expand());
91  Search::Statistics stat;
92  e_opt.clone = false;
93  e_opt.stop = Search::Seq::rbsstop(m_opt.stop);
95  SearchTracer::EngineType::RBS, 1U);
96  if (s->status(stat) == SS_FAILED) {
97  stat.fail++;
98  if (!m_opt.clone)
99  delete s;
100  e = Search::Seq::dead(e_opt, stat);
101  } else {
102  Space* master = m_opt.clone ? s->clone() : s;
103  Space* slave = master->clone();
104  MetaInfo mi(0,0,0,NULL,NoGoods::eng);
105  slave->slave(mi);
106  e = Search::Seq::rbsengine(master,e_opt.stop,
107  Search::build<T,E>(slave,e_opt),
108  stat,m_opt,E<T>::best);
109  }
110  }
111 
112 
113  template<class T, template<class> class E>
114  inline T*
115  rbs(T* s, const Search::Options& o) {
116  RBS<T,E> r(s,o);
117  return r.next();
118  }
119 
120  template<class T, template<class> class E>
121  SEB
122  rbs(const Search::Options& o) {
123  if (o.cutoff == NULL)
124  throw Search::UninitializedCutoff("rbs");
125  return new Search::RbsBuilder<T,E>(o);
126  }
127 
128 
129 }
130 
131 // STATISTICS: search-seq
A RBS engine builder.
Definition: rbs.hpp:61
Search engine implementation interface
Definition: search.hh:901
Search engine statistics
Definition: search.hh:149
RBS(T *s, const Search::Options &o)
Initialize engine for space s and options o.
Definition: rbs.hpp:87
Meta-engine performing restart-based search.
Definition: search.hh:1155
#define GECODE_SEARCH_EXPORT
Definition: search.hh:69
Search engine options
Definition: search.hh:748
A class for building search engines.
Definition: search.hh:967
Options opt
Stored and already expanded options.
Definition: search.hh:970
void stop(Support::Timer &timer, std::ostream &os)
Get time since start of timer and print user friendly time information.
Definition: script.cpp:46
virtual T * next(void)
Return next solution (NULL, if none exists or search has been stopped)
Definition: base.hpp:50
Engine * dead(const Options &o, const Statistics &stat)
Definition: dead.cpp:94
Engine * rbsengine(Space *master, Stop *stop, Engine *slave, const Search::Statistics &stat, const Options &opt, bool best)
Create restart engine.
Definition: rbs.cpp:48
virtual Engine * operator()(Space *s) const
The actual build function.
Definition: rbs.hpp:77
Computation spaces.
Definition: core.hpp:1668
Options expand(void) const
Expand with real number of threads.
Definition: options.cpp:47
RbsBuilder(const Options &opt)
The constructor.
Definition: rbs.hpp:72
Cutoff * cutoff
Cutoff for restart-based search.
Definition: search.hh:769
Options opt
The options.
Definition: test.cpp:101
Space * clone(CloneStatistics &stat=unused_clone) const
Clone space.
Definition: core.hpp:3144
bool clone
Whether engines create a clone when being initialized.
Definition: search.hh:751
virtual bool slave(const MetaInfo &mi)
Slave configuration function for meta search engines.
Definition: core.cpp:829
Post propagator for SetVar SetOpType SetVar SetRelType r
Definition: set.hh:769
static void engine(SearchTracer *tracer, SearchTracer::EngineType t, unsigned int n)
Register engine.
Stop * rbsstop(Stop *stop)
Create stop object.
Definition: rbs.cpp:43
Exception: Uninitialized cutoff for restart-based search
Definition: exception.hpp:46
static NoGoods eng
Empty no-goods.
Definition: core.hpp:1532
Stop * stop
Stop object for stopping search.
Definition: search.hh:767
Gecode toplevel namespace
Information passed by meta search engines.
Definition: core.hpp:1539
Space is failed
Definition: core.hpp:1608
T * rbs(T *s, const Search::Options &o)
Perform restart-based search.
Definition: rbs.hpp:115