Generated on Wed Mar 25 2020 20:16:53 for Gecode by doxygen 1.8.5
rbs.hh
Go to the documentation of this file.
1 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2 /*
3  * Main authors:
4  * Guido Tack <tack@gecode.org>
5  *
6  * Copyright:
7  * Guido Tack, 2012
8  *
9  * Last modified:
10  * $Date: 2015-03-19 14:02:56 +0100 (Thu, 19 Mar 2015) $ by $Author: schulte $
11  * $Revision: 14468 $
12  *
13  * This file is part of Gecode, the generic constraint
14  * development environment:
15  * http://www.gecode.org
16  *
17  * Permission is hereby granted, free of charge, to any person obtaining
18  * a copy of this software and associated documentation files (the
19  * "Software"), to deal in the Software without restriction, including
20  * without limitation the rights to use, copy, modify, merge, publish,
21  * distribute, sublicense, and/or sell copies of the Software, and to
22  * permit persons to whom the Software is furnished to do so, subject to
23  * the following conditions:
24  *
25  * The above copyright notice and this permission notice shall be
26  * included in all copies or substantial portions of the Software.
27  *
28  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
29  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
30  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
31  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
32  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
33  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
34  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35  *
36  */
37 
38 #ifndef __GECODE_SEARCH_META_RBS_HH__
39 #define __GECODE_SEARCH_META_RBS_HH__
40 
41 #include <gecode/search.hh>
42 
43 namespace Gecode { namespace Search { namespace Meta {
44 
45  class RBS;
46 
49  template<template<class>class,class> friend class ::Gecode::RBS;
50  friend class ::Gecode::Search::Meta::RBS;
51  private:
53  FailStop* e_stop;
55  Stop* m_stop;
57  bool e_stopped;
59  Statistics m_stat;
60  public:
62  RestartStop(Stop* s);
64  virtual bool stop(const Statistics& s, const Options& o);
66  void limit(const Search::Statistics& s, unsigned long int l);
68  void update(const Search::Statistics& s);
70  Stop* enginestop(void) const;
72  bool enginestopped(void) const;
74  Statistics metastatistics(void) const;
76  ~RestartStop(void);
77  };
78 
80  class GECODE_SEARCH_EXPORT RBS : public Engine {
81  protected:
93  unsigned long int sslr;
95  bool shared;
97  bool complete;
99  bool restart;
100  public:
102  RBS(Space* s, RestartStop* stop0, Engine* e0, const Options& o);
104  virtual Space* next(void);
106  virtual Search::Statistics statistics(void) const;
108  virtual bool stopped(void) const;
110  virtual ~RBS(void);
111  };
112 
113  /*
114  * Stopping for meta search engines
115  *
116  */
117 
120  : e_stop(new FailStop(0)), m_stop(s), e_stopped(false) {}
121 
122  forceinline void
123  RestartStop::limit(const Search::Statistics& s, unsigned long int l) {
124  m_stat += s;
125  e_stopped = false;
126  e_stop->limit(l);
127  }
128 
129  forceinline void
131  m_stat += s;
132  }
133 
135  RestartStop::enginestop(void) const {
136  return e_stop;
137  }
138 
139  forceinline bool
141  return e_stopped;
142  }
143 
146  return m_stat;
147  }
148 
151  delete e_stop;
152  delete m_stop;
153  }
154 
155 
156 
159  Engine* e0, const Options& opt)
160  : e(e0), master(s), last(NULL), co(opt.cutoff), stop(stop0),
161  sslr(0),
162  shared(opt.threads == 1), complete(true), restart(false) {
163  stop->limit(Statistics(),(*co)());
164  }
165 
166 }}}
167 
168 #endif
169 
170 // STATISTICS: search-meta
bool enginestopped(void) const
Return whether the engine has been stopped.
Definition: rbs.hh:140
Search engine implementation interface
Definition: search.hh:601
NNF * l
Left subtree.
Definition: bool-expr.cpp:244
~RestartStop(void)
Delete object.
Definition: rbs.hh:150
Search engine statistics
Definition: search.hh:136
Cutoff * co
The cutoff object.
Definition: rbs.hh:89
#define GECODE_SEARCH_EXPORT
Definition: search.hh:63
Engine for restart-based search.
Definition: rbs.hh:80
Search engine options
Definition: search.hh:449
void stop(Support::Timer &timer, std::ostream &os)
Get time since start of timer and print user friendly time information.
Definition: script.cpp:46
RBS(Space *s, RestartStop *stop0, Engine *e0, const Options &o)
Constructor.
Definition: rbs.hh:158
Base class for cutoff generators for restart-based meta engine.
Definition: search.hh:168
Computation spaces.
Definition: core.hpp:1362
Statistics metastatistics(void) const
Return statistics for the meta engine.
Definition: rbs.hh:145
unsigned long int sslr
How many solutions since the last restart.
Definition: rbs.hh:93
bool restart
Whether a restart must be performed when next is called.
Definition: rbs.hh:99
Options opt
The options.
Definition: test.cpp:101
unsigned long int limit(void) const
Return current limit.
Definition: stop.hpp:88
RestartStop * stop
The stop control object.
Definition: rbs.hh:91
const double threads
Number of threads to use.
Definition: search.hh:95
void limit(const Search::Statistics &s, unsigned long int l)
Set current limit for the engine to l fails.
Definition: rbs.hh:123
Stop-object for restart engine
Definition: rbs.hh:48
Space * last
The last solution space (possibly NULL)
Definition: rbs.hh:87
RestartStop(Stop *s)
Stop the meta engine if indicated by the stop object s.
Definition: rbs.hh:119
Stop * enginestop(void) const
Return the stop object to control the engine.
Definition: rbs.hh:135
Space * master
The master space to restart from.
Definition: rbs.hh:85
#define forceinline
Definition: config.hpp:132
Engine * e
The actual engine.
Definition: rbs.hh:83
void update(const Search::Statistics &s)
Update statistics.
Definition: rbs.hh:130
bool shared(const ConstView< ViewA > &, const ConstView< ViewB > &)
Test whether views share same variable.
Definition: view.hpp:662
Base-class for Stop-object.
Definition: search.hh:494
bool complete
Whether search for the next solution will be complete.
Definition: rbs.hh:97
Stop-object based on number of failures
Definition: search.hh:554
bool shared
Whether the slave can be shared with the master.
Definition: rbs.hh:95