1:
| 2:
| 3:
|
4:
| 5:
| 6:
|
It can be easier to determine that two graphs are not isomorphic than to show that they are. Which property of the nodes can be used to determine that two graphs are not isomorphic?
sys.path.append('/home/cs170/networkx/')
from networkx import *
Commands for creating a graph and adding nodes and edges:
G=Graph() ### initialises a new graph
G.add_node("One")
G.add_nodes_from(["Hello","World"]) ### adding a list of nodes
G.add_edge("Hello","World")
G.add_edges_from([("One","Hello"),("One","World")])
H= DiGraph(G) ### creates a directed graph using G
G.clear() ### removes all nodes and edges from a graph
Commands for displaying nodes and edges:
G.nodes() G.edges()
write_gif(G,"filename")Instead of filename you should type a name of a file (without extension). After executing the command, two files, filename.gif and filename.dot (which can be ignored), will appear in the current directory. You can view the gif file via your I:-drive.
The software that creates the layouts is called Graphviz. These layout options are available:
| write_gif(G,"filename") | hierarchical layout |
| write_gif(G,"filename","neato") | spring model layout |
| write_gif(G,"filename","fdp") | another spring model layout |
| write_gif(G,"filename","twopi") | radial layout |
| write_gif(G,"filename","circo") | circular layout |
This website has more information about Graphviz and the different types of layouts.
(Note: the write_gif function is only available on DCS. Here is information on how to use Graphviz on other computers.)
4) NetworkX provides many standard graphs. Try different layouts for these:
G1=house_x_graph()
G2=complete_bipartite_graph(3,5)
G3=lollipop_graph(10,20)
Where did you see the House Graph in the lecture?
6) Determine the chromatic number of the graphs. (The chromatic number is the minimum number of colours needed to colour a graph so that neighbouring nodes have different colours.)
7) Which of the graphs have a Hamiltonian or Eulerian path?