Generated on Tue Mar 24 2020 14:04:04 for Gecode by doxygen 1.8.17
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;
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;
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
An event for synchronization.
Definition: thread.hpp:215
bool add(Space *s, Slave< CollectAll > *r)
Add a solution a reported by r and always return true.
Definition: pbs.hpp:43
PBS< Collect > * master
The master engine.
Definition: pbs.hh:70
#define GECODE_SEARCH_EXPORT
Definition: search.hh:67
CollectAll(void)
Initialize.
Definition: pbs.hpp:40
Search engine options
Definition: search.hh:746
bool empty(void) const
Check whether there is any solution left.
Definition: pbs.hpp:100
bool slave_stop
Whether a slave has been stopped.
Definition: pbs.hh:150
Base-class for Stop-object.
Definition: search.hh:799
unsigned int n_slaves
Number of slave engines.
Definition: pbs.hh:146
Runnable slave of a portfolio master.
Definition: pbs.hh:67
unsigned int n_busy
Number of busy slaves.
Definition: pbs.hh:158
Computation spaces.
Definition: core.hpp:1742
Statistics stat
Master statistics.
Definition: pbs.hh:142
Support::DynamicQueue< Space *, Heap > solutions
Queue of solutions.
Definition: pbs.hh:94
bool add(Space *s, Slave< CollectBest > *r)
Add a solution s by r and return whether is was better.
Definition: pbs.hpp:71
Engine * slave
The slave engine.
Definition: pbs.hh:72
CollectBest(void)
Initialize.
Definition: pbs.hpp:68
Gecode toplevel namespace
Stop * stop
Stop object.
Definition: pbs.hh:74
Collect solutions
Collect solutions in this.
Definition: pbs.hh:154
Parallel portfolio engine implementation.
Definition: pbs.hh:63
Space * get(Slave< CollectAll > *&r)
Return solution reported by r.
Definition: pbs.hpp:57
Parallel depth-first search engine
Definition: engine.hh:46
void stop(Support::Timer &timer, std::ostream &os)
Get time since start of timer and print user friendly time information.
Definition: script.cpp:42
Space * get(Slave< CollectBest > *&r)
Return solution reported by r (only if a better one was found)
Definition: pbs.hpp:104
volatile bool tostop
Shared stop flag.
Definition: pbs.hh:152
Post propagator for SetVar SetOpType SetVar SetRelType r
Definition: set.hh:767
~CollectBest(void)
Destructor.
Definition: pbs.hpp:111
~CollectAll(void)
Destructor.
Definition: pbs.hpp:61
Space * b
Currently best solution.
Definition: pbs.hh:116
struct Gecode::@602::NNF::@65::@66 b
For binary nodes (and, or, eqv)
Slave< CollectBest > * reporter
Who has reported the best solution (NULL if solution has already been reported)
Definition: pbs.hh:118
Collect all solutions.
Definition: pbs.hh:91
Support::Mutex m
Mutex for synchronization.
Definition: pbs.hh:156
Queue with arbitrary number of elements.
static const bool best
Whether it collects best solutions.
Definition: pbs.hh:121
bool empty(void) const
Check whether there is any solution left.
Definition: pbs.hpp:53
unsigned int n_active
Number of active slave engines.
Definition: pbs.hh:148
bool constrain(const Space &b)
Dummy function.
Definition: pbs.hpp:48
static const bool best
Whether it collects best solutions.
Definition: pbs.hh:97
Support::Event idle
Signal that number of busy slaves becomes zero.
Definition: pbs.hh:160
An interface for objects that can be run by a thread.
Definition: thread.hpp:264
bool constrain(const Space &b)
Check whether b better and update accordingly.
Definition: pbs.hpp:86
A mutex for mutual exclausion among several threads.
Definition: thread.hpp:96
int n
Number of negative literals for node type.
Definition: bool-expr.cpp:234
Slave< Collect > ** slaves
Slave engines.
Definition: pbs.hh:144
Search engine statistics
Definition: search.hh:147
Stop object used for controling slaves in a portfolio.
Definition: pbs.hh:42
Collect best solutions.
Definition: pbs.hh:113