Generated on Thu Apr 5 2018 19:44:19 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$ by $Author$
11  * $Revision$
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_PAR_PBS_HH__
39 #define __GECODE_SEARCH_PAR_PBS_HH__
40 
41 #include <gecode/search.hh>
42 
43 namespace Gecode { namespace Search { namespace Par {
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;
152  unsigned int n_active;
156  volatile bool tostop;
158  Collect solutions;
162  unsigned int n_busy;
166  bool report(Slave<Collect>* slave, Space* s);
175  public:
177  PBS(Engine** s, Stop** so, unsigned int n, const Statistics& stat);
179  virtual Space* next(void);
181  virtual Statistics statistics(void) const;
183  virtual bool stopped(void) const;
185  virtual void constrain(const Space& b);
187  virtual ~PBS(void);
188  };
189 
190 }}}
191 
192 #include <gecode/search/par/pbs.hpp>
193 
194 #endif
195 
196 // STATISTICS: search-par
Statistics stat
Master statistics.
Definition: pbs.hh:146
volatile bool tostop
Shared stop flag.
Definition: pbs.hh:156
Space * b
Currently best solution.
Definition: pbs.hh:120
Search engine statistics
Definition: search.hh:149
#define GECODE_SEARCH_EXPORT
Definition: search.hh:69
Slave< Collect > ** slaves
Slave engines.
Definition: pbs.hh:148
Engine * slave
The slave engine.
Definition: pbs.hh:76
unsigned int n_slaves
Number of slave engines.
Definition: pbs.hh:150
unsigned int n_busy
Number of busy slaves.
Definition: pbs.hh:162
Search engine options
Definition: search.hh:748
An interface for objects that can be run by a thread.
Definition: thread.hpp:267
Collect all solutions.
Definition: pbs.hh:95
void stop(Support::Timer &timer, std::ostream &os)
Get time since start of timer and print user friendly time information.
Definition: script.cpp:46
Parallel depth-first search engine
Definition: engine.hh:50
Computation spaces.
Definition: core.hpp:1668
Stop * stop
Stop object.
Definition: pbs.hh:78
A mutex for mutual exclausion among several threads.
Definition: thread.hpp:105
Support::Event idle
Signal that number of busy slaves becomes zero.
Definition: pbs.hh:164
int n
Number of negative literals for node type.
Definition: bool-expr.cpp:238
An event for synchronization.
Definition: thread.hpp:218
Support::Mutex m
Mutex for synchronization.
Definition: pbs.hh:160
Slave< CollectBest > * reporter
Who has reported the best solution (NULL if solution has already been reported)
Definition: pbs.hh:122
Collect best solutions.
Definition: pbs.hh:117
Support::DynamicQueue< Space *, Heap > solutions
Queue of solutions.
Definition: pbs.hh:98
Collect solutions
Collect solutions in this.
Definition: pbs.hh:158
Post propagator for SetVar SetOpType SetVar SetRelType r
Definition: set.hh:769
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:46
bool slave_stop
Whether a slave has been stopped.
Definition: pbs.hh:154
Parallel portfolio engine implementation.
Definition: pbs.hh:67
Runnable slave of a portfolio master.
Definition: pbs.hh:71
Gecode toplevel namespace
unsigned int n_active
Number of active slave engines.
Definition: pbs.hh:152
Base-class for Stop-object.
Definition: search.hh:801
PBS< Collect > * master
The master engine.
Definition: pbs.hh:74