class Graph_matrix(object): def __init__(self): self.storage_matrix = [] self.node_list = [] def make_picture(self, matrix, _nodes): ''' :param matrix: 输入邻接矩阵 :return: ''' self.node_list = _nodes for m in matrix: self.storage_matrix.append(m) def dict_min_by_value(self,this_dict): ''' 字典里值最小的键 ''' min = 10 ** 10 key = '' for get_item in this_dict.items(): if get_item[-1]<min: min = get_item[-1] key = get_item[0] return key def get_node_index(self,node): ''' 找min_key在列表节点中的下标 ''' for i in xrange(len(self.node_list)): if node == self.node_list[i]: return i def dijkstra(self, start_node): over_node =
Python实现最短路径Dijkstra算法
最新推荐文章于 2024-02-13 21:52:24 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)