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