public int GreedyGrow(int maxImprovements = int.MaxValue) { int num = 0; List <Node> list = new List <Node>(); foreach (Node unmatchedRedNode in unmatchedRedNodes) { foreach (Arc item in Graph.Arcs(unmatchedRedNode, ArcFilter.All)) { Node node = Graph.Other(item, unmatchedRedNode); if (matching.HasNode(node)) { continue; } matching.Enable(item, true); list.Add(unmatchedRedNode); num++; if (num < maxImprovements) { break; } goto IL_00ce; } } goto IL_00ce; IL_00ce: foreach (Node item2 in list) { unmatchedRedNodes.Remove(item2); } return(num); }
/// Grows the current matching greedily. /// Can be used to speed up optimization by finding a reasonable initial matching. /// \param maxImprovements The maximum number of arcs to grow the current matching with. /// \return The number of arcs added to the matching. public int GreedyGrow(int maxImprovements = int.MaxValue) { int result = 0; List <Node> matchedRedNodes = new List <Node>(); foreach (var x in unmatchedRedNodes) { foreach (var arc in Graph.Arcs(x)) { Node y = Graph.Other(arc, x); if (!matching.HasNode(y)) { matching.Enable(arc, true); matchedRedNodes.Add(x); result++; if (result >= maxImprovements) { goto BreakAll; } break; } } } BreakAll: foreach (var n in matchedRedNodes) { unmatchedRedNodes.Remove(n); } return(result); }