ShortestPathTree represents a data type for solving the single-source shortest paths problem in edge-weighted directed acyclic graphs (DAGs). The edge weights can be positive, negative, or zero. There are three APIs: getDistTo(vertex), hasPathTo(vertex), pathTo(vertex).
var ShortestPathTree = natural.ShortestPathTree; var spt = new ShortestPathTree(digraph, 5);
digraph is an instance of EdgeWeightedDigraph, the second param is the start vertex of DAG.
Will return the dist to vertex.
the output will be: 0.35
Will return the shortest path:
output will be: