PBeFS
Parallel Best-First Search
Loading...
Searching...
No Matches
BranchAndBoundScheme.h
Go to the documentation of this file.
1/*--------------------------------------------------------------------------*/
2/*---------------------- File BranchAndBoundScheme.h -----------------------*/
3/*--------------------------------------------------------------------------*/
20/*--------------------------------------------------------------------------*/
21/*------------------------------ DEFINITIONS -------------------------------*/
22/*--------------------------------------------------------------------------*/
23
24#ifndef __PBeFS_BranchAndBoundScheme
25 #define __PBeFS_BranchAndBoundScheme
26 /* self-identification: #endif at the end of the file */
27
28/*--------------------------------------------------------------------------*/
29/*-------------------------------- INCLUDES --------------------------------*/
30/*--------------------------------------------------------------------------*/
31
32#include <array>
33
34#include <optional>
35
36#include <stdexcept>
37
38#include <string>
39
40#include <string_view>
41
42#include <utility>
43
44#include <vector>
45
47
49
51
53
55
56/*--------------------------------------------------------------------------*/
57/*------------------------------- NAMESPACE --------------------------------*/
58/*--------------------------------------------------------------------------*/
59
61namespace PBeFS_di_unipi_it
62{
63
64/*--------------------------------------------------------------------------*/
65/*----------------------------- ENUM BBScheme ------------------------------*/
66/*--------------------------------------------------------------------------*/
68
69
79
80/*--------------------------------------------------------------------------*/
81/*------------------------------- FUNCTIONS --------------------------------*/
82/*--------------------------------------------------------------------------*/
83
84namespace detail {
86 inline constexpr std::array< std::string_view , 7 > bb_scheme_names = {
87 "sequential" , "shared" , "distributed" , "deterministic" , "selfsplit" ,
88 "stealing" , "multiqueue" };
89 } // end( namespace detail )
90
91/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
93
94[[nodiscard]] inline std::string_view bb_scheme_name( BBScheme s ) {
95 return( detail::bb_scheme_names.at( std::size_t( s ) ) );
96 }
97
98/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
101
102[[nodiscard]] inline BBScheme bb_scheme( std::string_view name ) {
103 for( std::size_t i = 0 ; i < detail::bb_scheme_names.size() ; ++i )
104 if( detail::bb_scheme_names[ i ] == name )
105 return( BBScheme( i ) );
106 throw( std::invalid_argument( "bb_scheme: unknown scheme " +
107 std::string( name ) ) );
108 }
109
110/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
116
117template< BranchAndBound P , ADS::WorkerExecutor Executor = ADS::ThreadPool >
118[[nodiscard]] BBSolution< typename P::node_type , bb_value_t< P > >
119 parallel_branch_and_bound( const P & problem , BBScheme s ,
121 o = {} ,
122 std::optional< std::vector< BBLeaf<
123 typename P::node_type , bb_value_t< P > > > >
124 seeds = std::nullopt )
125{
126 const auto solve = [ & ]( const auto & b ) {
127 return( seeds ? b.solve( std::move( *seeds ) ) : b.solve() );
128 };
129 switch( s ) {
130 case( BBScheme::sequential ):
131 return( solve( BranchAndBoundSearch< P >( problem , o ) ) );
132 case( BBScheme::shared ):
133 return( solve( SharedBranchAndBound< P , Executor >( problem , o ) ) );
134 case( BBScheme::distributed ):
135 return( solve( DistributedBranchAndBound< P , Executor >( problem ,
136 o ) ) );
138 return( solve( DeterministicBranchAndBound< P , Executor >( problem ,
139 o ) ) );
140 case( BBScheme::selfsplit ):
141 return( solve( SelfSplitBranchAndBound< P , Executor >( problem , o ) ) );
142 case( BBScheme::multiqueue ):
143 if constexpr( MultiQueueValue< bb_value_t< P > > )
144 return( solve( MultiQueueBranchAndBound< P , Executor >( problem ,
145 o ) ) );
146 else
147 throw( std::invalid_argument( "parallel_branch_and_bound: the scheme "
148 "multiqueue needs values atomic with no "
149 "lock" ) );
150 default:
151 return( solve( StealingBranchAndBound< P , Executor >( problem , o ) ) );
152 }
153 }
154
155/*--------------------------------------------------------------------------*/
156
157} // end( namespace PBeFS_di_unipi_it )
158
159/*--------------------------------------------------------------------------*/
160
161#endif /* __PBeFS_BranchAndBoundScheme */
162
163/*--------------------------------------------------------------------------*/
164/*-------------------- End File BranchAndBoundScheme.h ---------------------*/
165/*--------------------------------------------------------------------------*/
Header file for DeterministicBranchAndBound, the parallel Branch-and-Bound (B&B) by synchronous round...
Header file for MultiQueueBranchAndBound, the parallel Branch-and-Bound (B&B) whose workers share the...
Header file for the parallel best-first searches with an incumbent, i.e., the parallel Branch-and-Bou...
Header file for SelfSplitBranchAndBound, the parallel Branch-and-Bound (B&B) whose workers share noth...
Header file for StealingBranchAndBound, the parallel Branch-and-Bound (B&B) whose workers keep the ch...
the sequential best-first search with an incumbent
Definition BranchAndBound.h:875
the parallel B&B by synchronous rounds
Definition DeterministicBranchAndBound.h:119
the parallel B&B with a queue per worker and the children sent to their owners
Definition ParallelBranchAndBound.h:595
the parallel B&B on the MultiQueue of ADS
Definition MultiQueueBranchAndBound.h:127
the parallel B&B by a split of the tree after a sampling
Definition SelfSplitBranchAndBound.h:130
the parallel B&B with one queue shared by the workers
Definition ParallelBranchAndBound.h:348
the parallel B&B by work stealing
Definition StealingBranchAndBound.h:117
the values that the MultiQueue of ADS takes as keys: arithmetic, with a greatest value,...
Definition MultiQueueBranchAndBound.h:104
namespace for the Parallel Best-First Search library
Definition AStar.h:83
BBScheme bb_scheme(std::string_view name)
the scheme of the given name; throws std::invalid_argument if there is none
Definition BranchAndBoundScheme.h:102
typename detail::bb_value< P >::type bb_value_t
the type of the values of the B&B problem P: its value_type, or double
Definition BranchAndBound.h:293
BBScheme
the schemes of the B&B of the core
Definition BranchAndBoundScheme.h:70
@ selfsplit
a split of a sampling [see SelfSplitBranchAndBound]
Definition BranchAndBoundScheme.h:75
@ stealing
work stealing [see StealingBranchAndBound]
Definition BranchAndBoundScheme.h:76
@ multiqueue
a MultiQueue [see MultiQueueBranchAndBound]
Definition BranchAndBoundScheme.h:77
@ sequential
one worker [see BranchAndBoundSearch]
Definition BranchAndBoundScheme.h:71
@ distributed
a queue per worker [see DistributedBranchAndBound]
Definition BranchAndBoundScheme.h:73
@ shared
one shared queue [see SharedBranchAndBound]
Definition BranchAndBoundScheme.h:72
@ deterministic
synchronous rounds [see DeterministicBranchAndBound]
Definition BranchAndBoundScheme.h:74
BBSolution< typename P::node_type, bb_value_t< P > > parallel_branch_and_bound(const P &problem, BBScheme s, const BasicParallelBBOptions< bb_value_t< P > > &o={}, std::optional< std::vector< BBLeaf< typename P::node_type, bb_value_t< P > > > > seeds=std::nullopt)
the B&B of the problem by the scheme s on the given runtime, with the given options,...
Definition BranchAndBoundScheme.h:119
std::string_view bb_scheme_name(BBScheme s)
the name of the scheme s
Definition BranchAndBoundScheme.h:94
the options of the parallel B&B with values of type V
Definition ParallelBranchAndBound.h:135