简体   繁体   English

具有所需顶点的有向加权图

[英]Directed Weighted Graph with required vertices

Given: A directed, weighted graph G=(V, E), some of the vertices are red, some blue, and the rest white, weight Ti which is the maximum weight allowed to go from any vertex red vertex to any blue vertex.给定:一个有向加权图 G=(V, E),一些顶点是红色的,一些是蓝色的,rest 是白色的,权重 Ti 是允许从任何顶点红色顶点到任何蓝色顶点到 go 的最大权重。

Problem: Create an algorithm that finds a path from source node S, to target node T with least weight and which at some point goes from a red vertex to a blue vertex in at most Ti weight before reaching vertex T. The algorithm should have time complexity O(n^3)问题:创建一个算法,找到一条从源节点 S 到目标节点 T 的路径,权重最小,并且在到达顶点 T 之前从红色顶点到蓝色顶点的权重最大为 Ti。该算法应该有时间复杂度 O(n^3)

Comments: I'm not sure how to get started on this, I figure it's some variation of Dijkstra's algorithm and I've seen some people talking about making copies of the graphs and connecting the copies but beyond that, I'm not sure what the setup of this algorithm would look like.评论:我不确定如何开始这个,我认为这是 Dijkstra 算法的一些变体,我看到一些人谈论制作图表的副本并连接副本,但除此之外,我不确定是什么该算法的设置看起来像。 Any help would be appreciated.任何帮助,将不胜感激。

Indeed, you can use the copy-strategy as follows:实际上,您可以按如下方式使用复制策略:

Copy the graph G to G' and to G" . Label all vertices in G' as in G , but with the apostrophe. So there is an S' and a T' in G' . Similarly, S" and T" belong to G" .将图G复制到G'G" 。Label G'中的所有顶点与G中的一样,但带有撇号。因此G ' 中有一个S'和一个T' 。类似地, S"T"属于G”

Let S be the start vertex, and T" be the target. As it stands now, G , G' and G" are disconnected.S为起始顶点, T"为目标。就目前而言, GG'G"已断开连接。 But add the following zero-weight , directed edges:但是添加以下零权重有向边:

  • Edges from each red vertex r in G , to its mirror r' in G' .从 G 中的每个红色顶点rG '中的镜像r'的边。
  • Edges from each blue vertex b' in G' , to its mirror b" in G" .从 G' 中的每个蓝色顶点b'G"的镜像b"的边。

So there are no paths from G" to G' , nor from G' to G , nor from G" to G .因此,不存在从G"G' 、从G'G或从G"G的路径。

Now start a Dijkstra algorithm in S , with an additional data attribute for each entry in the priority queue: the weight that a path accumulated by edges in G' only .现在在S中启动 Dijkstra 算法,优先级队列中的每个条目都有一个额外的数据属性:一条路径G'中的边累积的权重。 Let's call this w' .我们称之为w' This w' plays no role in the priority of the queue.这个w'在队列的优先级中不起作用。 The total weight of a path determines the priority as is standard in Dijkstra's algorithm.路径的权重决定优先级,这是 Dijkstra 算法中的标准。 The algorithm should not expand paths whereby w' would exceed Ti .该算法不应扩展w'超过Ti的路径。 Besides that specific limitation, all the rest of the algorithm can remain as in the standard Dijkstra algorithm.除了该特定限制外,该算法的所有 rest 都可以保留为标准 Dijkstra 算法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM