Hello Tiago and Tanguy,

I'm following your discussion with great interest as I have a similar
task. I want to convert a multigraph into a simple graph. This works
very nicely with

GraphView(u, efilt=label_parallel_edges(u).fa == 0)

However, removing the parallel edges this way means that the edge
properties of the parallel edges are lost. I have an edge property
called "eqntag" which is a string and I want to concatenate all eqntags
from the parallel edges into the simple graph. I think this is what
Tanguy meant by "edge coalescence". I did not understand how to use
condensation_graph() for this purpose, so I've written my own function:

def remove_parallel_edges_merge_eqntags(g):
    # create simple graph g2:
    g2 = gt.GraphView(g, efilt=gt.label_parallel_edges(g).fa == 0)
    # loop over the remaining edges in the simple graph:
    for e in g2.edges():
        # create a list with all edges from g that connect the same
        # vertices as the current edge in g2:
        edgelist = g.edge(e.source(), e.target(), all_edges=True)
        # replace eqntag by semicolon-separated merged eqntag:
        g2.ep.eqntag[e] = ';'.join([g.ep.eqntag[edge] for edge in edgelist])
    return g2

Best regards
Rolf 




--
Sent from: 
http://main-discussion-list-for-the-graph-tool-project.982480.n3.nabble.com/
_______________________________________________
graph-tool mailing list
[email protected]
https://lists.skewed.de/mailman/listinfo/graph-tool

Reply via email to