@@ -43,20 +43,20 @@ private HashSet<MatchEdge<T>> getMaxBiPartiteMatching(IGraph<T> graph,
4343 while ( freeVerticesOnRight . Count > 0 )
4444 {
4545 var visited = new HashSet < T > ( ) ;
46- var paths = new HashSet < MatchEdge < T > > ( ) ;
46+ var path = new HashSet < MatchEdge < T > > ( ) ;
4747
4848 foreach ( var vertex in freeVerticesOnRight )
4949 {
50- var path = dfs ( graph ,
50+ var currentPath = dfs ( graph ,
5151 leftToRightMatchEdges , rightToLeftMatchEdges , vertex , default , visited , true ) ;
5252
53- if ( path != null )
53+ if ( currentPath != null )
5454 {
55- union ( paths , path ) ;
55+ union ( path , currentPath ) ;
5656 }
5757 }
5858
59- xor ( matches , paths , leftToRightMatchEdges , rightToLeftMatchEdges ) ;
59+ xor ( matches , path , leftToRightMatchEdges , rightToLeftMatchEdges ) ;
6060
6161 freeVerticesOnRight = bfs ( graph , partitions , leftToRightMatchEdges , rightToLeftMatchEdges ) ;
6262 }
@@ -81,14 +81,14 @@ private List<T> bfs(IGraph<T> graph,
8181 foreach ( var vertex in partitions [ 1 ] )
8282 {
8383 //if this left vertex is free
84- if ( ! leftToRightMatchEdges . ContainsKey ( vertex ) )
84+ if ( ! leftToRightMatchEdges . ContainsKey ( vertex ) && ! visited . Contains ( vertex ) )
8585 {
8686 queue . Enqueue ( vertex ) ;
87- visited . Add ( vertex ) ;
88-
87+
8988 while ( queue . Count > 0 )
9089 {
9190 var current = queue . Dequeue ( ) ;
91+ visited . Add ( vertex ) ;
9292
9393 //unmatched edges left to right
9494 foreach ( var leftToRightEdge in graph . GetVertex ( current ) . Edges )
0 commit comments