Package com.jgalgo.alg.shortestpath
Interface KShortestPathsSt
- All Known Implementing Classes:
KShortestPathsStAbstract
,KShortestPathsStBasedPathsTree
,KShortestPathsStHershbergerMaxelSuri
,KShortestPathsStKatohIbarakiMine
,KShortestPathsStYen
public interface KShortestPathsSt
An algorithm for computing the K shortest paths between two vertices in a graph.
Given a graph \(G=(V,E)\), and a weight function \(w:E \rightarrow R\), one might ask what are the K shortest paths
from a source vertex to a target vertex, where the 'shortest' is defined by comparing the sum of edges
weights of each path. This interface computes such paths. It differ from ShortestPathSt
, as it computes
multiple paths, and not just one.
Use newInstance()
to get a default implementation of this interface.
- Author:
- Barak Ugav
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptioncomputeKShortestPaths
(Graph<V, E> g, WeightFunction<E> w, V source, V target, int k) Compute the K shortest paths from a source vertex to a target vertex.static KShortestPathsSt
Create a new K shortest paths algorithm object.
-
Method Details
-
computeKShortestPaths
<V,E> List<Path<V,E>> computeKShortestPaths(Graph<V, E> g, WeightFunction<E> w, V source, V target, int k) Compute the K shortest paths from a source vertex to a target vertex.If
g
isIntGraph
, the returned object is a list ofIPath
. Ifg
isIntGraph
, prefer to passIWeightFunction
for best performance.- Type Parameters:
V
- the vertices typeE
- the edges type- Parameters:
g
- the graphw
- an edge weight functionsource
- the source vertextarget
- the target vertexk
- the number of shortest paths to compute- Returns:
k
shortest paths from the source to the target, or less if there are no suchk
paths
-
newInstance
Create a new K shortest paths algorithm object.This is the recommended way to instantiate a new
KShortestPathsSt
object.- Returns:
- a default implementation of
KShortestPathsSt
-