Python Forum

Full Version: Applied Graph Theory
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I am trying to a graph that consists of 100 vertices obtained by starting with 50 isolated vertices and a complete subgraph of 50 vertices (K50) and connecting each isolated vertex to all vertices in K50. This is what I have so far.


K50=nx.complete_graph(50)
K50.add_nodes_from(range(50,100))
nx.draw(K50)
I cannot figure out how to connect the isolated vertices to those in the subgraph. I have tried many things but can't seem to figure out, I thought it should be along the lines of 
K50.add_edges_from([(range(0,50),range(50,100))]
I have also tried 
e=zip(range(0,50),range(50,100))

K5.add_edges_from(e)
but this only connects one vertex from the subgraph to each isolated vertex not 50.
Any help would be appreciated, thanks!
Check out: https://pypi.python.org/pypi?%3Aaction=s...mit=search
There should be a package that will fit your needs
You need to add all requested edges, in your case you want to add "cartesian product" of the range(50) and the  range(50,100). An example with lower number of nodes/edges:

k10 = nx.complete_graph(10)
k10.add_nodes_from(range(10, 20))
k10.add_edges_from(((x, y) for x in range(10) for y in range(10,20)))
Resulting graph:

[Image: Km3x1Ns.png]