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
### Setup
Unix/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 Types
TSPLIB4J 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 Solutions
Problem 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 Example
The `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
没有合适的资源?快使用搜索试试~ 我知道了~
用于从 TSPLIB 集合中读取旅行商、车辆路线和哈密顿循环问题实例_java_代码_下载
共42个文件
java:35个
xml:1个
md:1个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 184 浏览量
2022-06-22
15:31:29
上传
评论
收藏 114KB ZIP 举报
温馨提示
TSPLIB是旅行商、 车辆路线和 哈密顿循环 问题实例的集合,是一种用于存储实例数据的文件格式。TSPLIB4J 是一个用于读取和处理 TSPLIB 实例数据的 Java 库。 设置 Unix/Linux 用户可以运行download-datasets.shbash 脚本来下载和设置 TSPLIB 问题实例。 对于 Windows 用户,首先创建一个data/目录和下面列出的子文件夹。接下来,下载任何或所有 TSPLIB 问题实例。最后,将问题实例提取到适当的文件夹中。 更多详情、使用方法,请下载后阅读README.md文件
资源推荐
资源详情
资源评论
收起资源包目录
TSPLIB4J-master.zip (42个子文件)
TSPLIB4J
test
org
moeaframework
problem
tsplib
EdgeTest.java 2KB
TestTSP.java 6KB
TSP2OptHeuristicTest.java 4KB
TourTest.java 3KB
TestHCP.java 3KB
TestSOP.java 3KB
DistanceFunctionTest.java 2KB
TestVRP.java 3KB
TestATSP.java 3KB
build.xml 5KB
download-datasets.sh 2KB
screenshot.png 48KB
src
org
moeaframework
problem
tsplib
NodeCoordinates.java 5KB
Tour.java 10KB
DisplayDataType.java 1KB
EdgeWeightType.java 3KB
EdgeWeightMatrix.java 7KB
TSPInstance.java 12KB
Node.java 3KB
VehicleRoutingTable.java 4KB
EdgeData.java 5KB
Edge.java 4KB
DistanceFunction.java 3KB
package-info.java 1KB
EuclideanDistance.java 2KB
PseudoEuclideanDistance.java 2KB
ManhattanDistance.java 2KB
GeographicalDistance.java 3KB
TSP2OptHeuristic.java 3KB
DistanceTable.java 3KB
EdgeWeightFormat.java 2KB
DataType.java 2KB
NodeCoordType.java 2KB
TSPPanel.java 12KB
EdgeDataFormat.java 1KB
MaximumDistance.java 2KB
CeilingDistance.java 2KB
TSPExample.java 7KB
build.properties 380B
.gitignore 61B
README.md 4KB
COPYING 1KB
共 42 条
- 1
资源评论
快撑死的鱼
- 粉丝: 1w+
- 资源: 9156
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功