高级算法作业1:生成案例

发布于:2023-09-14 ⋅ 阅读:(115) ⋅ 点赞:(0)

Task 1-1. Two examples to demonstrate the strength of the simple
nearest neighbor greedy algorithm. We can always obtain the optimal
solution independent of the choice of a start city.

1.我们需要一个贪婪算法
2.表示点的方式:坐标
3.可以把坐标转为图的软件

matplotlib 这个python库可以,相关代码如下

import matplotlib.pyplot as plt

def plot_coordinates(coordinates):
    x_values = [coord[0] for coord in coordinates]
    y_values = [coord[1] for coord in coordinates]

    plt.scatter(x_values, y_values)
    plt.xlabel('X')
    plt.ylabel('Y')
    plt.title('Coordinate Plot')
    plt.grid(True)
    plt.show()

# 用法示例
coordinates = [(1, 2), (3, 4), (5, 6)]  # 替换为您的坐标列表
plot_coordinates(coordinates)

4.进化突变算法