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

WIP: BipartiteGraph and Hopcroft-Karp algorithm in C++ #1481

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

Upabjojr
Copy link
Contributor

@Upabjojr Upabjojr commented Nov 25, 2018

This is not supposed to be merged. These are algorithms needed for the commutative matcher of MatchPy. We will need these algorithms to port RUBI into C++.

Class BipartiteGraph was translated from its Python implementation at MatchPy

The Hopcroft Karp algorithm is my implementation, which solves the issue of relying on the GPL'd Python library (dependency of MatchPy).

  • add license of MatchPy


//Node = Tuple[int, Union[TLeft, TRight]]
// typedef tuple<int, variant<TLeft, TRight>> Node; ???
typedef tuple<int, TItem> Node;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

TItem is either TLeft or TRight. We could have typedef variant<TLeft, TRight> TItem, but this is probably only supported in C++17. As an alternative, two separate fields could be used. This latter alternative would probably some quantity of code to be reviewed.

@certik certik changed the title BipartiteGraph and Hopcroft-Karp algorithm in C++ WIP: BipartiteGraph and Hopcroft-Karp algorithm in C++ Nov 25, 2018
@certik
Copy link
Contributor

certik commented Nov 25, 2018

Try to use the formatting that our clang-format configuration enforces. The biggest one is to use 4 spaces, instead of tabs.

@certik
Copy link
Contributor

certik commented Nov 26, 2018

@isuruf this is interesting. It looks like @Upabjojr applied the patch from our bot, but then the bot complained again. In particular, the bot first suggested the change:

-//(Generic[TLeft, TRight, TEdgeValue], MutableMapping[Tuple[TLeft, TRight], TEdgeValue])
+//(Generic[TLeft, TRight, TEdgeValue], MutableMapping[Tuple[TLeft, TRight],
+//TEdgeValue])

and after @Upabjojr applied it, our bot now suggests this one instead:

--- a/matchpygen/bipartite.h
+++ b/matchpygen/bipartite.h
@@ -22,7 +22,7 @@ const int RIGHT = 1;
 typedef map<tuple<int, int>, tuple<int, int>> Matching;
 
 //(Generic[TLeft, TRight, TEdgeValue], MutableMapping[Tuple[TLeft, TRight],
-//TEdgeValue])
+// TEdgeValue])
 /*
  * A bipartite graph representation.
  */

So the question is why didn't the bot suggest the correct (final) change in the first place?

@isuruf
Copy link
Member

isuruf commented Nov 27, 2018

@Upabjojr, thanks for your work on this. I have two questions on the design decisions.

  1. Do we need a TEdgeValue value? It seems unneeded.
  2. The graph keeps left and right nodes, with an int to denote left or right. Why not use two graphs, one for left and one for right?

@Upabjojr
Copy link
Contributor Author

Do we need a TEdgeValue value? It seems unneeded.

It's more generic, you can generalize the class usages to more types.

I am opening PRs to SymEngine, but that's only a temporary measure. We may decide to put the code in a separate project.

The graph keeps left and right nodes, with an int to denote left or right. Why not use two graphs, one for left and one for right?

I suppose you mean the _graph field, as the graph is only one. Right now, I am just translating the code written in Python in MatchPy. The usage of two separate class variables is an issue in MatchPy.

See HPAC/matchpy#43

@Upabjojr
Copy link
Contributor Author

Upabjojr commented Dec 2, 2018

Added Takeaki Uno's algorithm. New code has not yet been tested.

@symengine symengine deleted a comment from isuruf-bot Jan 11, 2019
@symengine symengine deleted a comment from isuruf-bot Jan 11, 2019
@symengine symengine deleted a comment from isuruf-bot Jan 11, 2019
@symengine symengine deleted a comment from isuruf-bot Jan 11, 2019
@symengine symengine deleted a comment from isuruf-bot Jan 11, 2019
@symengine symengine deleted a comment from isuruf-bot Jan 11, 2019
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.

None yet

3 participants