floydAlgo: Compute length of shortest path between each pair of points.

Description Usage Arguments Value Examples

View source: R/floydAlgo.R

Description

Based on floyd function. If the graph is sparse, floyd seems to use the Johnson algorithm rather than more complex Floyd-Warhall algorithm. C++ code difficult to understand: https://github.com/cran/Rfast/blob/master/src/floyd_john.cpp. Adpated to Directed Acyclic graph, Floyd-Warshall algorithm is used to apply transitive closures.

Usage

1

Arguments

x

An igraph object or a matrix. Matrix values represent the edges cost values. If igraph object, it is automatically converted to adjacency matrix.

Value

A matrix m where he elements denote the length of the shortest path between each pair of points. m[i, j] is zero it means there is not any path from i to j, or a cost of 0.

Examples

1
2
3
4
5
6
7
8
9
library(igraph)
set.seed(123)
g = make_tree(5)
plot(g)
## Make a graph transitive closure with FW algo
m = floydAlgo(g)
m[m>1] = 1 # To adjacency matrix
g_closed = graph_from_adjacency_matrix(m)
plot(g_closed)

MiloMonnier/supplynet documentation built on Feb. 16, 2021, 8:03 p.m.