Say I make a DiGraph in NetworkX:
import networkx as nx
G = nx.DiGraph()
n = ["A","B","C","D","E","F","H","I","J","K","L","X","Y","Z"]
e = [("A","Z"),("Z","B"),("B","Y"),("Y","C"),("C","G"),("G","H"),("G","I"),("I","J"),("K","J"),("J","L"),("F","E"),("E","D"),("D","X"),("X","C")]
G.add_nodes_from(n)
G.add_edges_from(e)
How would I remove all the nodes with a in-degree and an out-degree equal to 1, so that my graph would look like this?:
import networkx as nx
G = nx.DiGraph()
n = ["A","C","F","G","H","J","K","L"]
e = [("A","C"),("C","G"),("G","H"),("G","J"),("K","J"),("J","L")
G.add_nodes_from(n)
G.add_edges_from(e)
The idea is to remove the "flow-through" nodes and retain connectivity.