使用遗传算法求解:
代码转于知乎博主https://zhuanlan.zhihu.com/p/153098599
from math import floor
import numpy as np
import...self.select_num], :] = self.sub_sel
def main(data):
Path_short = Gena_TSP(data) # 根据位置坐标,生成一个遗传算法类...[index])
Path_short.best_path.append(Path_short.chrom[index, :])
return Path_short # 返回遗传算法结果类...data = np.array([149,663,170,511,303,287,404,707,520,490]).reshape(5,2)
main(data)
遗传算法尚未看懂,先用再说,运行结果如下