Aleph-w 7.10.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
mat_path.H File Reference

Path reconstruction from Floyd-Warshall path matrices. More...

#include <concepts>
#include <functional>
#include <utility>
#include <tpl_matgraph.H>
Include dependency graph for mat_path.H:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  Aleph::Find_Min_Path< Mat, Compare >
 Functor wrapper for find_min_path. More...
 

Namespaces

namespace  Aleph
 Main namespace for Aleph-w library functions.
 
namespace  Aleph::mat_path_detail
 

Concepts

concept  Aleph::mat_path_detail::Arc_With_Distance
 Whether the arcs of GT give their weights by get_info().get_distance(), and Compare compares them.
 

Functions

template<class GT , class Compare >
void Aleph::mat_path_detail::append_node (GT &g, Path< GT > &path, typename GT::Node *node)
 
template<class Mat , class Compare = std::less<>>
void Aleph::find_min_path (Mat &p, long src_idx, long tgt_idx, Path< typename Mat::Graph_Type > &path)
 Build a minimum path from Floyd-Warshall path matrix using indices.
 
template<class Mat , class Compare = std::less<>>
void Aleph::find_min_path (Mat &p, typename Mat::Node *src_node, typename Mat::Node *tgt_node, Path< typename Mat::Graph_Type > &path)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Build a minimum path using node pointers instead of indices.
 

Detailed Description

Path reconstruction from Floyd-Warshall path matrices.

This file provides utilities for reconstructing minimum paths from the path matrix computed by the Floyd-Warshall all-pairs shortest path algorithm.

Overview

After running Floyd-Warshall (see latex_floyd.H or Floyd_Warshall.H), you obtain two matrices:

  • Distance matrix (dist): Contains the shortest path distances
  • Path matrix (path): Contains intermediate node indices for path reconstruction

This file provides find_min_path() to reconstruct the actual path from the path matrix.

Path Matrix Interpretation

For a path from node i to node j:

  • path(i, j) contains the index of the next node after i on the shortest path
  • To reconstruct the full path: start at i, follow path(i, j), path(path(i,j), j), etc.

Usage Example

#include <latex_floyd.H> // it includes mat_path.H
// Create the matrices and run Floyd-Warshall
Ady_Mat<Graph, double> dist(graph);
Ady_Mat<Graph, long> path(graph);
floyd_all_shortest_paths(graph, dist, path);
// Reconstruct path from node 0 to node 5
Path<Graph> min_path(graph);
find_min_path(path, 0L, 5L, min_path);
// Or using node pointers
find_min_path(path, src_node, tgt_node, min_path);
void floyd_all_shortest_paths(GT &g, Ady_Mat< GT, typename GT::Arc_Type::Distance_Type > &dist, Ady_Mat< GT, long > &path)
Compute all-pairs shortest paths using Floyd-Warshall algorithm.
void find_min_path(Mat &p, long src_idx, long tgt_idx, Path< typename Mat::Graph_Type > &path)
Build a minimum path from Floyd-Warshall path matrix using indices.
Definition mat_path.H:191
Floyd-Warshall algorithm with LaTeX output generation.
See also
latex_floyd.H Floyd-Warshall algorithm with LaTeX output
Floyd_Warshall.H Standard Floyd-Warshall implementation
tpl_matgraph.H Matrix-based graph representations
Author
Leandro Rabindranath León

Definition in file mat_path.H.