erik
erik

Reputation: 3880

Connecting two separate networks with an edge while retaining individual memory objects

I am not necessarily looking to merge two networkx graphs as seen in this kind of question. What I would like to do is have n graphs held separately in memory, and have the capability to connect each graph via an edge. I don't want to merge them into a larger graph as I'm anticipating each sub-graph will take up a reasonable amount of memory as is, and I'd like to be able to separate out memory objects for parallel processing purposes.

Effectively, I'd like to link GraphA, NodeX to GraphB, NodeY via EdgeXA_BY, however that edge doesn't create a new supergraph in a variable (i.e., ballooning GraphA to comprise ALL edges/nodes from GraphB).

If I'm traversing GraphA and I need to get to GraphB, I can follow that edge to the memory object.

Is such a thing possible in NetworkX or do I need to have some internal mapping of graph objects that would load each sub-graph into memory as required?

Upvotes: 0

Views: 55

Answers (1)

Joel
Joel

Reputation: 23887

The nodes of a graph can be a graph.

import networkx as nx
G=nx.Graph()
H=nx.Graph()
S=nx.Graph() #the (super)graph of graphs
H.add_edge(1,2)
G.add_edge('parrot','Norway')
S.add_edge(H,G)
S.edges()
> [(<networkx.classes.graph.Graph at 0x1063dd390>,
  <networkx.classes.graph.Graph at 0x1063dd350>)]
S.neighbors(H)
> [<networkx.classes.graph.Graph at 0x1063dd390>]

There's probably a way to get it to return these with the name you want assigned rather than the default type and memory location. I don't know how to do that offhand - if someone does, leave a comment so I can update this answer.

Upvotes: 1

Related Questions