26 using System.Collections.Generic;
37 public Func<Node, bool>
IsRed {
get;
private set; }
44 private readonly HashSet<Node> unmatchedRedNodes;
51 unmatchedRedNodes =
new HashSet<Node>();
60 unmatchedRedNodes.Clear();
62 if (
IsRed(n)) unmatchedRedNodes.Add(n);
70 public int GreedyGrow(
int maxImprovements =
int.MaxValue)
73 List<Node> matchedRedNodes =
new List<Node>();
74 foreach (var x
in unmatchedRedNodes)
80 matching.
Enable(arc,
true);
81 matchedRedNodes.Add(x);
83 if (result >= maxImprovements)
goto BreakAll;
88 foreach (var n
in matchedRedNodes) unmatchedRedNodes.Remove(n);
98 if (matching.
HasArc(arc))
return;
99 matching.
Enable(arc,
true);
101 unmatchedRedNodes.Remove(
IsRed(u) ? u :
Graph.
V(arc));
104 private Dictionary<Node, Arc> parentArc;
112 if (arc != matchedArc)
115 if (!parentArc.ContainsKey(y))
118 if (!matching.
HasNode(y))
return y;
119 Node result = Traverse(y);
127 if (!parentArc.ContainsKey(y))
129 parentArc[y] = matchedArc;
130 Node result = Traverse(y);
131 if (result !=
Node.Invalid)
return result;
142 List<Node> matchedRedNodes =
new List<Node>();
143 parentArc =
new Dictionary<Node, Arc>();
144 foreach (var x
in unmatchedRedNodes)
150 Node y = Traverse(x);
157 Arc arc = parentArc[y];
161 matching.
Enable(arc,
true);
163 y =
Graph.Other(arc2, z);
166 matchedRedNodes.Add(x);
170 foreach (var n
in matchedRedNodes) unmatchedRedNodes.Remove(n);