Solver Input
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.
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. |
Solver Interface
Open 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
public class TspIpSolver<V,E> { public static enum Option{ lazy,userCut, randomizedUserCut, christofidesApprox, christofidesHeuristic,twoOpt,incumbent; } public TspIpSolver(TspInstance<V,E> tspInstance) throws IloException{ this(tspInstance,EnumSet.of(Option.lazy, Option.userCut, Option.christofidesApprox, Option.christofidesHeuristic)); } public TspIpSolver(TspInstance<V,E> tspInstance, EnumSet<Option> options) throws IloException{} public void solve() throws IloException{ } public ImmutableSet<E> getEdgesInOpt(){ return null; } public double getOptVal(){ return 0; } }