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
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:
-
Constructor Summary
ConstructorDescriptionNegativeCycleException
(Graph<V, E> graph, Path<V, E> cycle) Create a new instance of the exception. -
Method Summary
Methods inherited from class java.lang.Throwable
addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString
-
Constructor Details
-
NegativeCycleException
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 Details
-
cycle
Get the negative cycle that was found in the graph.- Returns:
- the negative cycle that was found in the graph.
-
cycle
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.
-