使用Dijkstra算法获得最大利润

编程入门 行业动态 更新时间:2024-10-23 04:46:58
本文介绍了使用Dijkstra算法获得最大利润的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

Dijkstra算法是解决最短路径问题的最快算法之一.在我的情况下,网络由节点组成,其中边的权重就是我获得的利润.我想知道是否可以逆转Dijkstra的算法来解决此问题,但是我意识到如果我们在闭环中运行(因为成本会越来越高,它将永远持续下去),那该怎么办.我知道如何将其作为整数编程问题来解决,因此我可以验证算法的正确性(不幸的是不能正确地进行校正).这是我一直在使用的Dijkstra的伪代码.正确的修改是什么?

Dijkstra algorithm is one of the fastest algorithm for solving the shortest path problem. In my case network is made up of nodes where the weight of the edge is the profit that I get. I was wondering if I could reverse Dijkstra's algorithm to solve this problem, but I realized what if we run in a closed loop (because cost will increase more and more it will go on forever). I know how to solve it as an integer programing problem so I can verify the correctness of algorithm(and not correct unfortunately). Here is pseudo code for Dijkstra that I have been using. What is correct modification to be done?

ln=∞ for all n∈N∖{s}, ls=0 N′={s}, N′′=∅ repeat n=argminn′∈N′ln′ N′=N′∖{n}, N′′=N′′∪{n} for all (n,m)∈A with m∈N∖N′′ do if lm>ln+cn,m then lm=ln+cn,m N′=N′∪{m} end if end for until (N′=∅ or t∈N′′)

推荐答案

这属于最长的问题路径问题.换句话说,没有有效的方法来找到未加权图结构中的最大路径(在您的情况下为最大利润). 但是,您提到这是一个加权图,所以如果图是非循环的,您仍然可以仍然有效地进行操作:

This falls under the issue of the Longest Path Problem. In other words, there is no efficient way to find max path (in your case, max profits) in an unweighted graph structure. However, you mentioned that it was a weighted graph, so you might still be able to still do it efficiently if your graph is acyclic:

加权图G中两个给定顶点s和t之间的最长路径与通过改变每个权重对其取负而从G得出的图-G中的最短路径相同.因此,如果最短可以在-G中找到路径,然后在G中也可以找到最长路径.对于大多数图形,此变换没有用,因为它在-G中创建了负长度的循环.但是,如果G是一个有向无环图,则不能创建负周期,并且通过对-G中的最短路径应用线性时间算法,可以在线性时间中找到G中的最长路径,这也是有向无环图." 如在 Wiki文章中可以看到.

"A longest path between two given vertices s and t in a weighted graph G is the same thing as a shortest path in a graph −G derived from G by changing every weight to its negation. Therefore, if shortest paths can be found in −G, then longest paths can also be found in G. For most graphs, this transformation is not useful because it creates cycles of negative length in −G. But if G is a directed acyclic graph, then no negative cycles can be created, and longest paths in G can be found in linear time by applying a linear time algorithm for shortest paths in −G, which is also a directed acyclic graph." as seen in the wiki article.

因此,如果您的图是非循环的,则实际上可以使用高效的算法来解决您的问题.但是,如果您的图不是非循环的,则没有已知的有效算法.

So, if your graph is acyclic, you can indeed use an efficient algorithm to solve your problem. However, if your graph is not acyclic, then there is no known efficient algorithm.

更多推荐

使用Dijkstra算法获得最大利润

本文发布于:2023-11-30 03:24:25,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1648559.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:算法   利润   Dijkstra

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!