Learn R Programming

Rdimtools (version 1.0.0)

aux.shortestpath: Find shortest path using Floyd-Warshall algorithm

Description

This is a fast implementation of Floyd-Warshall algorithm to find the shortest path in a pairwise sense using 'RcppArmadillo'. A logical input is also accepted.

Usage

aux.shortestpath(dist)

Arguments

dist

either an \((n\times n)\) matrix or a dist class object.

Value

an \((n\times n)\) matrix containing pairwise shortest path.

References

Floyd, R.W. (1962) Algorithm 97: Shortest Path. Commincations of the ACMS, Vol.5(6):345.

Examples

Run this code
# NOT RUN {
## Generate 10-sample data
X = aux.gensamples(n=10)

## Find knn graph with k=3
Xgraph = aux.graphnbd(X,type=c("knn",3))

## Separately use binarized and real distance matrices
W1 = aux.shortestpath(Xgraph$mask)
W2 = aux.shortestpath(Xgraph$dist)

par(mfrow=c(1,2))
image(W1); title("from binarized")
image(W2); title("from Euclidean distance")
# }
# NOT RUN {
# }

Run the code above in your browser using DataLab