Open ntalluri opened 1 year ago
NetworkX has MultiGraph
and MultiDiGraph
classes, which allow parallel edges.
https://networkx.org/documentation/stable/reference/classes/index.html
I'm a little unclear how this affects the conversion of undirected to directed edges (I think in a DiGraph
the edge (1,2) and (2,1) are different). But we can talk at our meeting next week.
During my testing for directionality, I discovered that networkx digraph and graph do not allow multiple edges to exist between two nodes, instead rewriting the edge to the most recent one. In terms of introducing directionality, how we deal with the conversion from undirected to directed may be an issue. However, I wanted to put this out there in case we have a problem with this in the future. I'm still thinking about how I should handle the multiple edges in for the conversions, so if anyone has any suggestions, please put them here.
Here is some code to run to see the how to code is running under the hood:
import networkx as nx
D = nx.DiGraph() D.add_edge(1, 2, weight=1) print("Edges with attributes before adding a parallel edge for a Digraph:") print(D.edges(data=True)) D.add_edge(1, 2, weight=2) print("Edges with attributes after attempting to add a parallel edge for a Digraph:") print(D.edges(data=True)) D.add_edge(1, 2, weight=1) print("Edges with attributes after attempting to add a parallel edge for a Digraph:") print(D.edges(data=True)) G = nx.Graph() G.add_edge(1, 2, weight=1) print("Edges with attributes before adding a parallel edge for a Graph:") print(G.edges(data=True)) G.add_edge(1, 2, weight=2) print("Edges with attributes after attempting to add a parallel edge for Graph:") print(G.edges(data=True))