Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Applied Graph Theory
#1
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!
Reply
#2
Check out: https://pypi.python.org/pypi?%3Aaction=s...mit=search
There should be a package that will fit your needs
Reply
#3
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]
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Queuing Theory in Python NOLA_Saints 0 770 Feb-22-2023, 11:42 PM
Last Post: NOLA_Saints
  Theory behind referencing a dictionary rather than copying it to a list sShadowSerpent 2 2,074 Mar-24-2020, 07:18 PM
Last Post: sShadowSerpent
  lower() applied at in operator Beerforfree 3 2,305 Mar-22-2020, 11:51 AM
Last Post: ndc85430
  Theory question on grid neighbors Clunk_Head 9 3,771 Dec-16-2019, 11:23 PM
Last Post: ichabod801
  Strip does not work when applied on a string read from a text file. susmis666 1 2,387 Dec-27-2018, 07:07 AM
Last Post: perfringo
  How recursion function is applied? dukoolsharma 2 2,617 Dec-06-2018, 12:35 PM
Last Post: himanibansal

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020