Ejemplo n.º 1
0
 private static void Visit(UndirectedGraph graph, IReporter reporter,
                           ISet <Vertex> candidates, ISet <Vertex> excluded, ImmutableArray <Vertex> cliqueInProgress)
 {
     Debug.Assert(candidates.All(v => graph.Degree(v) > 0));
     Debug.Assert(excluded.All(v => graph.Degree(v) > 0));
     Debug.Assert(!candidates.Overlaps(excluded));
     Debug.Assert(candidates.Any());
     while (candidates.Any())
     {
         var v                      = CollectionsUtil.PopArbitrary(candidates);
         var neighbours             = graph.Neighbours(v);
         var neighbouringCandidates = CollectionsUtil.Intersection(candidates, neighbours);
         if (neighbouringCandidates.Any())
         {
             var neighbouringExcluded = CollectionsUtil.Intersection(excluded, neighbours);
             Visit(graph, reporter,
                   neighbouringCandidates, neighbouringExcluded,
                   CollectionsUtil.Append(cliqueInProgress, v));
         }
         else if (CollectionsUtil.AreDisjoint(excluded, neighbours))
         {
             reporter.Record(CollectionsUtil.Append(cliqueInProgress, v));
         }
         var added = excluded.Add(v);
         Debug.Assert(added);
     }
 }
Ejemplo n.º 2
0
        public void Degree()
        {
            var graph = new UndirectedGraph <char, EdgeData>();

            graph.AddNodes('a', 'b', 'c', 'd', 'e');
            graph.AddEdges(
                ('a', 'b', dummyEdgeData),
                ('a', 'c', dummyEdgeData),
                ('a', 'd', dummyEdgeData),
                ('b', 'c', dummyEdgeData),
                ('b', 'd', dummyEdgeData),
                ('c', 'd', dummyEdgeData),
                ('c', 'e', dummyEdgeData)
                );

            graph.Degree('a').Should().Be(3);
            graph.Degree('b').Should().Be(3);
            graph.Degree('c').Should().Be(4);
            graph.Degree('d').Should().Be(3);
            graph.Degree('e').Should().Be(1);
        }