File: expected_degree_sequence.py

package info (click to toggle)
python-networkx 1.9%2Bdfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 5,052 kB
  • ctags: 3,986
  • sloc: python: 52,132; makefile: 176
file content (28 lines) | stat: -rw-r--r-- 756 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/usr/bin/env python
"""
Random graph from given degree sequence.
"""
__author__ = """Aric Hagberg (hagberg@lanl.gov)"""
#    Copyright (C) 2006 by 
#    Aric Hagberg <hagberg@lanl.gov>
#    Dan Schult <dschult@colgate.edu>
#    Pieter Swart <swart@lanl.gov>
#    All rights reserved.
#    BSD license.

from networkx import *
from networkx.generators.degree_seq import *

# make a random graph of 500 nodes with expected degrees of 50
n=500 # n nodes
p=0.1
w=[p*n for i in range(n)] # w = p*n for all nodes
G=expected_degree_graph(w)  # configuration model
print("Degree histogram")
print("degree (#nodes) ****")
dh=degree_histogram(G)
low=min(degree(G))
for i in range(low,len(dh)):
    bar=''.join(dh[i]*['*'])
    print("%2s (%2s) %s"%(i,dh[i],bar))