Code for negative edge cycle with in a graph

212 views
Skip to first unread message

mukt...@gmail.com

unread,
Mar 10, 2016, 12:00:36 PM3/10/16
to networkx-discuss
  Hello,
         I am working on complex network. I want to find all negative cycle or positive cycle within a graph ,
          i get function (negative_edge_cycle(g)) in negative cycle,but it returns true or false while i need to
         find all list and sum of weight of edges which involved make cycle.
         i am new in python can any one help me?

Daniel Schult

unread,
Mar 10, 2016, 12:12:26 PM3/10/16
to networkx...@googlegroups.com
You might be able to tweak the code in the bellman ford algorithm (which is what negative_edge_cycle uses).  At line 742 there is the heart of the algorithm called
_bellman_ford_relaxation.

I'll also give my usual qualifier that it is highly unlikely that you really want all negative cycles (or all cycles). Because cycles can be combined to create other cycles and there are just too many possibilities. You probably want some sort of cycle basis that covers all the cycles only once. Then to create other cycles you combine those basis cycles. 

Finally, you can find a cycle basis using edge weights equal to 1 (using something like cycle_basis) and then go back and compute the cycle weights using the true weights. Not sure if that is what you really want though.

Good luck!
Dan

--
You received this message because you are subscribed to the Google Groups "networkx-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to networkx-discu...@googlegroups.com.
To post to this group, send email to networkx...@googlegroups.com.
Visit this group at https://groups.google.com/group/networkx-discuss.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages