I am trying to implement the Hopcroft Karp algorithm in Python using networkx as graph representation.
Currently I am as far as this:
#Algorithms for
In python there is a package for this algorithm. HopcroftKarp, you can directly use that package for your implementation.
The line
if self.pair[v] and self.dfs(v):
should be
if self.pair[v] is None and self.dfs(v):
as per the pseudo-code on the Wikipedia page. The only other problem I see is that you are using the deque as a stack and you want to use it as a queue. To remedy that, you just need to popleft rather than pop (which pops right). So the line
v = self.q.pop()
should be
v = self.q.popleft()
Hopefully everything else works. I was just checking that your Python code works in the same manner as the pseudocode on Wikipedia so hopefully that pseudocode is correct.