Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dhadka/tsplib4j
Java library for reading traveling salesman, vehicle routing, and Hamiltonian cycle problem instances from the TSPLIB collection.
https://github.com/dhadka/tsplib4j
Last synced: 18 days ago
JSON representation
Java library for reading traveling salesman, vehicle routing, and Hamiltonian cycle problem instances from the TSPLIB collection.
- Host: GitHub
- URL: https://github.com/dhadka/tsplib4j
- Owner: dhadka
- License: mit
- Created: 2012-11-25T03:17:32.000Z (almost 12 years ago)
- Default Branch: master
- Last Pushed: 2013-04-25T16:20:47.000Z (over 11 years ago)
- Last Synced: 2024-05-02T01:06:27.455Z (7 months ago)
- Language: Java
- Homepage:
- Size: 348 KB
- Stars: 34
- Watchers: 4
- Forks: 19
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: COPYING
Awesome Lists containing this project
README
A Java library for TSPLIB
===### About TSPLIB4J
[TSPLIB](http://comopt.ifi.uni-heidelberg.de/software/TSPLIB95/) is a collection
of [traveling salesman](http://en.wikipedia.org/wiki/Travelling_salesman_problem),
[vehicle routing](http://en.wikipedia.org/wiki/Vehicle_routing_problem), and
[Hamiltonian cycle](http://en.wikipedia.org/wiki/Hamiltonian_path_problem)
problem instances and a file format for storing instance data. TSPLIB4J is a
Java library for reading and processing TSPLIB instance data. TSPLIB4J is
licensed under the MIT license.Prerequisites:
- Java 1.5 or later
- [JUnit 4](http://www.junit.org/) to run test cases
- [MOEA Framework](http://www.moeaframework.org/) JAR files to run TSPExample
### SetupUnix/Linux users can run the `download-datasets.sh` bash script to download and
setup the TSPLIB problem instances.For Windows users, first create a `data/` directory and the subfolders listed
below. Next, download any or all of the
[TSPLIB problem instances](http://comopt.ifi.uni-heidelberg.de/software/TSPLIB95/).
Finally, extract the problem instances into the appropriate folder.data/atsp
data/hcp
data/sop
data/tsp
data/vrp### Traveling Salesman Problem (TSP)
TSPLIB4J provides the necessary methods to load TSP problem instances,
save and load tours, and provides useful methods for validating and
calculating the distance of tours.TSPProblem problem = new TSPProblem(new File("./data/tsp/pcb442.tsp"));
problem.addTour(new File("./data/tsp/pcb442.opt.tour"));
for (Tour tour : problem.getTours()) {
System.out.println(tour.distance(problem));
}
### Additional Problem TypesTSPLIB4J also provides support for Hamiltonian cycle problems (HCP),
asymmetric traveling salesman problems (ATSP), sequential ordering problems (SOP),
and vehicle routing problems (VRP). For example, the code snippet below
demonstrates working with a HCP instance.TSPProblem problem = new TSPProblem(new File("./data/hcp/alb1000.hcp"));
problem.addTour(new File("./data/hcp/alb1000.opt.tour"));
for (Tour tour : problem.getTours()) {
System.out.println(tour.isHamiltonianCycle(problem));
}
### Displaying SolutionsProblem instances and tours can be quickly displayed in Java GUIs using the
built-in TSPPanel Swing panel.TSPProblem problem = new TSPProblem(new File("./data/tsp/gr120.tsp"));
problem.addTour(new File("./data/tsp/gr120.opt.tour"));
TSPPanel panel = new TSPPanel(problem);
panel.displayTour(problem.getTours().get(0), Color.RED);
JFrame frame = new JFrame(problem.getName());
frame.getContentPane().setLayout(new BorderLayout());
frame.getContentPane().add(panel, BorderLayout.CENTER);
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.setSize(500, 400);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
### Optimization ExampleThe `TSPExample.java` file provides an example of optimizing a traveling
salesman problem using the [MOEA Framework](http://www.moeaframework.org)
library. To run this example, you must first download the [compiled binaries
for the MOEA Framework](http://www.moeaframework.org/downloads.html). Next,
you'll need to include the `.jar` files in the `lib/` directory when compiling
and running the TSPLIB4J code. Finally, run TSPExample. TSPExample creates a
GUI showing the evolution of the optimal solution from the initial random
population to the final optimal solution discovered by a genetic algorithm.The current example solves the `data/tsp/pr76.tsp` problem instance, as shown in
the screenshot below. The red line shows the best tour found so far and the
gray lines show alternate routes being searched by the genetic algorithm.![Screenshot of TSPLIB4J](screenshot.png "Screenshot of TSPLIB4J")
Other Open Source Libraries
---
- [MOEA Framework](http://www.moeaframework.org) - A Free and Open Source Java Framework for Multiobjective Optimization
- [DGantt](http://sourceforge.net/projects/dgantt/) - A simple yet powerful Gantt chart library for Java 1.6 and later