tsp.py 文件源码

python
阅读 24 收藏 0 点赞 0 评论 0

项目:travelling_sales_person_AI 作者: jana-uoft 项目源码 文件源码
def draw_final_path(state):
    '''Draw the TSP path given the cities in the correct order'''
    if not state:
        return None

    states = []
    while state:
        states.append(state)
        state = state.parent    

    cities = [state.current_city for state in states]
    rest = deepcopy(cities)
    rest = rest[1:]
    rest.reverse()
    cities = [cities[0]] + rest

    turtle.clear()
    turtle.hideturtle()
    turtle.up()
    turtle.pensize(1)

    for city in cities:
        x = city.position[0]
        y = city.position[1]
        turtle.pencolor("red")
        turtle.goto(x, y)
        turtle.pencolor("black")

        if city.is_start:
            turtle.write('{}-Start'.format(city.name), align="center", font=("Arial", 11, "bold"))
        else:
            turtle.write('{}'.format(city.name), align="center",  font=("Arial", 11, "bold"))

        turtle.down()

    turtle.pencolor("red")
    turtle.goto(cities[0].position[0], cities[0].position[1])
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号