Package net.automatalib.util.graph
Class ShortestPaths
- java.lang.Object
-
- net.automatalib.util.graph.ShortestPaths
-
public final class ShortestPaths extends Object
Unweighted shortest path search in graphs.This class offers an iterator-style approach to the shortest path search: the methods in this class generally return either an
Iterator
or anIterable
wrapped around an iterator which allows for enumerating all shortest paths to the given set of target nodes. The iterators implement this lazily, i.e., a call to thenext()
method of an iterator will continue the shortest path search on an as-needed basis.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <N,E>
@Nullable Path<N,E>shortestPath(IndefiniteGraph<N,E> graph, N start, int limit, Predicate<? super N> pred)
Returns a shortest path from the start node to the first node that satisfies the given predicate, if available.static <N,E>
@Nullable Path<N,E>shortestPath(IndefiniteGraph<N,E> graph, N start, int limit, N target)
Returns a shortest path from the start node to the target node, if available.static <N,E>
Iterable<Path<N,E>>shortestPaths(IndefiniteGraph<N,E> graph, Collection<? extends N> start, int limit, Collection<?> targets)
Returns a collection of shortest paths from the start nodes to the target nodes, if available.static <N,E>
Iterable<Path<N,E>>shortestPaths(IndefiniteGraph<N,E> graph, Collection<? extends N> start, int limit, Predicate<? super N> pred)
Returns a collection of shortest paths from the start nodes to all nodes that satisfy the given predicate, if available.static <N,E>
Iterable<Path<N,E>>shortestPaths(IndefiniteGraph<N,E> graph, Collection<? extends N> start, int limit, N target)
Returns a collection of shortest paths from the start nodes to the target node, if available.static <N,E>
Iterable<Path<N,E>>shortestPaths(IndefiniteGraph<N,E> graph, N start, int limit, Collection<?> targets)
Returns a collection of shortest paths from the start node to the target nodes, if available.static <N,E>
Iterable<Path<N,E>>shortestPaths(IndefiniteGraph<N,E> graph, N start, int limit, Predicate<? super N> pred)
Returns a collection of shortest paths from the start node to all nodes that satisfy the given predicate, if available.static <N,E>
Iterator<Path<N,E>>shortestPathsIterator(IndefiniteGraph<N,E> graph, Collection<? extends N> start, int limit, Predicate<? super N> pred)
Returns an iterator of shortest paths from the start nodes to all nodes that satisfy the given predicate, if available.
-
-
-
Method Detail
-
shortestPath
public static <N,E> @Nullable Path<N,E> shortestPath(IndefiniteGraph<N,E> graph, N start, int limit, N target)
Returns a shortest path from the start node to the target node, if available.- Type Parameters:
N
- node typeE
- edge type- Parameters:
graph
- the graphstart
- the start nodelimit
- a limit on the maximum path lengthtarget
- the target node- Returns:
- a shortest path from the start node to the target node,
null
if such a path does not exist or exceeds the givenlimit
.
-
shortestPath
public static <N,E> @Nullable Path<N,E> shortestPath(IndefiniteGraph<N,E> graph, N start, int limit, Predicate<? super N> pred)
Returns a shortest path from the start node to the first node that satisfies the given predicate, if available.- Type Parameters:
N
- node typeE
- edge type- Parameters:
graph
- the graphstart
- the start nodelimit
- a limit on the maximum path lengthpred
- the predicate that should be satisfied by the target node- Returns:
- a shortest path from the start node to the first node that satisfies the given predicate,
null
if such a path does not exist or exceeds the givenlimit
.
-
shortestPaths
public static <N,E> Iterable<Path<N,E>> shortestPaths(IndefiniteGraph<N,E> graph, N start, int limit, Collection<?> targets)
Returns a collection of shortest paths from the start node to the target nodes, if available.- Type Parameters:
N
- node typeE
- edge type- Parameters:
graph
- the graphstart
- the start nodelimit
- a limit on the maximum path lengthtargets
- the target nodes- Returns:
- a collection of shortest paths from the start node to the target nodes. May be empty if such paths do not
exist or exceed the given
limit
.
-
shortestPaths
public static <N,E> Iterable<Path<N,E>> shortestPaths(IndefiniteGraph<N,E> graph, N start, int limit, Predicate<? super N> pred)
Returns a collection of shortest paths from the start node to all nodes that satisfy the given predicate, if available.- Type Parameters:
N
- node typeE
- edge type- Parameters:
graph
- the graphstart
- the start nodelimit
- a limit on the maximum path lengthpred
- the predicate that should be satisfied by the target nodes- Returns:
- a collection of shortest paths from the start node to all nodes that satisfy the given predicate. May be
empty if such paths do not exist or exceed the given
limit
.
-
shortestPaths
public static <N,E> Iterable<Path<N,E>> shortestPaths(IndefiniteGraph<N,E> graph, Collection<? extends N> start, int limit, N target)
Returns a collection of shortest paths from the start nodes to the target node, if available.- Type Parameters:
N
- node typeE
- edge type- Parameters:
graph
- the graphstart
- the start nodeslimit
- a limit on the maximum path lengthtarget
- the target node- Returns:
- a collection of shortest paths from the start nodes to the target node. May be empty if such paths do not
exist or exceed the given
limit
.
-
shortestPaths
public static <N,E> Iterable<Path<N,E>> shortestPaths(IndefiniteGraph<N,E> graph, Collection<? extends N> start, int limit, Collection<?> targets)
Returns a collection of shortest paths from the start nodes to the target nodes, if available.- Type Parameters:
N
- node typeE
- edge type- Parameters:
graph
- the graphstart
- the start nodeslimit
- a limit on the maximum path lengthtargets
- the target nodes- Returns:
- a collection of shortest paths from the start nodes to the target nodes. May be empty if such paths do
not exist or exceed the given
limit
.
-
shortestPaths
public static <N,E> Iterable<Path<N,E>> shortestPaths(IndefiniteGraph<N,E> graph, Collection<? extends N> start, int limit, Predicate<? super N> pred)
Returns a collection of shortest paths from the start nodes to all nodes that satisfy the given predicate, if available.- Type Parameters:
N
- node typeE
- edge type- Parameters:
graph
- the graphstart
- the start nodeslimit
- a limit on the maximum path lengthpred
- the predicate that should be satisfied by the target nodes- Returns:
- a collection of shortest paths from the start nodes to all nodes that satisfy the given predicate. May be
empty if such paths do not exist or exceed the given
limit
.
-
shortestPathsIterator
public static <N,E> Iterator<Path<N,E>> shortestPathsIterator(IndefiniteGraph<N,E> graph, Collection<? extends N> start, int limit, Predicate<? super N> pred)
Returns an iterator of shortest paths from the start nodes to all nodes that satisfy the given predicate, if available.- Type Parameters:
N
- node typeE
- edge type- Parameters:
graph
- the graphstart
- the start nodeslimit
- a limit on the maximum path lengthpred
- the predicate that should be satisfied by the target nodes- Returns:
- an iterator of shortest paths from the start nodes to all nodes that satisfy the given predicate. May be
empty
if such paths do not exist or exceed the givenlimit
.
-
-