I'd like to reduce a DAG by replacing each longest non-branching path by an edge connecting the start and the end of the path.
For example, for a graph like this, I'd like to reduce it
a->b->c->d
a->d
to the following. Of course, a real DAG can be more complex than this.
a->d
a->d
I don't find a way to do so with networkx. Does anybody know how to do so in network? Thanks.
As far as I know, Networkx doesn't support it out of the box. However it isn't too complicated to implement. You can simply iterate over the nodes in the graph, and follow the next steps:
This seems to work: