On Fri, Feb 4, 2011 at 3:26 PM, Mike Hansen <mhan...@gmail.com> wrote: > On Fri, Feb 4, 2011 at 11:56 PM, Johannes <dajo.m...@web.de> wrote: >> Hi list >> how can i add a new edge (a->b) to a given graph G (n.n. connected), >> just in the case that there is no path (a -> ... -> b) before? > > You should use "shortest_path" which uses Dijkstra's algorithm under the hood. > > if g.shortest_path('a', 'b') == []: > g.add_edge('a', 'b')
Of course finding the shortest path may be (almost) as expensive as finding all of them... If you're doing this for a lot of edges you might want to break it up into components, then the test would be easy. It would be cool if all_paths were an iterator and you could just ask for the first one. - Robert -- To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-support URL: http://www.sagemath.org