I was using steiner_tree approximation algorithm in NetworkX library. While feeding it a directed graph it showed me an error that
NetworkXNotImplemented: not implemented for directed type.
I also tried to convert the following graph to an undirected type, and feed the same. But I'm losing some information like edge directions.
How can I extract Steiner Tree on a Directed Graph?
You cannot get a solution to the directed Steiner tree problem from the undirected one. I would suggest to write out your directed graph and solve it with specialized software for directed Steiner tree problems. I don't know any
python package that is able to do that, the only software I know is:
https://scipjack.zib.de/
Related
I have managed to create a graph using pos tagging in pyvis. But unable to find methods to extract in_degree and out_degree similar to networkx.
Converting pyvis graph to networkx seems to be a solution. Is that possible?
The pyvis package is used to visualize graphs. Instead, NetworkX is a package for the creation, manipulation, and study of the structure, dynamics, and functions of graphs. Their goals are completely different. It wouldn't make any sense to have such functions in a tools meant for visualization only.
What you can do is using NetworkX to build the graph (and manipulate it) and then convert it into the pyvis format to visualize it. You can find an example in the official docs here.
Assume that we turned a UML diagram into a directed graph with labeled edges (edges has labels like "Association" or "Generalization"). Is there any way to find a specific subgraph, say finding the graph of the Factory design pattern in this graph using NetworkX APIs?
I have a directed bigraph that contains directed and undirected edges.
networkx_Graph = nx.read_adjlist('graph.txt', create_using=nx.DiGraph())
I was able to find the number of directed edges using: len(list(networkx_Graph.in_edges(data=False)))
But I am trying to find the number of undirected edges.
This is quite easy using the python package snap, but I am not finding anything like this in networkx's documentation?
What is the networkx equivalent of snap.CntUniqDirEdges()?
You have to convert the graph to an undirected graph the calculate the size. NetworkX does not have a function that does this in one shot like snap does.
networkx_Graph.to_undirected().size()
I'm looking for a way to visualize hierarchical data where there is a many to many relationship between parent and child - this is not a tree, but should be hierarchical like a tree. Is there a good package in R for doing this? I've looked at a few but they're either for visualizing trees or for visualizing graphs, but I'd like to visualize a graph that is also hierarchical.
I think you want to visualise a Directed Acyclic Graph (DAG). I.e. there are no cycles but each node may have multiple in-degree and out-degree. Graph libraries will usually visualise these correctly if you set the right parameters. I would recommend networkx for small/medium-sized graphs, or Gephi for large graphs (gephi is a GUI program but makes good visualisations). Networkx's Graphviz drawing backend will do a good job of drawing DAGs
https://networkx.github.io/documentation/latest/reference/algorithms.dag.html
http://gephi.github.io/
In other posts Networkx was suggested as "my friend". But there doesn't seem to be a ready to use function for a certain solution for the TSP problem.
i.e. Creating undirected graphs in Python
I have an undirected graph, the suggested solutions are all related to directed graphs, and I want to know a short tour to visit all nodes using the available edges.
(also, the tsp with directed graphs I could not find in the documentation of networkx)
Does anybody did something like this for an undirected graph or should I modify solutions for directed graphs with infinit costs for unconnected nodes?
edit: I am learning: Actually, as the graph is unweighted (or 'all weights' are the same), and not every node is connected to all other nodes, I just need to find a cycle in the graph containing all the nodes. When that cycle does not exist, nodes may be repeated (so, it is not a cycle anymore...). There are no isolated groups (there is a path from each node to another). I think that this is not the salesman problem?!
Thanks for your feedback so far (when milliseconds start to matter, I will install a photofinish :) )
If you already have code for directed graphs, I would just convert your undirected graph. Replace each undirected edge with two directed edges, one in each direction, preserving the edge weight.