Lab 5 - Graphs with Sage (Feb 28/Mar 7, 2014)

Getting Sage Running

Sage is a free open-source mathematics package. Here are the basic ways to run sage for our course:

A little graph theory in Sage

First, Sage uses Python, so your familiarity with Python will give you a good start. You can do things in Sage the same was as in Python, but it has a whole bunch more built in so we can do lots of things more easily. If you like, you can go through a bit of the tutorial. For graph theory in Sage, the pages Sage in Graph Theory and Algebraic Graph Theory with Sage contain some instructions, and when all else fails, you can check the Sage Graph Theory Reference Manual.

We'll just go through a sample of some simple things you can do.

Constructing Graphs:

Graph Details: Given a graph G, you can get the

Graph Invariants: Given a graph G, you can get the

Here is a comprehensive list of generic (directed or undirected) graph functions.

Here are two examples of social networks you can play with.

Task 1: Using the graphs.RandomGNP(n,p) generate and plot several random graphs for n=20, p = 0.1. Here n is the number of vertices, and p is the probability of an edge between any pair of distinct vertices (i,j). (The probability p are identical and independent for all pairs of vertices.) What do you notice about the structure of such graphs? Do the same thing for various some different values of p, e.g., p=.05, .15, .2, .3, .5. Now what do you notice? How large should p be for this to usually be connected? Does this change if you take n=100? (You can use the function G.is_connected().)

Task 2: Write a function ddplot(G) that will graph the degree distribution of G. We can do this with a line plot or a bar chart, but let's use a bar chart. Use the bar_chart function on G.degree_histogram(). Now graph the degree distribution for our two social networks, as well as some random graphs. What do the degree distributions look like? Can you get similar degree distributions to the social network ones by using random graphs? (Use the same n, and figure out what p should be based on the number of edges to try to model these social networks.)



Labs Page
Course Home