I have 2 Node types, where TypeA will always point to TypeB, TypeB has no outbound edges.
How can I indicate this as a directed graph using igraph?
First, you will need to install python-igraph if you do not have it already installed. You can use pip. You will also need to install cairocffi to plot the graphs. If you are using a Python package manager such as Anaconda or Miniconda, you can install python-igraph using the conda install command.
Add the nodes from any container (a list, dict, set or even the lines from a file or the nodes from another graph). In addition to strings and integers any hashable Python object (except None) can represent a node, e.g. a customized node object, or even another Graph. Edges: G can also be grown by adding edges.
The igraph library requires less resources for compilation, and comes with additional bindings for the R and C languages which the other two lack. NetworkX is comparatively very inefficient, but it is trivial to install --- requiring no compilation at all, since it is pure python.
A graph without cycles is called an acyclic graph. A directed graph without directed cycles is called a directed acyclic graph. A connected graph without cycles is called a tree.
https://igraph.org/python/doc/tutorial/generation.html#from-nodes-and-edges
g = Graph(directed=True)
g.add_vertices(2)
g.add_edges([(0,1)])
g.degree(mode="in") # -> [0, 1]
g.degree(mode="out") # -> [1, 0]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With