Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to add undirected and directed edges to a graph object in networkx?

I'm working on implementing an algorithm to determine the graphical structure of a dataset. The dataset could have undirected or directed edges between variables. I could create my own graph object in Python, but I was curious if Networkx has this capability. From what I've seen, Networkx only has a Graph object (only undirected edges) and a DiGraph object (for directed edges only). Is there a way to include directed edges in a undirected graph in Networkx and/or vice versa?

like image 722
m13op22 Avatar asked Apr 03 '19 13:04

m13op22


People also ask

Can a graph have both directed and undirected edges?

All the edges in a graph must be either DIRECTED or UNDIRECTED. The two types of edges cannot be mixed together. A graph that uses only DIRECTED EDGES is called a DIRECTED GRAPH. Likewise, a graph that uses only UNDIRECTED EDGES is called an UNDIRECTED GRAPH.

How do I add edges in NetworkX?

Add an edge between u and v. The nodes u and v will be automatically added if they are not already in the graph. Edge attributes can be specified with keywords or by directly accessing the edge's attribute dictionary.


1 Answers

networkx has no mixed graph handling. There were discussions about it, but the implementation had an impact on the whole library, so it was suspended. As I know, graph-tool and igraph has no this functionality too. If you are not satisfied by bidirected edges as undirected, I am afraid you should not use Python libraries, because it is impossible to have both directed and undirected edges in the most popular Python graph libraries: networkx, graph-tool and igraph.

like image 151
vurmux Avatar answered Nov 03 '22 18:11

vurmux