Class HamiltonianPathAlgoAbstract
- java.lang.Object
-
- com.jgalgo.alg.hamilton.HamiltonianPathAlgoAbstract
-
- All Implemented Interfaces:
HamiltonianPathAlgo
- Direct Known Subclasses:
HamiltonianPathAlgoAbstractBasedCycle
public abstract class HamiltonianPathAlgoAbstract extends Object implements HamiltonianPathAlgo
Abstract class for computing Hamiltonian cycles/paths in graphs.The class implements the interface by solving the problem on the index graph and then maps the results back to the original graph. The implementation for index graphs is abstract and left to the subclasses.
- Author:
- Barak Ugav
-
-
Constructor Summary
Constructors Constructor Description HamiltonianPathAlgoAbstract()
Default constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <V,E>
Iterator<Path<V,E>>hamiltonianCyclesIter(Graph<V,E> g)
Iterate over all Hamiltonian cycles in the given graph.<V,E>
Iterator<Path<V,E>>hamiltonianPathsIter(Graph<V,E> g)
Iterate over all Hamiltonian paths in the given graph.<V,E>
Iterator<Path<V,E>>hamiltonianPathsIter(Graph<V,E> g, V source, V target)
Iterate over all Hamiltonian paths in the given graph that start and end at two given vertices.-
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.jgalgo.alg.hamilton.HamiltonianPathAlgo
hamiltonianCycle, hamiltonianPath, hamiltonianPath
-
-
-
-
Method Detail
-
hamiltonianPathsIter
public <V,E> Iterator<Path<V,E>> hamiltonianPathsIter(Graph<V,E> g)
Description copied from interface:HamiltonianPathAlgo
Iterate over all Hamiltonian paths in the given graph.An Hamiltonian path is a path that visits each vertex of the graph exactly once. This method returns an iterator that iterate over all Hamiltonian paths in the graph. Each returned path will start and end at two arbitrary vertices.
If the graph has no vertices, this methods returns an empty iterator. If the graph has only one vertex, this method returns an iterator that iterate over a single empty path (which is actually a cycle).
If
g
isIntGraph
, the returned iterator will iterate overIPath
objects.- Specified by:
hamiltonianPathsIter
in interfaceHamiltonianPathAlgo
- Type Parameters:
V
- the vertices typeE
- the edges type- Parameters:
g
- the graph- Returns:
- an iterator that iterate over all Hamiltonian paths in the graph
-
hamiltonianPathsIter
public <V,E> Iterator<Path<V,E>> hamiltonianPathsIter(Graph<V,E> g, V source, V target)
Description copied from interface:HamiltonianPathAlgo
Iterate over all Hamiltonian paths in the given graph that start and end at two given vertices.An Hamiltonian path is a path that visits each vertex of the graph exactly once. This method returns an iterator that iterate over all Hamiltonian paths in the graph that start at
source
and end attarget
.If the source and target are the same vertex, the returned iterator will iterate over all Hamiltonian cycles in the graph.
If
g
isIntGraph
, the returned iterator will iterate overIPath
objects.- Specified by:
hamiltonianPathsIter
in interfaceHamiltonianPathAlgo
- Type Parameters:
V
- the vertices typeE
- the edges type- Parameters:
g
- the graphsource
- the source vertextarget
- the target vertex- Returns:
- an iterator that iterate over all Hamiltonian paths in the graph that start at
source
and end attarget
-
hamiltonianCyclesIter
public <V,E> Iterator<Path<V,E>> hamiltonianCyclesIter(Graph<V,E> g)
Description copied from interface:HamiltonianPathAlgo
Iterate over all Hamiltonian cycles in the given graph.An Hamiltonian cycle is a cycle that visits each vertex of the graph exactly once. This method returns an iterator that iterate over all Hamiltonian cycles in the graph.
If the graph has no vertices, this methods returns an empty iterator. If the graph has only one vertex, this method returns an iterator that iterate over a single empty cycle.
If
g
isIntGraph
, the returned iterator will iterate overIPath
objects.- Specified by:
hamiltonianCyclesIter
in interfaceHamiltonianPathAlgo
- Type Parameters:
V
- the vertices typeE
- the edges type- Parameters:
g
- the graph- Returns:
- an iterator that iterate over all Hamiltonian cycles in the graph
-
-