1.将python版本升级到3.9以上

安装networkx 3.x以上版本

import networkx as nx
import networkx.algorithms.approximation as nx_app 
# 使用最短路径规划算法
G = nx.random_geometric_graph(len(uav_point_list), radius=0.4, seed=3)
# Calculating the distances between the nodes as edge's weight.
for i in range(len(uav_point_list)):
    for j in range(i + 1, len(uav_point_list)):
        # print(i, j)
        dist = math.hypot(uav_point_list[i]["x"] - uav_point_list[j]["x"], uav_point_list[i]["y"] - uav_point_list[j]["y"])
        dist = dist
        G.add_edge(i, j, weight=dist)
cycle = nx_app.christofides(G, weight="weight")
uav_point_list_travle = [uav_point_list[_] for _ in cycle[0:-1]]
results_json = json.dumps(uav_point_list_travle).encode("utf-8")

Logo

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐