## Solving Travelling Salesman Problem using Ant Colony Optimization
### Install dependencies
`pip install -r requirements.txt`
### Usage
The demo is given in the last section of the file. You can also import this file and do the following -
```python
import random
# Instantiate SolveTSPUsingACO passing the desired parameters
acs = SolveTSPUsingACO(mode='ACS', nodes=[(random.uniform(-400, 400), random.uniform(-400, 400)) for _ in range(0, 15)])
# Run the optimization
acs.run()
# Plot the tour
acs.plot()
```
### Example
```python
_colony_size = 5
_steps = 50
_nodes = [(random.uniform(-400, 400), random.uniform(-400, 400)) for _ in range(0, 15)]
acs = SolveTSPUsingACO(mode='ACS', colony_size=_colony_size, steps=_steps, nodes=_nodes)
acs.run()
acs.plot()
elitist = SolveTSPUsingACO(mode='Elitist', colony_size=_colony_size, steps=_steps, nodes=_nodes)
elitist.run()
elitist.plot()
max_min = SolveTSPUsingACO(mode='MaxMin', colony_size=_colony_size, steps=_steps, nodes=_nodes)
max_min.run()
max_min.plot()
```
#### Output
```
Started : ACS
Ended : ACS
Sequence : <- 2 - 11 - 12 - 3 - 1 - 6 - 5 - 15 - 8 - 7 - 13 - 4 - 14 - 9 - 10 ->
Total distance travelled to complete the tour : 2977.62
Started : Elitist
Ended : Elitist
Sequence : <- 1 - 6 - 3 - 12 - 11 - 2 - 10 - 9 - 14 - 4 - 7 - 13 - 8 - 15 - 5 ->
Total distance travelled to complete the tour : 2815.67
Started : MaxMin
Ended : MaxMin
Sequence : <- 12 - 2 - 11 - 10 - 9 - 14 - 4 - 7 - 13 - 8 - 15 - 5 - 1 - 6 - 3 ->
Total distance travelled to complete the tour : 2780.43
```
#### Plots
![ACS Tour](tour_plots/ACS.png "ACS Tour")
![Elitist Tour](tour_plots/Elitist.png "Elitist Tour")
![MaxMin Tour](tour_plots/MaxMin.png "MaxMin Tour")
### Reference
www.theprojectspot.com/tutorial-post/ant-colony-optimization-for-hackers/10
野生的狒狒
- 粉丝: 3398
- 资源: 2437
最新资源
- mamba 2 windows (cuda12.4)安装包,包括causal-conv1d,mamba-ssm
- simulink风储调频,风机混合储能电池超级电容储能联合一次调频,系统频率特性如下 电池储能采用双闭环pwm设计,频率控制环节为下垂控制 超级电容采用恒流充放电,降低电压释放存储在电容器中的能量
- OPC用户使用操作使用说明
- 0java实验报告.7z
- 两层液压梯程序,使用三菱FX1N系列PLC,已在设备上正常使用,非常稳定可靠,包含PLC程序
- zb25电气调车参考文档
- C++、基于MFC图像处理系统-2025
- JAVA基础编程练习:涵盖条件语句、循环结构、类和对象、继承多态及异常处理的应用案例集合
- zb45电气调车参考文档
- C++期末大作业-MFC 开发的Windows标准计算器和程序员计算器-2025
- Java编程实践:多位数字解析、文本检索、格式校验及其他基础练习
- python 的虚拟环境 原理
- C++-MFC框架为基础,结合opencv来对图像做处理-2025
- LSSVM,SSA-LSSVM,VMD-LSSVM,VMD-SSA-LSSVM四种算法做短期电力负荷预测,做对比 结果分析-lssvm 均方根误差(RMSE):0.79172 平均绝对误差(MAE)
- JAVA面向对象编程与异常处理核心技术解析及实际应用
- ZB45电气简化图册1
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈