From 9c3bce48cffab1041b26f26f0e67b9ef46ae9e0f Mon Sep 17 00:00:00 2001 From: guofei9987 Date: Thu, 26 Dec 2019 20:18:53 +0800 Subject: [PATCH] version 0.5.4 --- README.md | 6 +++--- docs/en/README.md | 6 +++--- docs/make_doc.py | 4 ++++ docs/zh/README.md | 6 +++--- examples/demo_aca_tsp.py | 6 +++--- 5 files changed, 16 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 3d7b95b..5fb5b76 100644 --- a/README.md +++ b/README.md @@ -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() diff --git a/docs/en/README.md b/docs/en/README.md index a9ec1ae..edfd741 100644 --- a/docs/en/README.md +++ b/docs/en/README.md @@ -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() diff --git a/docs/make_doc.py b/docs/make_doc.py index 76f1f6f..c2b5b05 100644 --- a/docs/make_doc.py +++ b/docs/make_doc.py @@ -12,6 +12,8 @@ 需要从py文件中解析出: 1. # %% 做断点后赋予index值,然后插入readme ''' +import os +import sys import re @@ -93,3 +95,5 @@ def make_doc(origin_file): docs_new = make_doc(origin_file=i) with open(i, encoding='utf-8', mode="w") as f: f.writelines(docs_new) + +sys.exit() diff --git a/docs/zh/README.md b/docs/zh/README.md index 4356e92..450ab5b 100644 --- a/docs/zh/README.md +++ b/docs/zh/README.md @@ -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() diff --git a/examples/demo_aca_tsp.py b/examples/demo_aca_tsp.py index 640cf32..0e49794 100644 --- a/examples/demo_aca_tsp.py +++ b/examples/demo_aca_tsp.py @@ -3,7 +3,6 @@ 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 @@ def cal_total_distance(routine): 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()