简体   繁体   English

利用负循环找到图上两个节点之间零/负权重的路径

[英]Finding path of zero/Negative weight between Two Nodes on Graph by Utilizing Negative Cycles

I really struggled with describing this in the title but I'll give it a go in a longer format. 我确实很难在标题中对此进行描述,但是我将以更长的格式进行介绍。

I'm really stumped on this problem and I'm not looking for answers, just a little help or some specific topics to read up on. 我真的很困惑这个问题,我不是在寻找答案,只是需要一点帮助或需要阅读的一些特定主题。

What I have is a directed Graph with edges of various weights, both negative and positive. 我所拥有的是一个有向图,其边缘具有各种权重,包括负值和正值。 What I am attempting to do is to write an algorithm that is provided with two nodes positioned on the graph (and assuming they're connected) finds a path between them that results in the total weight of the path being either zero or negative. 我试图做的是编写一种算法,该算法提供了两个位于图上的节点(并假定它们已连接),它们之间找到一条路径,导致该路径的总权重为零或负。 The path can include nodes multiple times (hopefully allowing for the path to offset the positive weight of included edges). 该路径可以多次包含节点(希望允许该路径抵消包含的边的正权重)。

I'm currently reading Russel and Norvig's Artificial Intelligence, but am struggling to find a way to apply the logic in the text to my problem due to various problems (The algorithm continuously going round the negative cycle). 我目前正在阅读Russel和Norvig的《人工智能》,但是由于各种问题(算法不断绕负周期运行),我正努力寻找一种方法将文本中的逻辑应用于我的问题。 I'm not fully understanding how to utilize methods such as Backtrack and AStar for this 我对此并不完全了解如何利用Backtrack和AStar之类的方法

If anyone could point me in the right direction of something that would help me understand my problem better it would be a great help, I'm fine with dealing with DFS and BFS and many other things in relation to Graphs but having to find a path between two nodes with the weight restrictions is really baffling me. 如果有人能为我指明正确的方向,这可以帮助我更好地理解我的问题,那将是很大的帮助,我可以处理DFS和BFS以及与图有关的许多其他事情,但必须找到路径两个节点之间的重量限制确实让我感到困惑。

Thanks 谢谢

Below I've included a sample graph, I need to be able to find a path from Start to Goal where the total weight of the path doesn't exceed Zero. 下面,我提供了一个示例图,我需要能够找到从开始到目标的路径,其中路径的总权重不超过零。

Example Graph http://i144.photobucket.com/albums/r166/ZooropaTV/bu.jpg 图表示例http://i144.photobucket.com/albums/r166/ZooropaTV/bu.jpg

Just realised that a lot of the searching/Reading I've been doing has been misguided, since my goal isn't necessarily about finding the shortest path by weight, but by visiting the minimum required number of nodes, I need to have another think about it now, but still would like any advice 刚意识到我一直在做的很多搜索/阅读都被误导了,因为我的目标并不一定是找到按重量计的最短路径,而是通过访问最少的所需节点数,我需要重新思考一下关于它,但是仍然想要任何建议

I think this is what you want: The Floyd–Warshall algorithm http://en.wikipedia.org/wiki/Floyd%E2%80%93Warshall_algorithm 我认为这就是您想要的:Floyd–Warshall算法http://en.wikipedia.org/wiki/Floyd%E2%80%93Warshall_algorithm

You'll have to modify it to fit your needs but it will detect negative cycles thus allowing you to find a path of zero or lesser weight. 您必须对其进行修改以适合您的需求,但是它将检测到负循环,从而使您可以找到重量为零或更少的路径。

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

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