Skip to content

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

Open
Upabjojr wants to merge 8 commits into
symengine:mainfrom
Upabjojr:matchpy_symengine
Open

Upabjojr wants to merge 8 commits into
symengine:mainfrom
Upabjojr:matchpy_symengine

Conversation

@Upabjojr

@Upabjojr Upabjojr commented Nov 25, 2018 •

Copy link
Copy Markdown
Contributor

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

Comment thread matchpygen/bipartite.h Outdated

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

Copy link
Copy Markdown
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

certik commented Nov 25, 2018

Copy link
Copy Markdown
Contributor

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

@certik

certik commented Nov 26, 2018

Copy link
Copy Markdown
Contributor

@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

isuruf commented Nov 27, 2018

Copy link
Copy Markdown
Member

@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
Copy Markdown
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

Upabjojr commented Dec 2, 2018

Copy link
Copy Markdown
Contributor Author

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

This branch has not been deployed

No deployments
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.

3 participants