Hello everyone, I'm curious as to whether it is possible to compare two graphs (g2 and g1) and build a graph object from the edges g2 has but g1 misses? In other words, create a graph object out of the edges in g2 that are unique to it compared to the edges in g1, given that both g1 and g2 have sources and targets that are the same. Ideally, it would be interesting to see how to do that regardless of whether someone is a source or a target in either graph (undirected). I know there is likely an involved way of doing this, but I'm wondering whether there is a novel approach to take. Any ideas? Thank you for your time. -- View this message in context: http://main-discussion-list-for-the-graph-tool-project.982480.n3.nabble.com/... Sent from the Main discussion list for the graph-tool project mailing list archive at Nabble.com.
On 11/01/2012 12:49 PM, cc wrote:
Hello everyone,
I'm curious as to whether it is possible to compare two graphs (g2 and g1) and build a graph object from the edges g2 has but g1 misses? In other words, create a graph object out of the edges in g2 that are unique to it compared to the edges in g1, given that both g1 and g2 have sources and targets that are the same. Ideally, it would be interesting to see how to do that regardless of whether someone is a source or a target in either graph (undirected).
I know there is likely an involved way of doing this, but I'm wondering whether there is a novel approach to take. Any ideas? Thank you for your time.
This seems pretty simple. Assuming the mapping between the vertices of g1, g2 and gdiff are given by their indexes, this is a simple loop: gdiff = Graph() gdiff.add_vertex(g1.num_vertices()) for e in g2.edges(): s, t = e e1 = g1.edge(int(s), int(t)) if e1 is None: gdiff.add_edge(int(s), int(t)) Also take a look at the topology.similarity() function. Cheers, Tiago -- Tiago de Paula Peixoto <tiago@skewed.de>
participants (2)
-
cc -
Tiago de Paula Peixoto