提交 9c3bce48 编写于 作者: guofei9987's avatar guofei9987

version 0.5.4

上级 63cec13a
......@@ -401,12 +401,12 @@ More: Plot the animation:
## 5. ACA (Ant Colony Algorithm) for tsp
-> Demo code: [examples/demo_aca_tsp.py#s2](https://github.com/guofei9987/scikit-opt/blob/master/examples/demo_aca_tsp.py#L23)
-> Demo code: [examples/demo_aca_tsp.py#s2](https://github.com/guofei9987/scikit-opt/blob/master/examples/demo_aca_tsp.py#L17)
```python
from sko.ACA import ACA_TSP
aca = ACA_TSP(func=cal_total_distance, n_dim=8,
size_pop=10, max_iter=20,
aca = ACA_TSP(func=cal_total_distance, n_dim=num_points,
size_pop=50, max_iter=200,
distance_matrix=distance_matrix)
best_x, best_y = aca.run()
......
......@@ -381,12 +381,12 @@ More: Plot the animation:
## 5. ACA (Ant Colony Algorithm) for tsp
-> Demo code: [examples/demo_aca_tsp.py#s2](https://github.com/guofei9987/scikit-opt/blob/master/examples/demo_aca_tsp.py#L23)
-> Demo code: [examples/demo_aca_tsp.py#s2](https://github.com/guofei9987/scikit-opt/blob/master/examples/demo_aca_tsp.py#L17)
```python
from sko.ACA import ACA_TSP
aca = ACA_TSP(func=cal_total_distance, n_dim=8,
size_pop=10, max_iter=20,
aca = ACA_TSP(func=cal_total_distance, n_dim=num_points,
size_pop=50, max_iter=200,
distance_matrix=distance_matrix)
best_x, best_y = aca.run()
......
......@@ -12,6 +12,8 @@
需要从py文件中解析出:
1. # %% 做断点后赋予index值,然后插入readme
'''
import os
import sys
import re
......@@ -93,3 +95,5 @@ for i in docs:
docs_new = make_doc(origin_file=i)
with open(i, encoding='utf-8', mode="w") as f:
f.writelines(docs_new)
sys.exit()
......@@ -350,12 +350,12 @@ print(best_points, best_distance, cal_total_distance(best_points))
## 5. 蚁群算法
蚁群算法(ACA, Ant Colony Algorithm)解决TSP问题
-> Demo code: [examples/demo_aca_tsp.py#s2](https://github.com/guofei9987/scikit-opt/blob/master/examples/demo_aca_tsp.py#L23)
-> Demo code: [examples/demo_aca_tsp.py#s2](https://github.com/guofei9987/scikit-opt/blob/master/examples/demo_aca_tsp.py#L17)
```python
from sko.ACA import ACA_TSP
aca = ACA_TSP(func=cal_total_distance, n_dim=8,
size_pop=10, max_iter=20,
aca = ACA_TSP(func=cal_total_distance, n_dim=num_points,
size_pop=50, max_iter=200,
distance_matrix=distance_matrix)
best_x, best_y = aca.run()
......
......@@ -3,7 +3,6 @@ from scipy import spatial
import pandas as pd
import matplotlib.pyplot as plt
np.random.seed(6)
num_points = 25
points_coordinate = np.random.rand(num_points, 2) # generate coordinate of points
......@@ -25,8 +24,9 @@ aca = ACA_TSP(func=cal_total_distance, n_dim=num_points,
best_x, best_y = aca.run()
# %% Plot
fig, ax = plt.subplots(1, 1)
fig, ax = plt.subplots(1, 2)
best_points_ = np.concatenate([best_x, [best_x[0]]])
best_points_coordinate = points_coordinate[best_points_, :]
ax.plot(best_points_coordinate[:, 0], best_points_coordinate[:, 1], 'o-r')
ax[0].plot(best_points_coordinate[:, 0], best_points_coordinate[:, 1], 'o-r')
pd.DataFrame(aca.y_best_history).cummin().plot(ax=ax[1])
plt.show()
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册