Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiply rooted graph similarity #4907

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

antonpibm
Copy link

Adding support for multiple roots in all similarity algorithms.

  • optimize_edit_paths and graph_edit_distance had support for a single root, I've extended the functionality to support multiple roots (multiply vertex-rooted graphs)
  • optimize_graph_edit_distance and optimal_edit_paths actually use optimize_edit_paths to search for results but didn't have support for roots, I've added it to those methods as well.

root_u, root_v = roots
if root_u not in pending_u or root_v not in pending_v:
raise nx.NodeNotFound("Root node not in graph.")
roots = [roots] if type(roots) == tuple else roots
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
roots = [roots] if type(roots) == tuple else roots
if isinstance(roots, tuple) and len(roots) == 2:
roots = [roots]

Comment on lines +1104 to +1105
initial_cost = sum(
[1 - node_match(G1.nodes[root_u], G2.nodes[root_v]) for root_u, root_v in roots])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be (1 - sum(node_match for all pairs of root nodes)) or sum( 1 - nodematch)??

Copy link
Member

@dschult dschult left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this looks pretty good. Sorry for the delay in review while we focused on release of NX v2.6. Can you add a paragraph to the doc_string explaining what it means to have multiply rooted graphs and how that affects the algorithm?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants