~ubuntu-branches/ubuntu/trusty/python-networkx/trusty-proposed

« back to all changes in this revision

Viewing changes to examples/basic/properties.py

  • Committer: Bazaar Package Importer
  • Author(s): Cyril Brulebois
  • Date: 2009-02-28 13:36:24 UTC
  • mfrom: (1.2.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20090228133624-9l5rwi1ftlzc7b0l
* Upload to unstable now that lenny is released (yay).
* Fix FTBFS with python-support 0.90.3: no longer rely on its internal
  behaviour, and xnow set tests/test.py executable right after “setup.py
  install” (Closes: #517065).
* Drop executable bits from bz2 files.
* Update Vcs-* fields: move from DPMT's svn to collab-maint's git.
* Remote DPMT from Uploaders, following Piotr Ożarowski's request.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
"""
 
3
Compute some network properties for the lollipop graph.
 
4
"""
 
5
#    Copyright (C) 2004 by 
 
6
#    Aric Hagberg <hagberg@lanl.gov>
 
7
#    Dan Schult <dschult@colgate.edu>
 
8
#    Pieter Swart <swart@lanl.gov>
 
9
#    Distributed under the terms of the GNU Lesser General Public License
 
10
#    http://www.gnu.org/copyleft/lesser.html
 
11
 
 
12
from networkx import *
 
13
 
 
14
G = lollipop_graph(4,6)
 
15
 
 
16
pathlengths=[]
 
17
 
 
18
print "source vertex {target:length, }"
 
19
for v in G.nodes():
 
20
    spl=single_source_shortest_path_length(G,v)
 
21
    print v,spl
 
22
    for p in spl.values():
 
23
        pathlengths.append(p)
 
24
 
 
25
print
 
26
print "average shortest path length ", sum(pathlengths)/len(pathlengths)
 
27
 
 
28
# histogram of path lengths 
 
29
dist={}
 
30
for p in pathlengths:
 
31
    if dist.has_key(p):
 
32
        dist[p]+=1
 
33
    else:
 
34
        dist[p]=1
 
35
 
 
36
print
 
37
print "length #paths"
 
38
verts=dist.keys()
 
39
verts.sort()
 
40
for d in verts:
 
41
    print d,dist[d]
 
42
 
 
43
print "radius: ",radius(G)
 
44
print "diameter: ",diameter(G)
 
45
print "eccentricity: ",eccentricity(G,with_labels=True)
 
46
print "center: ",center(G)
 
47
print "periphery: ",periphery(G)
 
48
print "density: ", density(G)
 
49