python - Efficiently finding the shortest path in large graphs -


I want to find a way in real time to find the smallest path between the nodes in a huge graph. There are thousands of corners and millions of edges. I know that this question has been asked before and I think the answer is wide-before using the search, but I am more interested in knowing which software you can use to implement it. For example, it would be completely perfect if it is already present in a library (with dragon binding) in the ungraded graph to do BF.

Added:

The comments made me curious how OPP was a problem in order to show pygraph, so I created a toy program to find out. Here's the output for a small version of the problem:

  $ python2.6 biggraph.py 4 6 large graph generating 10000 nodes 00:00:00 Biggraph generates 1000000 edges Are 00:00:00 add biggraph edges 00:00:05 biggraph Digg 00:01:32 biggraph done shortest_path 00:04:15 step: 1 9 15 2 step: 0 1 is used to walk biggraph: the way: [99 99 , 1915, 0]  

Not very bad for 10k nodes and 1M edges. It is important to keep in mind that the calculation of the diagram is calculated by pagraph Census is, each target relative to generate a dictionary of all spanning trees for each node (which was arbitrary node 0, and there was no Biseshadikarit position in the graph). Therefore, the solution that takes 3.75 minutes to solve is actually "What is the shortest route from all nodes to goal?" Got the answer. Actually, once the "code" was at least_path , the reply was simply an accomplished dictionary and basically did not take any time. It is also worth noting that adding the graph to pre-calculated edges was expensive in ~ 1.5 minutes. This time is consistent in many runs.

I would like to say that the process is well scalable, but I still am waiting on random computer at biggraph 5 6 (Athlon 64, 4800 per processor, In all core) which is running for more than a quarter hour. At least memory usage is stable at about 0.5 GB. And the results are in the following:

  Biggraph generated 100000 nodes 00:00:00 Biggrib generated 1000000 edges 00:00:00 Biggraph adds to the edges 00:00:07 Biggraph Dzra 00:01: 27 Biggraphs less than_pathped 00:23:44 Steps: 48437 Step 4: 66200 3 Steps: 83824 Step 2: 0 1 Walking Magnusen 00:23:44 Path: [99 99, 48437, 66200, 83824, 0]  

It is a long time, but it was also a heavy calculation (and I would really like to get results). Here's the code for the curious:

#! / Usr / bin / python import pygraph.classes.graph import pygraph.algorithms to pygraph.algorithms.minmax import random import SYS time if LAN (Sys.argv) = 3: print ( "Use% s: node_exponent edge_exponent '% Sys.argv [0]) sys.exit (1) nnodes = 10 ** int (sys.argv [1]) nedges = 10 * * int (sys.argv [2]) start_time = time.clock () DEP timestamp (S): t = time.gmtime (time.clock () - start_time) print 'biggraph', s.ljust (24), time timephamp ('% H:% M:% S', t) timestamp ('% D nodes generated '% nnodes) bg = pygraph.classes.graph.graph () bg.add_nodes (xrange (nnodes) timestamp (generate'% d edges% nedges) edges = set () while lane (qin S) & lt; Nedus: left, right = random. Randomization (node), random. Randering (node) if left == right: elif left & gt; Right: left, right = left, left edges. ((Left, right)) Add the timestamp ( "edges edge edges") to: Biji.ad_aj (edge) timestamp ( "Dijkstro") Target = 0 term, dist = Pygraph.algorithms.minmax.shortest_path (bg , Target) Timestamp ('shortest_path done') # The path from any node is in the specified duration, let's select # any arbitrary node (the last one) and go to the # target there, related distance # monotonically lastnode = nnodes less Will be - 1 path = [] lastnode! NextNode (lastnode) path.append (lastnode) lastnode = nextnode path.append (target) timestamp in the 'move:', nextnode, dist (lastnode) bg.neighbors in print: 'target: target: nextnode = span [lastnode] Walking ') print' path: ', path

Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -