Suppose there is a weighted directed graph, possibly with cycles
import neteorkx as nx
G = nx.DiGraph()
G.add_weighted_edges_from(
[
("a", "b", 10),
("b", "c", 10),
("c", "d", 10),
("d", "e", 5),
("d", "a", 3),
]
)
What is the proper way to reduce that graph such that all cycles are removed and the weights are adjusted accordingly?
e.g. in this example since the D -(3)-> A
edge is removed, we drop all weights in the path by 3, giving a reduced form of A -(7)-> B -(7)-> C -(7)-> D -(5)-> E
Does networkx provide a standardized algorithm for this, or do I need to implement this myself?
question from:
https://stackoverflow.com/questions/65859073/reducing-a-weighted-directed-graph-into-a-dag-with-networkx 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…