LongestPathTree represents a data type for solving the single-source longest paths problem in edge-weighted directed acyclic graphs (DAGs). The edge weights can be positive, negative, or zero. There are three APIs same as ShortestPathTree: getDistTo(vertex), hasPathTo(vertex), pathTo(vertex).
var LongestPathTree = natural.LongestPathTree; var lpt = new LongestPathTree(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: 2.06
Will return the longest path:
output will be:
[5, 1, 3, 6, 4]