Skip to content

Commit

Permalink
Merge branch 'develop' into beta
Browse files Browse the repository at this point in the history
  • Loading branch information
justcoding121 committed Apr 21, 2021
2 parents b48149e + a9936c7 commit b253374
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/Advanced.Algorithms/Graph/Matching/HopcroftKarp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,20 +43,20 @@ private HashSet<MatchEdge<T>> getMaxBiPartiteMatching(IGraph<T> graph,
while (freeVerticesOnRight.Count > 0)
{
var visited = new HashSet<T>();
var paths = new HashSet<MatchEdge<T>>();
var path = new HashSet<MatchEdge<T>>();

foreach (var vertex in freeVerticesOnRight)
{
var path = dfs(graph,
var currentPath = dfs(graph,
leftToRightMatchEdges, rightToLeftMatchEdges, vertex, default, visited, true);

if (path != null)
if (currentPath != null)
{
union(paths, path);
union(path, currentPath);
}
}

xor(matches, paths, leftToRightMatchEdges, rightToLeftMatchEdges);
xor(matches, path, leftToRightMatchEdges, rightToLeftMatchEdges);

freeVerticesOnRight = bfs(graph, partitions, leftToRightMatchEdges, rightToLeftMatchEdges);
}
Expand All @@ -81,14 +81,14 @@ private List<T> bfs(IGraph<T> graph,
foreach (var vertex in partitions[1])
{
//if this left vertex is free
if (!leftToRightMatchEdges.ContainsKey(vertex))
if (!leftToRightMatchEdges.ContainsKey(vertex) && !visited.Contains(vertex))
{
queue.Enqueue(vertex);
visited.Add(vertex);


while (queue.Count > 0)
{
var current = queue.Dequeue();
visited.Add(vertex);

//unmatched edges left to right
foreach (var leftToRightEdge in graph.GetVertex(current).Edges)
Expand Down

0 comments on commit b253374

Please sign in to comment.