95# ifndef FLOYD_WARSHALL_H
96# define FLOYD_WARSHALL_H
98# include <type_traits>
268 <<
"Floyd_All_Shortest_Paths::index_node() node not found";
294 for (
typename GT::Node_Iterator it(
g); it.has_curr(); it.next_ne())
302 for (
long i = 0; i <
n; ++i)
303 for (
long j = 0; j <
n; ++j)
306 for (
long i = 0; i <
n; ++i)
309 for (
long j = 0; j <
n; ++j)
319 Arc *arc =
arcs.search_directed(src, tgt);
332 for (
long k = 0;
k <
n; ++
k)
333 for (
long i = 0; i <
n; ++i)
336 for (
long j = 0; j <
n; ++j)
350 if constexpr (std::numeric_limits<Distance_Type>::is_integer)
352 if constexpr (std::numeric_limits<Distance_Type>::is_signed)
380 for (
long idx = 0; idx <
n; ++idx)
381 if (
dist(idx, idx) < 0)
408 std::stringstream
ss;
425 for (
int i = 0; i <
n; ++i)
427 for (
int j = 0; j <
n; ++j)
451 <<
"Source index out of range";
453 <<
"Target index out of range";
458 auto src =
nodes(src_idx);
Exception handling system with formatted messages for Aleph-w.
#define ah_out_of_range_error_if(C)
Throws std::out_of_range if condition holds.
#define ah_domain_error_if(C)
Throws std::domain_error if condition holds.
#define ah_invalid_argument_if(C)
Throws std::invalid_argument if condition holds.
Standard functor implementations and comparison objects.
High-level sorting functions for Aleph containers.
List_Graph< Graph_Node< Node_Info >, Graph_Arc< Arc_Info > > GT
Default distance accessor for arc weights.
size_t size() const noexcept
Return the current dimension of array.
T & access(const size_t i) const noexcept
Fast access without checking allocation and bound_min_clock checking.
void reserve(const size_t l, const size_t r)
Allocate a range of entries.
Dynamic matrix with sparse storage.
void allocate()
Pre-allocate memory for the entire matrix.
constexpr size_t rows() const noexcept
Get the number of rows.
T & access(const size_t i, const size_t j)
Direct access to an allocated entry.
Compute the all-pairs shortest path distance matrix and the path reconstruction matrix for a graph g ...
DynMatrix< Distance_Type > dist
DynArray< Node * > get_nodes() const
Get an owning copy of the graph nodes array.
DynArray< Node * > get_nodes_copy() const
Get an owning copy of the graph nodes array.
Path< GT > get_min_path(const long src_idx, const long tgt_idx) const
Reconstruct the shortest path between two nodes by matrix indices.
DynMatrix< long > path_mat
const DynMatrix< Distance_Type > & get_dist_mat() const noexcept
Get the distance matrix.
Node * select_node(long i) const noexcept
Get the graph node at a given matrix index.
constexpr bool has_negative_cycle() const noexcept
Check if the graph contains a negative cycle.
std::string entry(const Distance_Type &e) const
Convert a distance value to string representation.
Path< GT > get_min_path(typename GT::Node *src, typename GT::Node *tgt) const
Reconstruct the shortest path between two nodes.
Distance::Distance_Type Distance_Type
const DynArray< Node * > & get_nodes_ref() const noexcept
Get the array of graph nodes as a constant reference.
Floyd_All_Shortest_Paths(const GT &g, SA &&sa=SA())
Construct Floyd-Warshall solver with rvalue arc filter.
Floyd_All_Shortest_Paths(const GT &__g, SA &__sa)
Construct Floyd-Warshall solver for all-pairs shortest paths.
const DynMatrix< long > & get_path_mat() const noexcept
Get the path reconstruction matrix.
long index_node(Node *p) const
Return the adjacency-matrix index corresponding to node p.
static void print(const DynMatrix< Distance_Type > &dist)
Print a distance matrix to standard output.
Index for fast arc lookup by its endpoint nodes.
void append_directed(Node *p)
Append a node to a directed path.
__gmp_expr< typename __gmp_resolve_expr< T, V >::value_type, __gmp_binary_expr< __gmp_expr< T, U >, __gmp_expr< V, W >, __gmp_max_function > > max(const __gmp_expr< T, U > &expr1, const __gmp_expr< V, W > &expr2)
DynArray< Graph::Arc * > arcs
Main namespace for Aleph-w library functions.
Divide_Conquer_DP_Result< Cost > divide_and_conquer_partition_dp(const size_t groups, const size_t n, Transition_Cost_Fn transition_cost, const Cost inf=dp_optimization_detail::default_inf< Cost >())
Optimize partition DP using divide-and-conquer optimization.
DynArray< T > & in_place_sort(DynArray< T > &c, Cmp cmp=Cmp())
Sorts a DynArray in place.
bool binary_search(Itor beg, Itor end, const T &value)
Binary search for a value.
Default filter for filtered iterators on arcs.
Dynamic matrix with lazy allocation.
Generic graph and digraph implementations.
Utility algorithms and operations for graphs.
Arc indexing for fast lookup by endpoint nodes.