ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
Paths.h
Go to the documentation of this file.
1/*--------------------------------------------------------------------------*/
2/*------------------------------ File Paths.h ------------------------------*/
3/*--------------------------------------------------------------------------*/
105/*--------------------------------------------------------------------------*/
106/*----------------------------- DEFINITIONS --------------------------------*/
107/*--------------------------------------------------------------------------*/
108
109#ifndef __ADS_Paths
110 #define __ADS_Paths
111/* self-identification: #endif constant */
112
113/*--------------------------------------------------------------------------*/
114/*------------------------------ INCLUDES ----------------------------------*/
115/*--------------------------------------------------------------------------*/
116
117#include "ADS/Contract.h"
118#include "ADS/graph/Graph.h"
119#include "ADS/graph/Visit.h"
120
121#include <algorithm>
122#include <cstddef>
123#include <cstdint>
124#include <optional>
125#include <set>
126#include <type_traits>
127#include <utility>
128#include <variant>
129#include <vector>
130
131/*--------------------------------------------------------------------------*/
132/*--------------------------- NAMESPACE ------------------------------------*/
133/*--------------------------------------------------------------------------*/
134
135namespace ADS
136{
137
138namespace detail
139{
140
142template< class G >
143struct EdgeLength
144{
145 using type = int;
146 };
147
148template< class G >
149 requires requires { typename G::Weight; } &&
150 ( ! std::is_same_v< typename G::Weight , std::monostate > )
151struct EdgeLength< G >
152{
153 using type = typename G::Weight;
154 };
155
156} // end( namespace detail )
157
159template< class G >
160using PathLength = typename detail::EdgeLength< G >::type;
161
162/*--------------------------------------------------------------------------*/
163/*----------------------------- SHORTEST PATHS -----------------------------*/
164/*--------------------------------------------------------------------------*/
165
191template< Graph G >
192std::vector< std::uint64_t > countShortestPaths( const G & g , int s );
193
220template< Graph G >
221std::pair< std::vector< int > , std::vector< int > >
222multiSourceDistance( const G & g , const std::vector< int > & S );
223
245template< Graph G >
246int setDistance( const G & g , const std::vector< bool > & A ,
247 const std::vector< bool > & B );
248
249/*--------------------------------------------------------------------------*/
250/*----------------------------- LONGEST PATHS ------------------------------*/
251/*--------------------------------------------------------------------------*/
252
282template< Graph G >
283std::vector< int > longestPathLayering( const G & g );
284
306template< Graph G , class Keep >
307std::vector< PathLength< G > > dagLongestPaths( const G & g , Keep && keep );
308
320template< Graph G >
321std::vector< PathLength< G > > dagLongestPaths( const G & g );
322
323/*--------------------------------------------------------------------------*/
324/*--------------------------------- CYCLES ---------------------------------*/
325/*--------------------------------------------------------------------------*/
326
358template< Graph G , class F >
359void simpleCycles( const G & g , int s , F && f );
360
361/*--------------------------------------------------------------------------*/
362/*--------------------------------- A LINE ---------------------------------*/
363/*--------------------------------------------------------------------------*/
364
389template< class T >
390std::optional< std::vector< std::size_t > >
391refuelingStops( const std::vector< T > & D , T L , T R );
392
393/*--------------------------------------------------------------------------*/
394
395} // end( namespace ADS )
396
397/*--------------------------------------------------------------------------*/
398/*-------------------------- IMPLEMENTATION --------------------------------*/
399/*--------------------------------------------------------------------------*/
400
401#include "ADS/graph/impl/Paths.tpp"
402
403/*--------------------------------------------------------------------------*/
404
405#endif /* Paths.h included */
406
407/*--------------------------------------------------------------------------*/
408/*---------------------------- End File Paths.h ----------------------------*/
409/*--------------------------------------------------------------------------*/
The contracts of ADS: the preconditions, the postconditions and the invariants of the operations,...
The visits of a GRAPH of section 9.5 and their applications, each in time on lists or vectors of adj...
The GRAPH of chapter 9 and its realizations.
Keep
what an on() that returns it asks: to stay, or to be detached after the event, with no exception
Definition Modification.h:156
typename detail::EdgeLength< G >::type PathLength
the type of the lengths of the paths of
Definition Paths.h:160
std::pair< std::vector< int >, std::vector< int > > multiSourceDistance(const G &g, const std::vector< int > &S)
the distance from the nearest node of , INF if none reaches it, and the parents in the forest of the ...
std::vector< std::uint64_t > countShortestPaths(const G &g, int s)
the number of shortest paths, in edges, from to each node, modulo : 1 for , 0 for the nodes not reac...
void simpleCycles(const G &g, int s, F &&f)
calls on each simple cycle through , its nodes from back to
std::vector< int > longestPathLayering(const G &g)
the edges of a longest path ending at each node of the acyclic graph, 0 on the sources (and on the na...
int setDistance(const G &g, const std::vector< bool > &A, const std::vector< bool > &B)
the fewest edges of a path from a node of to one of , 0 if they meet, INF if there is none
std::optional< std::vector< std::size_t > > refuelingStops(const std::vector< T > &D, T L, T R)
the places in of the fewest stops of a trip from 0 to , a full tank lasting and the stations at ,...
std::vector< PathLength< G > > dagLongestPaths(const G &g, Keep &&keep)
the largest total length of a path leaving each node along the edges with , the empty path included,...
GrB_Type type(void)
the type of GraphBLAS of the numbers T: GrB_BOOL, the integers of 8 to 64 bits with or without sign,...
Definition GraphBLAS.h:128
Definition ADT.h:96