public bool AddArc(Arc arc) { Node node = Graph.U(arc); if (MaxDegree != null && Degree[node] >= MaxDegree(node)) { return(false); } DisjointSetSet <Node> a = components.WhereIs(node); Node node2 = Graph.V(arc); if (MaxDegree != null && Degree[node2] >= MaxDegree(node2)) { return(false); } DisjointSetSet <Node> b = components.WhereIs(node2); if (a == b) { return(false); } Forest.Add(arc); components.Union(a, b); Node key; Dictionary <Node, int> degree; (degree = Degree)[key = node] = degree[key] + 1; Node key2; (degree = Degree)[key2 = node2] = degree[key2] + 1; arcsToGo--; return(true); }
/// Tries to add the specified arc to the current forest. /// An arc cannot be added if it would either create a cycle in the forest, /// or the maximum degree constraint would be violated with the addition. /// \return \c true if the arc could be added. public bool AddArc(Arc arc) { var u = Graph.U(arc); if (MaxDegree != null && Degree[u] >= MaxDegree(u)) { return(false); } DisjointSetSet <Node> x = components.WhereIs(u); var v = Graph.V(arc); if (MaxDegree != null && Degree[v] >= MaxDegree(v)) { return(false); } DisjointSetSet <Node> y = components.WhereIs(v); if (x == y) { return(false); // cycle } Forest.Add(arc); components.Union(x, y); Degree[u]++; Degree[v]++; arcsToGo--; return(true); }
public IEnumerable <T> Elements(DisjointSetSet <T> aSet) { T element = aSet.Representative; yield return(element); /*Error: Unable to find new state assignment for yield return*/; }
public Node Merge(Node u, Node v) { DisjointSetSet <Node> a = nodeGroups.WhereIs(u); DisjointSetSet <Node> disjointSetSet = nodeGroups.WhereIs(v); if (a.Equals(disjointSetSet)) { return(a.Representative); } unionCount++; return(nodeGroups.Union(a, disjointSetSet).Representative); }
public DisjointSetSet <T> Union(DisjointSetSet <T> a, DisjointSetSet <T> b) { T representative = a.Representative; T representative2 = b.Representative; if (!representative.Equals(representative2)) { parent[representative] = representative2; next[GetLast(representative2)] = representative; last[representative2] = GetLast(representative); } return(b); }
public IEnumerable <T> Elements(DisjointSetSet <T> aSet) { T element = aSet.Representative; while (true) { yield return(element); if (!next.TryGetValue(element, out element)) { break; } } }
public DisjointSetSet <T> Union(DisjointSetSet <T> a, DisjointSetSet <T> b) { T x = a.Representative; T y = b.Representative; if (!x.Equals(y)) { parent[x] = y; next[GetLast(y)] = x; last[y] = GetLast(x); } return(b); }
public IEnumerable <Arc> Arcs(Node u, ArcFilter filter = ArcFilter.All) { DisjointSetSet <Node> x = nodeGroups.WhereIs(u); foreach (var node in nodeGroups.Elements(x)) { foreach (var arc in graph.Arcs(node, filter)) { bool loop = (U(arc) == V(arc)); // we should avoid outputting an arc twice if (!loop || !(filter == ArcFilter.All || IsEdge(arc)) || graph.U(arc) == node) { yield return(arc); } } } }
public IEnumerable <Arc> Arcs(Node u, ArcFilter filter = ArcFilter.All) { DisjointSetSet <Node> x = nodeGroups.WhereIs(u); foreach (Node item in nodeGroups.Elements(x)) { foreach (Arc item2 in graph.Arcs(item, filter)) { if (!(U(item2) == V(item2)) || (filter != 0 && !IsEdge(item2)) || graph.U(item2) == item) { yield return(item2); /*Error: Unable to find new state assignment for yield return*/; } } } yield break; IL_01db: /*Error near IL_01dc: Unexpected return in MoveNext()*/; }
public bool Equals(DisjointSetSet <T> other) { return(Representative.Equals(other.Representative)); }