Generated on Sat Jun 2 2018 07:17:44 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  * This file is part of Gecode, the generic constraint
10  * development environment:
11  * http://www.gecode.org
12  *
13  * Permission is hereby granted, free of charge, to any person obtaining
14  * a copy of this software and associated documentation files (the
15  * "Software"), to deal in the Software without restriction, including
16  * without limitation the rights to use, copy, modify, merge, publish,
17  * distribute, sublicense, and/or sell copies of the Software, and to
18  * permit persons to whom the Software is furnished to do so, subject to
19  * the following conditions:
20  *
21  * The above copyright notice and this permission notice shall be
22  * included in all copies or substantial portions of the Software.
23  *
24  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
29  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31  *
32  */
33 
34 #ifndef __GECODE_SEARCH_PAR_PBS_HH__
35 #define __GECODE_SEARCH_PAR_PBS_HH__
36 
37 #include <gecode/search.hh>
38 
39 namespace Gecode { namespace Search { namespace Par {
40 
43  private:
45  Stop* so;
47  volatile bool* tostop;
48  public:
50  PortfolioStop(Stop* so);
52  void share(volatile bool* ts);
54  virtual bool stop(const Statistics& s, const Options& o);
56  void stop(bool s);
58  bool stop(void) const;
59  };
60 
61  // Forward declaration
62  template<class Collect>
63  class PBS;
64 
66  template<class Collect>
68  protected:
75  public:
77  Slave(PBS<Collect>* m, Engine* s, Stop* so);
79  Statistics statistics(void) const;
81  bool stopped(void) const;
83  void constrain(const Space& b);
85  virtual void run(void);
87  virtual ~Slave(void);
88  };
89 
91  class CollectAll {
92  protected:
95  public:
97  static const bool best = false;
99  CollectAll(void);
101  bool add(Space* s, Slave<CollectAll>* r);
103  bool constrain(const Space& b);
105  bool empty(void) const;
107  Space* get(Slave<CollectAll>*& r);
109  ~CollectAll(void);
110  };
111 
113  class CollectBest {
114  protected:
119  public:
121  static const bool best = true;
123  CollectBest(void);
125  bool add(Space* s, Slave<CollectBest>* r);
127  bool constrain(const Space& b);
129  bool empty(void) const;
131  Space* get(Slave<CollectBest>*& r);
133  ~CollectBest(void);
134  };
135 
137  template<class Collect>
138  class GECODE_SEARCH_EXPORT PBS : public Engine {
139  friend class Slave<Collect>;
140  protected:
146  unsigned int n_slaves;
148  unsigned int n_active;
152  volatile bool tostop;
154  Collect solutions;
158  unsigned int n_busy;
162  bool report(Slave<Collect>* slave, Space* s);
171  public:
173  PBS(Engine** s, Stop** so, unsigned int n, const Statistics& stat);
175  virtual Space* next(void);
177  virtual Statistics statistics(void) const;
179  virtual bool stopped(void) const;
181  virtual void constrain(const Space& b);
183  virtual ~PBS(void);
184  };
185 
186 }}}
187 
188 #include <gecode/search/par/pbs.hpp>
189 
190 #endif
191 
192 // STATISTICS: search-par
Statistics stat
Master statistics.
Definition: pbs.hh:142
volatile bool tostop
Shared stop flag.
Definition: pbs.hh:152
Space * b
Currently best solution.
Definition: pbs.hh:116
Search engine statistics
Definition: search.hh:145
#define GECODE_SEARCH_EXPORT
Definition: search.hh:65
Slave< Collect > ** slaves
Slave engines.
Definition: pbs.hh:144
Engine * slave
The slave engine.
Definition: pbs.hh:72
unsigned int n_slaves
Number of slave engines.
Definition: pbs.hh:146
unsigned int n_busy
Number of busy slaves.
Definition: pbs.hh:158
Search engine options
Definition: search.hh:744
An interface for objects that can be run by a thread.
Definition: thread.hpp:264
Collect all solutions.
Definition: pbs.hh:91
void stop(Support::Timer &timer, std::ostream &os)
Get time since start of timer and print user friendly time information.
Definition: script.cpp:42
Parallel depth-first search engine
Definition: engine.hh:46
Computation spaces.
Definition: core.hpp:1701
Stop * stop
Stop object.
Definition: pbs.hh:74
A mutex for mutual exclausion among several threads.
Definition: thread.hpp:96
Support::Event idle
Signal that number of busy slaves becomes zero.
Definition: pbs.hh:160
int n
Number of negative literals for node type.
Definition: bool-expr.cpp:234
An event for synchronization.
Definition: thread.hpp:215
Support::Mutex m
Mutex for synchronization.
Definition: pbs.hh:156
Slave< CollectBest > * reporter
Who has reported the best solution (NULL if solution has already been reported)
Definition: pbs.hh:118
Collect best solutions.
Definition: pbs.hh:113
Support::DynamicQueue< Space *, Heap > solutions
Queue of solutions.
Definition: pbs.hh:94
Collect solutions
Collect solutions in this.
Definition: pbs.hh:154
Post propagator for SetVar SetOpType SetVar SetRelType r
Definition: set.hh:765
Queue with arbitrary number of elements.
struct Gecode::@585::NNF::@62::@63 b
For binary nodes (and, or, eqv)
Stop object used for controling slaves in a portfolio.
Definition: pbs.hh:42
bool slave_stop
Whether a slave has been stopped.
Definition: pbs.hh:150
Parallel portfolio engine implementation.
Definition: pbs.hh:63
Runnable slave of a portfolio master.
Definition: pbs.hh:67
Gecode toplevel namespace
unsigned int n_active
Number of active slave engines.
Definition: pbs.hh:148
Base-class for Stop-object.
Definition: search.hh:797
PBS< Collect > * master
The master engine.
Definition: pbs.hh:70