Package com.jgalgo.alg.shortestpath
Class NegativeCycleException
- java.lang.Object
-
- java.lang.Throwable
-
- java.lang.Exception
-
- java.lang.RuntimeException
-
- com.jgalgo.alg.shortestpath.NegativeCycleException
-
- All Implemented Interfaces:
Serializable
public class NegativeCycleException extends RuntimeException
Exception thrown when a negative cycle is detected in a graph during a shortest path computation.Negative weights are supported by some implementations of shortest path algorithm, and the 'shortest path' is well defined as long as there are no negative cycle in the graph as a path can loop in the cycle and achieve arbitrary small 'length'. When negative cycles exists, algorithms will raise
NegativeCycleException
exception.- Author:
- Barak Ugav
- See Also:
ShortestPathSingleSource
,ShortestPathAllPairs
, Serialized Form
-
-
Constructor Summary
Constructors Constructor Description NegativeCycleException(Graph<V,E> graph, Path<V,E> cycle)
Create a new instance of the exception.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Path<?,?>
cycle()
Get the negative cycle that was found in the graph.<V,E>
Path<V,E>cycle(Graph<V,E> g)
Get the negative cycle that was found in the graph in type generic safe way.-
Methods inherited from class java.lang.Throwable
addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString
-
-
-
-
Constructor Detail
-
NegativeCycleException
public NegativeCycleException(Graph<V,E> graph, Path<V,E> cycle)
Create a new instance of the exception.- Type Parameters:
V
- the vertices typeE
- the edges type- Parameters:
graph
- the graph on which the negative cycle was detectedcycle
- the negative cycle that was found in the graph
-
-
Method Detail
-
cycle
public Path<?,?> cycle()
Get the negative cycle that was found in the graph.- Returns:
- the negative cycle that was found in the graph.
-
cycle
public <V,E> Path<V,E> cycle(Graph<V,E> g)
Get the negative cycle that was found in the graph in type generic safe way.by passing the graph on which the exception was thrown to this method, we can safely conclude the generic types of the return path and avoid unchecked casts.
- Type Parameters:
V
- the vertices typeE
- the edges type- Parameters:
g
- the graph on which the exception was thrown- Returns:
- the negative cycle that was found in the graph.
-
-