- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我正在尝试在 python 中实现 Yen 提出的 Bellman-Ford 算法的优化,以及 Bannister & Eppstein 提出的随机加速。
我正在关注 Bannister 和 Eppstein 关于该主题的论文,可以找到 here
我已经能够成功地实现原始的 Bellman-Ford 算法,一个包括算法提前终止的变体(当顶点距离没有变化时退出),以及 Yen 对算法的第一次改进(算法 3 in论文)。
但是,我在实现 Yen 的第二次改进和 Bannister-Eppstein 随机改进(论文中的算法 4 和 5)时遇到了一些麻烦。
论文中给出的Yen第二次改进的伪代码是
1. number the vertices arbitrarily, starting with s
2. C ← {s}
3. while C != ∅ do
4. for each vertex u in numerical order do
5. if u ∈ C or D[u] has changed since start of iteration then
6. for each edge uv in graph G+ do
7. relax(u, v)
8. for each vertex u in reverse numerical order do
9. if u ∈ C or D[u] has changed since start of iteration then
10. for each edge uv in graph G− do
11. relax(u, v)
12. C ← {vertices v for which D[v] changed}
Bannister-Eppstein 算法(算法 5)的伪代码与上面完全相同,除了第一行声明:
1. number the vertices randomly such that all permutations with s first are equally likely
我发现第 1 行和 (4,8) 行的语言令人困惑。
“任意/随机编号顶点”是什么意思?
按数字顺序遍历顶点是什么意思?
关于我的代码的一些附加信息:我的算法将 Graph 对象作为参数,该对象具有顶点 ([0,n]) 和边 ([source,destination,weight]) 的列表属性
编辑:论文中有关算法的一些额外信息:
"As Yen observed, it is also possible to improve the algorithm in a different way, by choosing more carefully the order in which to relax the edges within each iteration of the outer loop so that two correct relaxations can be guaranteed for each iteration except possibly the last. Specifically, number the vertices arbitrarily starting from the source vertex, let G+ be the subgraph formed by the edges that go from a lower numbered vertex to a higher numbered vertex, and let G− be the subgraph formed by the edges that go from a higher numbered vertex to a lower numbered vertex. Then G+ and G− are both directed acyclic graphs, and the numbering of the vertices is a topological numbering of G+ and the reverse of a topological numbering for G−. Each iteration of Yen’s algorithm processes each of these two subgraphs in topological order."
最佳答案
使用 Fisher--Yates 打乱 s 以外的顶点。例如,您可能有顶点 s、a、b、c、d、e、f 并洗牌到 f、a、c、e、d、b。然后就可以赋值连续的数s->0,f->1,a->2,c->3,e->4,d->5,b->6。数字顺序为 s、f、a、c、e、d、b。相反的数字顺序是 b、d、e、c、a、f、s。 G+ 中的边从编号较低的顶点到编号较高的顶点,例如 c->b。 G- 中的边从编号较高的顶点到编号较低的顶点。
关于python - Bellman-Ford 算法的 Yen's & Bannister-Eppstein 优化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53454427/
我最近在学习图形算法,在我的大学里我们被教导,Bellman-Ford 的结果是一个所有节点到所有其他节点的距离表(所有对最短路径)。但是我不明白这个算法是如何实现的,并试图通过观看 YouTube
一 点睛 如果遇到负权边,则在没有负环(回路的权值之和为负)存在时,可以采用 Bellman-Ford 算法求解最短路径。该算法的优点是变的权值可以是负数、实现简单,缺点是时间复杂度过高。但是该算法可
关闭。这个问题需要更多focused .它目前不接受答案。 想改进这个问题吗? 更新问题,使其只关注一个问题 editing this post . 关闭 1 年前。 Improve this qu
我正在阅读 Robert Sedgewick 编写的《算法》一书中的 Ford-Fulkerson maxflow 算法。这里作者提到如下 The number of augmenting paths
我对 Ford-Fulkerson 算法的分析结果不正确。例如,采用下图: _____>4___>_ | | 0--->1---->3------6 |
这是我的代码: #include #include #define inf 99999999 #define vertex 5 #define edge 6 int main(){ int d
我尝试编写 bellman-ford 算法,但我发现它不起作用。问题是,我(和我问过的任何人)都找不到错误,我认为这一定很简单。起初它似乎是正确的,因为对于我使用它的每个示例,它都很好用,但对于一些更
在具有 V 个节点和 E 条边的有向图中,Bellman-Ford 算法将每个顶点(或者更确切地说,从每个顶点发出的边)松弛 (V - 1) 次。这是因为从源到任何其他节点的最短路径最多包含 (V -
关于 Ford Fulkerson使用路径 s-x-y-z-t 的算法,我们必须找出如何增加沿该路径的流量。 我遇到的问题是,我不知道如何获取解决方案中的值。 谁能解释一下? 最佳答案 为了在 For
因此,如果我尝试使用 Bellman Ford 算法找到最短路径,使用此方法来测试是否存在路径: public boolean hasPath(int v){ return distTo[v]
我想在流网络 G 的所有最小割中找到积分容量,包含最少边数的容量。我们怎样才能修改 G 的容量以创建一个新的流网络 G',其中任何最小值G'中的割是G中边数最少的最小割。来源-Cormen 最佳答案
假设有一个有100-Vertexes 的有向图,例如V_1---> V_2 ---> ... ---> V_100 所有边的权重都是 1。我们想使用 Bellman-Ford 算法找到顶点 1 (V_
是否每个图都有边的顺序,以便在根据此顺序运行 Bellman-Ford 算法的单次迭代后,每个顶点都标有它到源的最短路径? 我很确定答案是肯定的,但我想不出能够找到边顺序的算法,谢谢 =] 最佳答案
我正在学习 Ford Fulkerson 算法,但我对向后边缘的用途以及它们如何帮助我们达到最大流量感到困惑。我已经观看了几个不同的视频并阅读了一些关于该算法的文档,但没有任何点击。也许这里有人可以用
我一直在搜索 Bellman-Ford 算法的空间复杂度,但是在 wikipedia Bellman-Ford Algorithm 上它说空间复杂度是 O(V)。在 this link它说 O(V^2
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 我们不允许提问寻求书籍、工具、软件库等的推荐。您可以编辑问题,以便用事实和引用来回答。 关闭 7 年前。
Suppose that we redefine the residual network to disallow edges into s. Argue that the procedure FOR
我不知道还有什么地方可以发布这个问题,我只想知道我是否正确地进行了跟踪。我得到了这张图 问题是: Show the trace of the Bellman-Ford algorithm on the
假设我们想使用 Bellman-Ford 来最小化 max_i x_i - min_i x_i 在变量 x_1, x_2, ... x_n 上(总共 n 个变量) 受到形式为 x_i - x_j <=
我正在尝试从 CLRS 实现 Bellman Ford 算法,它似乎在距离度量上随机溢出。我的代码如下: private void initSingleSource(Vertice source) {
我是一名优秀的程序员,十分优秀!