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

feat(matching): use the Hungarian Algorithm for unordered matching #50

Merged
merged 7 commits into from
May 1, 2024

Conversation

jpedroh
Copy link
Owner

@jpedroh jpedroh commented May 1, 2024

Our current approach to unordered node matching relies on a naive assumption: that all nodes possess an identifier. While this holds true for most nodes we've encountered thus far, such as method and property declarations within a Java class, it proves insufficient when attempting to match nodes lacking a label, like static blocks in Java. In such cases, calculations for matchings may yield incorrect results, consequently leading to erroneous merges.

This pull request introduces a solution for matching unordered nodes via the Assignment Problem, utilizing the Hungarian Algorithm to resolve it. This approach mirrors the one used in jDime.

Given the widespread recognition of the Hungarian Algorithm, we rely on the implementation provided by the pathfinding crate. This simplifies our implementation efforts, as we only need to provide the weights matrix and extract the matching information from the solution.

A workaround had to be implemented since pathfinding expects the input matrix weight to have the same number of rows and columns, which might not always be true in our case since nodes can have a different number of children. The solution involves initializing the remaining columns/rows with 0.

For now, our naive label implementation has been bypassed and is not being utilized. In a further pull request, the idea is to resort to the Hungarian algorithm only if the nodes are unlabeled, as it's significantly more complex than merely matching identifiers.

Copy link

codesandbox bot commented May 1, 2024

Review or Edit in CodeSandbox

Open the branch in Web EditorVS CodeInsiders

Open Preview

@coveralls
Copy link

coveralls commented May 1, 2024

Coverage Status

coverage: 86.126% (-0.3%) from 86.418%
when pulling eb9fe81 on feat-assignment-problem
into 31ea3c8 on main.

@jpedroh jpedroh marked this pull request as ready for review May 1, 2024 21:01
@jpedroh jpedroh merged commit fd5d943 into main May 1, 2024
8 checks passed
@jpedroh jpedroh deleted the feat-assignment-problem branch May 1, 2024 21:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants