Generated on Wed Jan 24 2018 21:22:26 for Gecode by doxygen 1.8.13
pbs.hh
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  *
6  * Copyright:
7  * Christian Schulte, 2015
8  *
9  * Last modified:
10  * $Date: 2016-04-19 17:19:45 +0200 (Tue, 19 Apr 2016) $ by $Author: schulte $
11  * $Revision: 14967 $
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_PARALLEL_PBS_HH__
39 #define __GECODE_SEARCH_META_PARALLEL_PBS_HH__
40 
41 #include <gecode/search.hh>
42 
43 namespace Gecode { namespace Search { namespace Meta { namespace Parallel {
44 
47  private:
49  Stop* so;
51  volatile bool* tostop;
52  public:
54  PortfolioStop(Stop* so);
56  void share(volatile bool* ts);
58  virtual bool stop(const Statistics& s, const Options& o);
60  void stop(bool s);
62  bool stop(void) const;
63  };
64 
65  // Forward declaration
66  template<class Collect>
67  class PBS;
68 
70  template<class Collect>
72  protected:
79  public:
81  Slave(PBS<Collect>* m, Engine* s, Stop* so);
83  Statistics statistics(void) const;
85  bool stopped(void) const;
87  void constrain(const Space& b);
89  virtual void run(void);
91  virtual ~Slave(void);
92  };
93 
95  class CollectAll {
96  protected:
99  public:
101  static const bool best = false;
103  CollectAll(void);
105  bool add(Space* s, Slave<CollectAll>* r);
107  bool constrain(const Space& b);
109  bool empty(void) const;
111  Space* get(Slave<CollectAll>*& r);
113  ~CollectAll(void);
114  };
115 
117  class CollectBest {
118  protected:
123  public:
125  static const bool best = true;
127  CollectBest(void);
129  bool add(Space* s, Slave<CollectBest>* r);
131  bool constrain(const Space& b);
133  bool empty(void) const;
135  Space* get(Slave<CollectBest>*& r);
137  ~CollectBest(void);
138  };
139 
141  template<class Collect>
142  class GECODE_SEARCH_EXPORT PBS : public Engine {
143  friend class Slave<Collect>;
144  protected:
150  unsigned int n_slaves;
154  volatile bool tostop;
156  Collect solutions;
160  unsigned int n_busy;
164  bool report(Slave<Collect>* slave, Space* s);
165  public:
167  PBS(Engine** s, Stop** so, unsigned int n, const Statistics& stat);
169  virtual Space* next(void);
171  virtual Statistics statistics(void) const;
173  virtual bool stopped(void) const;
175  virtual void constrain(const Space& b);
177  virtual ~PBS(void);
178  };
179 
180 }}}}
181 
183 
184 #endif
185 
186 // STATISTICS: search-meta
unsigned int n_busy
Number of busy slaves.
Definition: pbs.hh:160
Search engine implementation interface
Definition: search.hh:601
Search engine statistics
Definition: search.hh:140
#define GECODE_SEARCH_EXPORT
Definition: search.hh:63
Collect best solutions.
Definition: pbs.hh:117
Search engine options
Definition: search.hh:446
An interface for objects that can be run by a thread.
Definition: thread.hpp:258
Stop * stop(Stop *so)
Create stop object.
Definition: pbs.cpp:65
Space * b
Currently best solution.
Definition: pbs.hh:120
Engine * slave
The slave engine.
Definition: pbs.hh:76
Support::DynamicQueue< Space *, Heap > solutions
Queue of solutions.
Definition: pbs.hh:98
volatile bool tostop
Shared stop flag.
Definition: pbs.hh:154
Computation spaces.
Definition: core.hpp:1748
A mutex for mutual exclausion among several threads.
Definition: thread.hpp:99
Support::Event idle
Signal that number of busy slaves becomes zero.
Definition: pbs.hh:162
int n
Number of negative literals for node type.
Definition: bool-expr.cpp:238
An event for synchronization.
Definition: thread.hpp:223
Stop * stop
Stop object.
Definition: pbs.hh:78
Runnable slave of a portfolio master.
Definition: pbs.hh:71
Statistics stat
Master statistics.
Definition: pbs.hh:146
PBS< Collect > * master
The master engine.
Definition: pbs.hh:74
struct Gecode::@579::NNF::@61::@62 b
For binary nodes (and, or, eqv)
Support::Mutex m
Mutex for synchronization.
Definition: pbs.hh:158
Post propagator for SetVar SetOpType SetVar SetRelType r
Definition: set.hh:784
Queue with arbitrary number of elements.
Stop object used for controling slaves in a portfolio.
Definition: pbs.hh:46
Slave< Collect > ** slaves
Slave engines.
Definition: pbs.hh:148
Collect all solutions.
Definition: pbs.hh:95
unsigned int n_slaves
Number of slave engines.
Definition: pbs.hh:150
Gecode toplevel namespace
Base-class for Stop-object.
Definition: search.hh:501
bool slave_stop
Whether a slave has been stopped.
Definition: pbs.hh:152
Collect solutions
Collect solutions in this.
Definition: pbs.hh:156
Parallel portfolio engine implementation.
Definition: pbs.hh:67
Slave< CollectBest > * reporter
Who has reported the best solution (NULL if solution has already been reported)
Definition: pbs.hh:122