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