Mercurial > public > think_complexity
annotate ch5ex6-3.py @ 47:2b0e229e163c
Chapter 7, exercise 2. R-Pentomino game of life.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Thu, 25 Jul 2013 21:53:44 -0500 |
parents | 305cc03c2750 |
children |
rev | line source |
---|---|
bgneal@36 | 1 """Chapter 5.5, exercise 6 in Allen Downey's Think Complexity book. |
bgneal@36 | 2 |
bgneal@36 | 3 3. Use the BA model to generate a graph with about 1000 vertices and compute the |
bgneal@36 | 4 characteristic length and clustering coefficient as defined in the Watts and |
bgneal@36 | 5 Strogatz paper. Do scale-free networks have the characteristics of |
bgneal@36 | 6 a small-world graph? |
bgneal@36 | 7 |
bgneal@36 | 8 """ |
bgneal@36 | 9 |
bgneal@36 | 10 from ch5ex6 import BAGraph |
bgneal@36 | 11 |
bgneal@36 | 12 g = BAGraph(5, 5) |
bgneal@36 | 13 |
bgneal@36 | 14 for i in xrange(1000): |
bgneal@36 | 15 g.step() |
bgneal@36 | 16 |
bgneal@36 | 17 g.set_edge_length(1) |
bgneal@36 | 18 print "Clustering coefficient:", g.clustering_coefficient() |
bgneal@36 | 19 print "Characteristic length:", g.big_l3() |