public static void Explore(UndirectedGraph graph, IReporter reporter, Pivot.Choice pivotChoice) { var order = graph.Order; if (order == 0) { return; } var pivot = graph.MaxDegreeVertex(); // In this initial iteration, we don't need to represent the set of candidates // because all neighbours are candidates until excluded. var excluded = new HashSet <Vertex>(capacity: order); foreach (var v in Enumerable.Range(0, order).Select(Vertex.Nth)) { var neighbours = graph.Neighbours(v); if (neighbours.Any() && !neighbours.Contains(pivot)) { var neighbouringExcluded = CollectionsUtil.Intersection(neighbours, excluded); if (neighbouringExcluded.Count < neighbours.Count) { var neighbouringCandidates = CollectionsUtil.Difference(neighbours, neighbouringExcluded); Visit(graph, reporter, pivotChoice, neighbouringCandidates, neighbouringExcluded, ImmutableArray.Create <Vertex>(v)); } var added = excluded.Add(v); Debug.Assert(added); } } }
public static void Explore(UndirectedGraph graph, IReporter reporter, Pivot.Choice pivotChoice) { // In this initial iteration, we don't need to represent the set of candidates // because all neighbours are candidates until excluded. var excluded = new HashSet <Vertex>(capacity: graph.Order); foreach (var v in Degeneracy.Ordering(graph, drop: 1)) { var neighbours = graph.Neighbours(v); Debug.Assert(neighbours.Any()); var neighbouringExcluded = CollectionsUtil.Intersection(excluded, neighbours); if (neighbouringExcluded.Count < neighbours.Count) { var neighbouringCandidates = CollectionsUtil.Difference(neighbours, neighbouringExcluded); Pivot.Visit(graph, reporter, pivotChoice, neighbouringCandidates, neighbouringExcluded, ImmutableArray.Create(v)); } var added = excluded.Add(v); Debug.Assert(added); } }