编程语言
首页 > 编程语言> > 进化算法求解TSP问题

进化算法求解TSP问题

作者:互联网

描述

旅行商问题,即TSP问题(Traveling Salesman Problem)又译为旅行推销员问题、货郎担问题,是数学领域中著名问题之一。假设有一个旅行商人要拜访n个城市,他必须选择所要走的路径,路径的限制是每个城市只能拜访一次,而且最后要回到原来出发的城市。路径的选择目标是要求得的路径路程为所有路径之中的最小值。

方法

进化算法框架加上有利的重组算子(A Comparison of Genetic Sequencing Operators[1])

[1] Starkweather T, McDaniel S, Mathias K E, et al. A Comparison of Genetic Sequencing Operators[C]//ICGA. 1991: 69-76.

代码

下面是部分代码,完整代码太长,可在GitHub - busyxu/TSP找到

from TSP import input, init, select, fitness, crossover, mutation


if __name__ == '__main__':

    # 种群大小
    IndividualTotal = 200
    # 进化次数
    maxEvolve = 500
    # 交叉概率
    crossoverProbability = 0.7
    # 变异概率
    mutationProbability = 0.3

    citys = input.input_city()
    N = len(citys)
    dt = init.dt_function(citys)

    population = init.init_population(IndividualTotal, N)
    fitness.FitnessFunction(population, N, dt)
    for i in range(maxEvolve):

        if i % 20 == 0:
            num = []
            index = []
            best = select.BestIndividual(population)
            print(best)
            print('****************第', i, '代******************')

        population = select.vs_select(IndividualTotal, population) # 竞标赛选择算子
        # population = select.roulette_select(IndividualTotal, population) # 轮盘赌选择算子
        population = crossover.edge_crossover(N, population, crossoverProbability) # 边重组交叉算子 ER
        # population = crossover.oder_crossover(N, population, crossoverProbability) # 顺序交叉算子 OX
        # population = crossover.cycle_crossover(N, population, crossoverProbability)  # 循环交叉算子 CR
        # population = crossover.PMX_crossover(N, population, crossoverProbability)  # 部分匹配交叉算子 CR
        # population = crossover.position_based_crossover(N, population, crossoverProbability)  # 基于位置交叉算子  PBX
        population = mutation.mutation(N, population, mutationProbability)
        fitness.FitnessFunction(population, N, dt)

        pass
    best = select.BestIndividual(population)
    print('***************最优解**************')
    print(best)


MOEAs的相关研究及应用

参考

[2] Yang X, Zou J, Yang S, et al. A Fuzzy Decision Variables Framework for Large-scale Multiobjective Optimization[J]. IEEE Transactions on Evolutionary Computation, 2021.

[3] Zou J, Yang X, Liu Z, et al. Multiobjective Bilevel Optimization Algorithm Based on Preference Selection to Solve Energy Hub System Planning Problems[J]. Energy, 2021: 120995.

[4] Liu J, Yang X, Liu Z, et al. Investigation and evaluation of building energy flexibility with energy storage system in hot summer and cold winter zones[J]. Journal of Energy Storage, 2022, 46: 103877.

标签:__,crossoverProbability,求解,crossover,算法,select,算子,TSP,population
来源: https://blog.csdn.net/qq_35685675/article/details/122608310