当前位置: 首页 > news >正文

电商网站模版公司网络平台搭建

电商网站模版,公司网络平台搭建,品牌型网站建设哪家好,长葛网站建设公司Dijkstra单源最短路径算法#xff0c;用于计算一个节点到其他所有节点的最短路径。主要特点是以起始点为中心向外层层扩展#xff0c;直到扩展到终点为止。Dijkstra算法是很有代表性的最短路径算法#xff0c;在很多专业课程中都作为基本内容有详细的介绍#xff0c;如数据…Dijkstra单源最短路径算法用于计算一个节点到其他所有节点的最短路径。主要特点是以起始点为中心向外层层扩展直到扩展到终点为止。Dijkstra算法是很有代表性的最短路径算法在很多专业课程中都作为基本内容有详细的介绍如数据结构图论运筹学等等。注意该算法要求图中不存在负权边。设G(V,E)是一个带权有向图把图中顶点集合V分成两组第一组为已求出最短路径的顶点集合(用S表示初始时S中只有一个源点以后每求得一条最短路径 , 就将加入到集合S中直到全部顶点都加入到S中算法就结束了)第二组为其余未确定最短路径的顶点集合(用U表示)按最短路径长度的递增次序依次把第二组的顶点加入S中。在加入的过程中总保持从源点v到S中各顶点的最短路径长度不大于从源点v到U中任何顶点的最短路径长度。此外每个顶点对应一个距离S中的顶点的距离就是从v到此顶点的最短路径长度U中的顶点的距离是从v到此顶点只包括S中的顶点为中间顶点的当前最短路径长度。python 算法实现import queuefrom collections import namedtupleEdge namedtuple(Edge, [vertex, weight])class GraphUndirectedWeighted(object):def __init__(self, vertex_count):self.vertex_count vertex_countself.adjacency_list [[] for _ in range(vertex_count)]def add_edge(self, source, dest, weight):assert source self.vertex_countassert dest self.vertex_countself.adjacency_list[source].append(Edge(dest, weight))self.adjacency_list[dest].append(Edge(source, weight))def get_edge(self, vertex):for e in self.adjacency_list[vertex]:yield edef get_vertex(self):for v in range(self.vertex_count):yield vdef dijkstra(graph, source, dest):q queue.PriorityQueue()parents []distances []start_weight float(inf)for i in graph.get_vertex():weight start_weightif source i:weight 0distances.append(weight)parents.append(None)q.put(([0, source]))while not q.empty():v_tuple q.get()v v_tuple[1]for e in graph.get_edge(v):candidate_distance distances[v] e.weightif distances[e.vertex] candidate_distance:distances[e.vertex] candidate_distanceparents[e.vertex] v# primitive but effective negative cycle detectionif candidate_distance -1000:raise Exception(Negative cycle detected)q.put(([distances[e.vertex], e.vertex]))shortest_path []end destwhile end is not None:shortest_path.append(end)end parents[end]shortest_path.reverse()return shortest_path, distances[dest]def main():g GraphUndirectedWeighted(9)g.add_edge(0, 1, 4)g.add_edge(1, 7, 6)g.add_edge(1, 2, 1)g.add_edge(2, 3, 3)g.add_edge(3, 7, 1)g.add_edge(3, 4, 2)g.add_edge(3, 5, 1)g.add_edge(4, 5, 1)g.add_edge(5, 6, 1)g.add_edge(6, 7, 2)g.add_edge(6, 8, 2)g.add_edge(7, 8, 2)# for testing negative cycles# g.add_edge(1, 9, -5)# g.add_edge(9, 7, -4)shortest_path, distance dijkstra(g, 0, 1)assert shortest_path [0, 1] and distance 4shortest_path, distance dijkstra(g, 0, 8)assert shortest_path [0, 1, 2, 3, 7, 8] and distance 11shortest_path, distance dijkstra(g, 5, 0)assert shortest_path [5, 3, 2, 1, 0] and distance 9shortest_path, distance dijkstra(g, 1, 1)assert shortest_path [1] and distance 0if __name__ __main__:main()
http://www.zqtcl.cn/news/767267/

相关文章:

  • 永平建设有限公司网站2023一般纳税人企业所得税怎么算
  • 创业网站推广怎么做简单的网站首页
  • 外贸网站模板 外贸网站制作如何推广宣传一个品牌
  • 中企动力企业邮箱 手机邮箱河南网站建设优化推广
  • 广州seo网站多少钱王野天津音乐广播电台图片
  • 东莞网站制作十强怎么做一个链接网站
  • 深圳网站设计 建设首选wordpress 获取父页面
  • 大兴企业网站建设公司wordpress谷歌字体优化
  • 哈尔滨建设银行网站网站建设运营服务商
  • 重庆本地建站企业网站建设流程及费用
  • 网站建设需要用到那些语言简述网站建设和推广评价指标
  • 17网站一起做 佛山印刷做网站网上接单
  • 网站建设步骤 优帮云网站建设首选定制开发
  • 专门做家居的网站国内企业网站设计
  • 做网站时怎么取消鼠标悬停性价比最高网站建设
  • 三网合一网站模板网站上内容列表怎么做
  • 鲜花商城网站建设西安房产网站大全
  • 家庭宽带做网站空间一个数据库可以做几个网站
  • 环境设计公司排名搜索引擎seo是什么意思
  • 北京网站建设策划排名长春市建设集团股份有限公司
  • 网站建设项目怎么跟进客户安阳哪里有做网站的
  • 重庆定制网站建设公司郑州网站模板
  • 网站 建设 领导小组wordpress下拉 友情链接
  • 做网站用php广州最新新闻
  • 福州市住房和城乡建设局网站18款禁用观看黄入口
  • 西安网站制作工作室网页怎么做成网站
  • 做h5网站公司百度知道网页入口
  • 网站建设 中企动力上海在线设计房屋效果图
  • 河南宝盈建设集团有限公司网站代理二级分销系统
  • 青岛高级网站建设价格对外宣传及网站建设文件稿