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.

352 CHAPTER 16. DYNAMICAL NETWORKS I: MODELINGg.pos = nx.spring_layout(g)g.count = 0def observe():global gcla()nx.draw(g, pos = g.pos)def update():global gg.count += 1if g.count % 20 == 0: # rewiring once in every 20 stepsnds = g.nodes()i = rd.choice(nds)if g.degree(i) > 0:g.remove_edge(i, rd.choice(g.neighbors(i)))nds.remove(i)for j in g.neighbors(i):nds.remove(j)g.add_edge(i, rd.choice(nds))# simulation <strong>of</strong> node movementg.pos = nx.spring_layout(g, pos = g.pos, iterations = 5)import pycxsimula<strong>to</strong>rpycxsimula<strong>to</strong>r.GUI().start(func=[initialize, observe, update])The initialize function creates a ring-shaped network <strong>to</strong>pology by connecting eachnode <strong>to</strong> its k nearest neighbors (j ∈ {1, . . . , k/2}). “% n” is used <strong>to</strong> confine <strong>the</strong> names<strong>of</strong> nodes <strong>to</strong> <strong>the</strong> domain [0,n−1] with periodic boundary conditions. An additional attributeg.count is also created in order <strong>to</strong> count time steps between events <strong>of</strong> <strong>to</strong>pologicalchanges. In <strong>the</strong> update function, g.count is incremented by one, <strong>and</strong> <strong>the</strong> r<strong>and</strong>om edgerewiring is simulated in every 20 steps as follows: First, node i is r<strong>and</strong>omly chosen, <strong>and</strong><strong>the</strong>n one <strong>of</strong> its connections is removed. Then node i itself <strong>and</strong> its neighbors are removedfrom <strong>the</strong> c<strong>and</strong>idate node list. A new edge is <strong>the</strong>n created between i <strong>and</strong> a node r<strong>and</strong>omlychosen from <strong>the</strong> remaining c<strong>and</strong>idate nodes. Finally, regardless <strong>of</strong> whe<strong>the</strong>r a r<strong>and</strong>omedge rewiring occurred or not, node movement is simulated using <strong>the</strong> spring_layout

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

Saved successfully!

Ooh no, something went wrong!