The problem data is organized and passed to the solver in an instance of the class TspInstance<V,E> . Note the use of generics. Here V is the type of the objects that will correspond to vertices and E is the type of the objects that will correspond to edges. The point of generics is that our code will not really depend on what the types of our nodes and edges are. Lets take a quick look at the highlights of the public interface to this class. Code Block |
---|
public UndirectedGraph<V, E> getGraph() {
...
}
public Function<E, Integer> getEdgeWeights() {
...
}
|
The UndirectedGraph<V,E> returned by getGraph() is from the JUNG library. You can view the complete documentation here (this page might be more helpful), but some important highlights are Name | Return Type | Arguments | Description |
---|
addVertex | boolean | V vertex | Adds vertex to this graph. Fails if vertex is null or already in the graph. | addEdge | boolean | E e, V v1, V v2 | Adds edge e to this graph such that it connects vertex v1 to v2. | findEdge | E | V v1, V v2 | Returns an edge that connects this vertex to v. Returns null if either v2 is not connected to v1 or either v1 or v2 are not present in this graph. | getIncidentEdges | Collection<E> | V vertex | Returns the collection of edges in this graph which are connected to vertex. | getVertices | Collection<V> | Returns a view of all vertices in this graph. |
---|
Solver InterfaceOpen the file src/solver/TspIpSolver.java by double clicking it from the Project Explorer. This is the file we will be primarily editing. It should contain the following (after the imports):
Toggle TspIpSolver.java Cloak |
---|
visible | true |
---|
id | TspIpSolverStart |
---|
| |
|