15.08.2015 Views

Introduction to the Modeling and Analysis of Complex Systems

introduction-to-the-modeling-and-analysis-of-complex-systems-sayama-pdf

introduction-to-the-modeling-and-analysis-of-complex-systems-sayama-pdf

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

17.2. SHORTEST PATH LENGTH 37717.2 Shortest Path LengthNetwork analysis can measure <strong>and</strong> characterize various features <strong>of</strong> network <strong>to</strong>pologiesthat go beyond size <strong>and</strong> density. Many <strong>of</strong> <strong>the</strong> <strong>to</strong>ols used here are actually borrowed fromsocial network analysis developed <strong>and</strong> used in sociology [60].The first measurement we are going <strong>to</strong> discuss is <strong>the</strong> shortest path length from onenode <strong>to</strong> ano<strong>the</strong>r node, also called geodesic distance in a graph. If <strong>the</strong> network is undirected,<strong>the</strong> distance between two nodes is <strong>the</strong> same, regardless <strong>of</strong> which node is <strong>the</strong>starting point <strong>and</strong> which is <strong>the</strong> end point. But if <strong>the</strong> network is directed, this is no longer<strong>the</strong> case in general.The shortest path length is easily measurable using NetworkX:Code 17.5:>>> g = nx.karate_club_graph()>>> nx.shortest_path_length(g, 16, 25)4The actual path can also be obtained as follows:Code 17.6:>>> nx.shortest_path(g, 16, 25)[16, 5, 0, 31, 25]The output above is a list <strong>of</strong> nodes on <strong>the</strong> shortest path from node 16 <strong>to</strong> node 25. Thiscan be visualized using draw_networkx_edges as follows:Code 17.7: shortest-path.pyfrom pylab import *import networkx as nxg = nx.karate_club_graph()positions = nx.spring_layout(g)path = nx.shortest_path(g, 16, 25)edges = [(path[i], path[i+1]) for i in xrange(len(path) - 1)]nx.draw_networkx_edges(g, positions, edgelist = edges,edge_color = ’r’, width = 10)

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!