开发者

graph algorithm question

开发者 https://www.devze.com 2023-01-20 05:57 出处:网络
How can I find all available path for each Vertices which won\'t cause a cycle? What algorithm to use? Please be brief and provide links if possible, and ask questions if something is not clear from t

How can I find all available path for each Vertices which won't cause a cycle? What algorithm to use? Please be brief and provide links if possible, and ask questions if something is not clear from the wonderful diagram below :)

graph algorithm question

I am not looking for a shortest path or anything like that. Instead I just want to know which paths I can still draw on my graph without causing a loop/cycle. For example L4 can goto 开发者_开发百科L1, L2, L5 AND L2 can goto L5...and so on....

I guess I want a Directed acyclic graph and need help finding out which algorithm to use and how?


A shortest-path algorithm like Bellman-Ford or Dijkstra has the side effect of telling you which nodes you can reach from a given node "A" -- which is exactly the list of nodes from which edges to "A" would form a loop.

I suspect there is a way to modify Bellman-Ford to generate all these lists in one go, instead of running the algorithm separately for every node, but I'll leave that as an exercise for the reader. :)


Look the Ford Algorithm

http://en.wikipedia.org/wiki/Bellman%E2%80%93Ford_algorithm

Enjoy',


Following is not the answer but just a way to think for this problem.
You can think for the problem from the opposite side. Find all the paths that have exactly one edge missing to form a cycle(I havn't think of it, how). Then those missing edges are not the edges you are looking. Accept everything other than that.

0

精彩评论

暂无评论...
验证码 换一张
取 消