Module org.jgrapht.core
Package org.jgrapht.alg.interfaces
Interface HamiltonianPathSearchResult<V,E>
- Type Parameters:
V- the graph vertex typeE- the graph edge type
public interface HamiltonianPathSearchResult<V,E>
Tri-state result of a
HamiltonianPathAlgorithm search.
A Hamiltonian path search can terminate in three distinct ways:
HamiltonianPathSearchResult.Status.PATH_FOUND— a Hamiltonian path was discovered. The path is available viagetPath().HamiltonianPathSearchResult.Status.PROVEN_ABSENT— the search ran to completion (or was rejected by a sound precheck) and proved that no Hamiltonian path exists.HamiltonianPathSearchResult.Status.ABORTED— the search hit a configured limit before completing. Whether a Hamiltonian path exists in the input graph is unknown.
Callers must consult getStatus() before interpreting an empty getPath():
an empty path may mean either HamiltonianPathSearchResult.Status.PROVEN_ABSENT or HamiltonianPathSearchResult.Status.ABORTED, and
the two have very different semantic implications.
Instances are obtained either from a HamiltonianPathAlgorithm implementation or via
the found(GraphPath, long), provenAbsent(long), and
aborted(long) static factory methods on this interface, which return a default
immutable implementation.
- Author:
- seilat
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic enumTermination state of a Hamiltonian path search. -
Method Summary
Modifier and TypeMethodDescriptionstatic <V,E> HamiltonianPathSearchResult <V, E> aborted(long statesExpanded) Creates a result for a search that was stopped by a state limit before completing.static <V,E> HamiltonianPathSearchResult <V, E> Creates a result for a successful search.getPath()Returns the Hamiltonian path if the search found one.longReturns the number of DFS / DP states the search explored.Returns the termination status of this search.static <V,E> HamiltonianPathSearchResult <V, E> provenAbsent(long statesExpanded) Creates a result for an exhaustive search that proved no Hamiltonian path exists.
-
Method Details
-
getStatus
HamiltonianPathSearchResult.Status getStatus()Returns the termination status of this search.- Returns:
- the search status
-
getPath
Returns the Hamiltonian path if the search found one.- Returns:
- the discovered path, or
Optional.empty()forHamiltonianPathSearchResult.Status.PROVEN_ABSENTandHamiltonianPathSearchResult.Status.ABORTED
-
getStatesExpanded
long getStatesExpanded()Returns the number of DFS / DP states the search explored. The exact counting semantics are implementation-defined; consult the JavaDoc of the producing algorithm for details.- Returns:
- states explored during this search
-
found
Creates a result for a successful search.- Type Parameters:
V- the graph vertex typeE- the graph edge type- Parameters:
path- the Hamiltonian path that was found (must not benull)statesExpanded- the number of states the search explored- Returns:
- a
HamiltonianPathSearchResult.Status.PATH_FOUNDresult holding the given path
-
provenAbsent
Creates a result for an exhaustive search that proved no Hamiltonian path exists.- Type Parameters:
V- the graph vertex typeE- the graph edge type- Parameters:
statesExpanded- the number of states the search explored before concluding- Returns:
- a
HamiltonianPathSearchResult.Status.PROVEN_ABSENTresult with no path
-
aborted
Creates a result for a search that was stopped by a state limit before completing.- Type Parameters:
V- the graph vertex typeE- the graph edge type- Parameters:
statesExpanded- the number of states the search explored before aborting- Returns:
- an
HamiltonianPathSearchResult.Status.ABORTEDresult with no path
-