简单易用的python包,用于快速实验经典的旅行推销员问题。
pytspsolver的Python项目详细描述
Pytssolver
简单易用的软件包,用于对经典的旅行推销员问题进行快速实验。包含各种优化算法、酷的可视化工具和插件架构的实现。
安装
> pip install pytspsolver
用法
此包旨在提供直观的Python接口;允许您以最小的代码和最大的灵活性进行实验。
以下是如何启动旅行推销员问题实验的方法:
frompytspsolver.entitiesimportTSProblemfrompytspsolver.experimentsimportExperimentfrompytspsolver.solversimport*frompytspsolver.utilitiesimportcreate_random_problem,get_tsp_lib_problem,Visualizerimportmatplotlib.pyplotasplt# Create a few tsp problems (represented as an adjacency matrix)problems=[create_random_problem("UniqueProblemName"+str(i),i)foriinrange(3,12)]# Pass in the location of TSPLIB95 dataset filetsp_prob=get_tsp_lib_problem("gr17.tsp")# Create a new Experimentexperiment=Experiment()# Add the problems to the experiment (single or list of problems)experiment.add_problem(tsp_prob)experiment.add_problems(problems)# Add solvers to use in the experimentexperiment.add_solver(ExhaustiveSearch(time_limit=50))experiment.add_solver(GreedySearch(time_limit=100))# Run the experiment desired number of timesresults=experiment.run(epoch=10)# Set up Visualizer with experiment resultsvisualizer=Visualizer(results)# Show visualizations - automatically averages the results from different epochsvisualizer.plot_n_vs_time_all(plt)# Note: the visualizer has various plots available, they can be called in a similar fashion.
它带有一个插件架构,因此非常可定制。
其他示例
使用jupyter笔记本实现了一些示例;可在examples文件夹中找到。通过从当前conda环境启动jupyter笔记本,可以访问这些笔记本。
> jupyter notebook
启动jupyter notebook时,请确保您处于正确的环境中,否则,jupyter notebook内核将指向另一个未安装pytspsolver
包的python版本。
贡献
鼓励贡献和拉动请求!
如果您发现任何问题或希望添加新功能,请在编写代码和提交请求之前在github问题部分进行讨论。