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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

308 CHAPTER 15. BASICS OF NETWORKS<strong>the</strong> edges are all considered one-way. Symmetries are not maintained au<strong>to</strong>matically, asillustrated in <strong>the</strong> following example:Code 15.8:>>> g = nx.DiGraph()>>> g.add_edge(’Josh’, ’Jess’)>>> g.edge[’Josh’][’Jess’][’love’] = True>>> g.edge{’Jess’: {}, ’Josh’: {’Jess’: {’love’: True}}}>>> g.edge[’Jess’][’Josh’][’love’]Traceback (most recent call last):File "", line 1, in g.edge[’Jess’][’Josh’][’love’]KeyError: ’Josh’>>>The last error message means that Jess doesn’t know a guy named Josh in this case,because <strong>the</strong> graph is asymmetric. Life is hard.Exercise 15.6<strong>of</strong> NetworkX.Represent <strong>the</strong> network shown in Exercise 15.1 as a Graph objectExercise 15.7 Represent a small social network around you (say, 10 people) asei<strong>the</strong>r Graph or DiGraph object <strong>of</strong> NetworkX. Then add properties <strong>to</strong> nodes <strong>and</strong>edges, such as:• Node properties: full name, age, job, address, etc.• Edge properties: relationship, connection weight, etc.In <strong>the</strong> examples above, we manually constructed network models by adding or removingnodes <strong>and</strong> edges. But NetworkX also has some built-in functions that can generatenetworks <strong>of</strong> specific shapes more easily. Here are a few examples:Code 15.9: networkx-test2.pyimport networkx as nx

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

Saved successfully!

Ooh no, something went wrong!