Generated on Tue Jul 18 2017 18:41:42 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: 2016-04-19 17:19:45 +0200 (Tue, 19 Apr 2016) $ by $Author: schulte $
13  * $Revision: 14967 $
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 Meta {
44 
47  stop(Stop* so);
48 
50  GECODE_SEARCH_EXPORT Engine*
51  engine(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::Meta::stop(m_opt.stop);
94  Space* master;
95  Space* slave;
96  if (s->status(stat) == SS_FAILED) {
97  stat.fail++;
98  master = NULL;
99  slave = NULL;
100  e = new Search::Meta::Dead(stat);
101  } else {
102  master = m_opt.clone ? s->clone() : s;
103  slave = master->clone(true,m_opt.share_rbs);
104  MetaInfo mi(0,0,0,NULL,NoGoods::eng);
105  slave->slave(mi);
106  e = Search::Meta::engine(master,e_opt.stop,Search::build<T,E>(slave,e_opt),
107  stat,m_opt,E<T>::best);
108  }
109  }
110 
111 
112  template<class T, template<class> class E>
113  inline T*
114  rbs(T* s, const Search::Options& o) {
115  RBS<T,E> r(s,o);
116  return r.next();
117  }
118 
119  template<class T, template<class> class E>
120  SEB
121  rbs(const Search::Options& o) {
122  if (o.cutoff == NULL)
123  throw Search::UninitializedCutoff("rbs");
124  return new Search::RbsBuilder<T,E>(o);
125  }
126 
127 
128 }
129 
130 // STATISTICS: search-meta
A RBS engine builder.
Definition: rbs.hpp:61
Search engine implementation interface
Definition: search.hh:601
Search engine statistics
Definition: search.hh:140
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:855
#define GECODE_SEARCH_EXPORT
Definition: search.hh:63
Search engine options
Definition: search.hh:446
A class for building search engines.
Definition: search.hh:667
Options opt
Stored and already expanded options.
Definition: search.hh:670
virtual T * next(void)
Return next solution (NULL, if none exists or search has been stopped)
Definition: base.hpp:50
virtual Engine * operator()(Space *s) const
The actual build function.
Definition: rbs.hpp:77
Space * clone(bool share_data=true, bool share_info=true, CloneStatistics &stat=unused_clone) const
Clone space.
Definition: core.hpp:3326
Computation spaces.
Definition: core.hpp:1748
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:471
bool share_rbs
Whether to share AFC information between restarts.
Definition: search.hh:459
Options opt
The options.
Definition: test.cpp:101
A dead engine (failed root)
Definition: dead.hh:44
void fail(void)
Fail space.
Definition: core.hpp:4081
bool clone
Whether engines create a clone when being initialized.
Definition: search.hh:449
virtual bool slave(const MetaInfo &mi)
Slave configuration function for meta search engines.
Definition: core.cpp:841
Post propagator for SetVar SetOpType SetVar SetRelType r
Definition: set.hh:784
Exception: Uninitialized cutoff for restart-based search
Definition: exception.hpp:46
static NoGoods eng
Empty no-goods.
Definition: core.hpp:1613
Engine * engine(Space *master, Stop *stop, Engine *slave, const Search::Statistics &stat, const Options &opt, bool best)
Create restart engine.
Definition: rbs.cpp:48
Stop * stop
Stop object for stopping search.
Definition: search.hh:469
Gecode toplevel namespace
Information passed by meta search engines.
Definition: core.hpp:1620
Space is failed
Definition: core.hpp:1689
T * rbs(T *s, const Search::Options &o)
Perform restart-based search.
Definition: rbs.hpp:114
Stop * stop(Stop *stop)
Create stop object.
Definition: rbs.cpp:43