【发布时间】:2018-05-05 21:35:12
【问题描述】:
我从 Python 中的 DEAP 开始,并假装实现一个 GA 来解决 TSP problem。
我想知道是否可以创建一个城市名称(字符串)作为个人的列表。例如,个人可以是:["Madrid","Paris","London","Rome"]。
此时,我用整数表示城市:
creator.create("Individual", list, fitness=creator.FitnessMin)
IND_SIZE=8
toolbox = base.Toolbox()
toolbox.register("indices", random.sample, range(IND_SIZE), IND_SIZE)
toolbox.register("individual", tools.initIterate, creator.Individual, toolbox.indices)
【问题讨论】:
-
作为一般评论,您可以看看 Peter Norvig 在 Jupyter Notebook 中对 TSP 的出色演练。 github.com/norvig/pytudes/blob/master/ipynb/TSP.ipynb他对完整巡回演出的表现进行了反思。
-
有趣,谢谢分享。我的目标有点不同。我假装学习DEAP。此时,城市是整数,并且工作正常。我想知道有关城市使用字符串的信息。在那个链接中我找不到我的问题的答案。
标签: python genetic-algorithm deap