main page
modules
namespaces
classes
files
Gecode home
Generated on Tue Jan 28 2020 00:00:00 for Gecode by
doxygen
1.8.17
gecode
search
meta
parallel
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
46
class
GECODE_SEARCH_EXPORT
PortfolioStop
:
public
Stop
{
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>
71
class
GECODE_SEARCH_EXPORT
Slave
:
public
Support::Runnable
{
72
protected
:
74
PBS<Collect>
*
master
;
76
Engine
*
slave
;
78
Stop
*
stop
;
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
:
98
Support::DynamicQueue<Space*,Heap>
solutions
;
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
:
120
Space
*
b
;
122
Slave<CollectBest>
*
reporter
;
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
:
146
Statistics
stat
;
148
Slave<Collect>
**
slaves
;
150
unsigned
int
n_slaves
;
152
bool
slave_stop
;
154
volatile
bool
tostop
;
156
Collect
solutions
;
158
Support::Mutex
m
;
160
unsigned
int
n_busy
;
162
Support::Event
idle
;
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
182
#include <
gecode/search/meta/parallel/pbs.hpp
>
183
184
#endif
185
186
// STATISTICS: search-meta
Gecode::Search::Meta::Parallel::CollectBest::CollectBest
CollectBest(void)
Initialize.
Definition:
pbs.hpp:68
Gecode::Support::Event
An event for synchronization.
Definition:
thread.hpp:223
Gecode::Search::Meta::Parallel::CollectBest::b
Space * b
Currently best solution.
Definition:
pbs.hh:120
Gecode::Search::Meta::Parallel::CollectBest
Collect best solutions.
Definition:
pbs.hh:117
Gecode::Search::Meta::Parallel::PBS
Parallel portfolio engine implementation.
Definition:
pbs.hh:67
Gecode::Search::Meta::Parallel::CollectAll::get
Space * get(Slave< CollectAll > *&r)
Return solution reported by r.
Definition:
pbs.hpp:59
GECODE_SEARCH_EXPORT
#define GECODE_SEARCH_EXPORT
Definition:
search.hh:63
Gecode::Search::Meta::Parallel::CollectAll::empty
bool empty(void) const
Check whether there is any solution left.
Definition:
pbs.hpp:55
Gecode::Search::Options
Search engine options
Definition:
search.hh:446
Gecode::Search::Stop
Base-class for Stop-object.
Definition:
search.hh:501
Gecode::Search::Meta::Parallel::CollectAll::CollectAll
CollectAll(void)
Initialize.
Definition:
pbs.hpp:42
search.hh
Gecode::Space
Computation spaces.
Definition:
core.hpp:1748
Gecode::Search::Meta::Parallel::CollectAll::solutions
Support::DynamicQueue< Space *, Heap > solutions
Queue of solutions.
Definition:
pbs.hh:98
Gecode::Search::Meta::Parallel::Slave::slave
Engine * slave
The slave engine.
Definition:
pbs.hh:76
Gecode::Search::Meta::Parallel::CollectBest::reporter
Slave< CollectBest > * reporter
Who has reported the best solution (NULL if solution has already been reported)
Definition:
pbs.hh:122
Gecode::Search::Meta::Parallel::Slave::stop
Stop * stop
Stop object.
Definition:
pbs.hh:78
Gecode::Search::Meta::Parallel::CollectBest::best
static const bool best
Whether it collects best solutions.
Definition:
pbs.hh:125
Gecode
Gecode toplevel namespace
Gecode::Search::Meta::Parallel::PBS::idle
Support::Event idle
Signal that number of busy slaves becomes zero.
Definition:
pbs.hh:162
Gecode::Search::Meta::Parallel::CollectAll::~CollectAll
~CollectAll(void)
Destructor.
Definition:
pbs.hpp:63
Gecode::Search::Meta::Parallel::CollectAll::best
static const bool best
Whether it collects best solutions.
Definition:
pbs.hh:101
Gecode::Search::Meta::Parallel::CollectAll
Collect all solutions.
Definition:
pbs.hh:95
Gecode::Search::Meta::Parallel::CollectBest::constrain
bool constrain(const Space &b)
Check whether b better and update accordingly.
Definition:
pbs.hpp:86
b
struct Gecode::@579::NNF::@61::@62 b
For binary nodes (and, or, eqv)
Gecode::Search::Meta::Parallel::stop
Stop * stop(Stop *so)
Create stop object.
Definition:
pbs.cpp:65
Gecode::Search::Meta::Parallel::Slave
Runnable slave of a portfolio master.
Definition:
pbs.hh:71
Gecode::Search::Engine
Search engine implementation interface
Definition:
search.hh:601
Gecode::r
Post propagator for SetVar SetOpType SetVar SetRelType r
Definition:
set.hh:784
Gecode::Search::Meta::Parallel::PBS::n_busy
unsigned int n_busy
Number of busy slaves.
Definition:
pbs.hh:160
Gecode::Search::Meta::Parallel::PBS::tostop
volatile bool tostop
Shared stop flag.
Definition:
pbs.hh:154
Gecode::Search::Meta::Parallel::PBS::slaves
Slave< Collect > ** slaves
Slave engines.
Definition:
pbs.hh:148
Gecode::Search::Meta::Parallel::PBS::m
Support::Mutex m
Mutex for synchronization.
Definition:
pbs.hh:158
Gecode::Search::Meta::Parallel::Slave::master
PBS< Collect > * master
The master engine.
Definition:
pbs.hh:74
pbs.hpp
Gecode::Search::Meta::Parallel::CollectAll::constrain
bool constrain(const Space &b)
Dummy function.
Definition:
pbs.hpp:50
Gecode::Search::Meta::Parallel::CollectBest::~CollectBest
~CollectBest(void)
Destructor.
Definition:
pbs.hpp:111
Gecode::Search::Meta::Parallel::PBS::slave_stop
bool slave_stop
Whether a slave has been stopped.
Definition:
pbs.hh:152
Gecode::Support::DynamicQueue
Queue with arbitrary number of elements.
Definition:
dynamic-queue.hpp:46
Gecode::Search::Meta::Parallel::CollectBest::empty
bool empty(void) const
Check whether there is any solution left.
Definition:
pbs.hpp:100
Gecode::Search::Meta::Parallel::CollectBest::get
Space * get(Slave< CollectBest > *&r)
Return solution reported by r (only if a better one was found)
Definition:
pbs.hpp:104
Gecode::Search::Meta::Parallel::PBS::stat
Statistics stat
Master statistics.
Definition:
pbs.hh:146
Gecode::Support::Runnable
An interface for objects that can be run by a thread.
Definition:
thread.hpp:258
Gecode::Search::Meta::Parallel::PBS::solutions
Collect solutions
Collect solutions in this.
Definition:
pbs.hh:156
Gecode::Support::Mutex
A mutex for mutual exclausion among several threads.
Definition:
thread.hpp:99
n
int n
Number of negative literals for node type.
Definition:
bool-expr.cpp:238
Gecode::Search::Meta::Parallel::CollectBest::add
bool add(Space *s, Slave< CollectBest > *r)
Add a solution s by r and return whether is was better.
Definition:
pbs.hpp:71
Gecode::Search::Statistics
Search engine statistics
Definition:
search.hh:140
Gecode::Search::Meta::Parallel::CollectAll::add
bool add(Space *s, Slave< CollectAll > *r)
Add a solution a reported by r and always return true.
Definition:
pbs.hpp:45
Gecode::Search::Meta::Parallel::PortfolioStop
Stop object used for controling slaves in a portfolio.
Definition:
pbs.hh:46
Gecode::Search::Meta::Parallel::PBS::n_slaves
unsigned int n_slaves
Number of slave engines.
Definition:
pbs.hh:150