ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
Parallel.h
Go to the documentation of this file.
1/*--------------------------------------------------------------------------*/
2/*---------------------------- File Parallel.h -----------------------------*/
3/*--------------------------------------------------------------------------*/
42/*--------------------------------------------------------------------------*/
43/*----------------------------- DEFINITIONS --------------------------------*/
44/*--------------------------------------------------------------------------*/
45
46#ifndef __ADS_interop_lemon_Parallel
47 #define __ADS_interop_lemon_Parallel
48/* self-identification: #endif constant */
49
50/*--------------------------------------------------------------------------*/
51/*------------------------------ INCLUDES ----------------------------------*/
52/*--------------------------------------------------------------------------*/
53
54#if ! __has_include( <lemon/core.h> )
55 #error "the interoperation with LEMON needs the headers of LEMON"
56#endif
57
63
64#include <lemon/bits/traits.h>
65#include <lemon/core.h>
66#include <lemon/dijkstra.h>
67
68#include <cstddef>
69#include <type_traits>
70#include <utility>
71#include <vector>
72
73/*--------------------------------------------------------------------------*/
74/*--------------------------- NAMESPACE ------------------------------------*/
75/*--------------------------------------------------------------------------*/
76
77namespace ADS::lemon_interop
78{
79
80/*--------------------------------------------------------------------------*/
81/*------------------------------ dijkstraFrom ------------------------------*/
82/*--------------------------------------------------------------------------*/
83
102template< class H = void , Executor E , class GR , class LM >
103[[nodiscard]] std::vector< std::vector< typename LM::Value > >
104dijkstraFrom( E & ex , const GR & g , const LM & l ,
105 const std::vector< typename GR::Node > & S )
106{
107 using V = typename LM::Value;
108 using CR = DenseMap< GR , int >;
109 using DM = DenseMap< GR , V >;
111 using Heap = std::conditional_t< std::is_void_v< H > , DaryHeap< V , CR > ,
112 H >;
113 using D =
114 typename ::lemon::Dijkstra< GR , LM >::template SetPredMap< PM >::Create::
115 template SetDistMap< DM >::Create::template SetHeap< Heap , CR >::Create;
116 std::vector< std::vector< V > > R( S.size() );
117 ex.bulk( S.size() , [ & ]( std::size_t i ) {
118 CR cr( g , -1 );
119 DM dm( g );
120 PM pm( g , ::lemon::INVALID );
121 Heap h( cr );
122 D d( g , l );
123 d.predMap( pm ).distMap( dm ).heap( h , cr );
124 d.run( S[ i ] );
125 std::vector< V > r( std::size_t( g.maxNodeId() + 1 ) , infinity< V >() );
126 for( typename GR::NodeIt v( g ) ; v != ::lemon::INVALID ; ++v )
127 if( d.reached( v ) )
128 r[ std::size_t( g.id( v ) ) ] = d.dist( v );
129 R[ i ] = std::move( r );
130 } );
131 return( R );
132 }
133
134/*--------------------------------------------------------------------------*/
135/*------------------------------- sortedArcs -------------------------------*/
136/*--------------------------------------------------------------------------*/
137
141template< Executor E , class GR , class CM , class Item = typename CM::Key >
142[[nodiscard]] std::vector< std::pair< Item , typename CM::Value > >
143sortedArcs( E & ex , const GR & g , const CM & c )
144{
145 using It = typename ::lemon::ItemSetTraits< GR , Item >::ItemIt;
146 std::vector< std::pair< Item , typename CM::Value > > S;
147 for( It x( g ) ; x != ::lemon::INVALID ; ++x )
148 S.emplace_back( x , c[ x ] );
149 ADS::sort( ex , S , []( const auto & a , const auto & b ) {
150 return( a.second < b.second );
151 } );
152 return( S );
153 }
154
155/*--------------------------------------------------------------------------*/
156
157} // end( namespace ADS::lemon_interop )
158
159/*--------------------------------------------------------------------------*/
160
161#endif /* Parallel.h included */
162
163/*--------------------------------------------------------------------------*/
164/*-------------------------- End File Parallel.h ---------------------------*/
165/*--------------------------------------------------------------------------*/
The layer of execution of the parallel algorithms of ADS, beyond the book: an executor runs the calls...
The heaps of ADS as heaps of LEMON, beyond the book: models of the concept lemon::concepts::Heap< PR ...
The maps of LEMON on the structures of ADS, beyond the book: models of the concepts ReadMap,...
The parallel sorts, beyond the book: sort( ex , A , less ) and stableSort( ex , A ,...
The shortest paths of chapter 11 from a node of an oriented GRAPH whose edges have a cost [see Grap...
an IndexedDaryHeap of ADS as a heap of LEMON, on the cross-reference map IM of the caller
Definition Heaps.h:128
a ReferenceMap of LEMON by the ids of the items of a graph, on an array of its own,...
Definition Maps.h:96
std::vector< std::vector< typename LM::Value > > dijkstraFrom(E &ex, const GR &g, const LM &l, const std::vector< typename GR::Node > &S)
the distances from each node of in the digraph of the lengths , by one run of the Dijkstra of LEMON...
Definition Parallel.h:104
std::vector< std::pair< Item, typename CM::Value > > sortedArcs(E &ex, const GR &g, const CM &c)
the pairs ( item , cost ) of the items Item of , the edges of a graph by default, in the order of the...
Definition Parallel.h:143
void sort(E &ex, Store &&A, C less=C())
the vector sorted by less on the threads of ex, not necessarily stable
Definition Digraphs.h:89