コード例 #1
0
        private void BronKerbosch(SortedDictionary <int, List <List <int> > > distribution, int recStep,
                                  List <int> r, List <int> p, List <int> x)
        {
            // If p and x are both empty:
            if (p.Count == 0 && x.Count == 0)
            {
                // Report r as a maximal clique
                // TODO should be opened

                /*List<List<int>> d = distribution.computeIfAbsent(r.Count, k-> new HashSet<>());
                 * d.Add(r);*/
                return;
            }

            // for each vertex v in p:
            List <int> vertices = p;

            foreach (int v in vertices)
            {
                // bronKerbosch(r ⋃ {v}, p ⋂ n(v), x ⋂ n(v))
                List <int> nv = container.GetAdjacentVertices(v);
                BronKerbosch(distribution, recStep + 1, Union(r, v), Intersect(p, nv), Intersect(x, nv));

                // p = p \ {v}
                p = Subtract(p, v);
                // x = x ⋃ {v}
                x = Union(x, v);
            }
        }
コード例 #2
0
        private void BFS(int i, Node[] nodes)
        {
            Debug.Assert(i >= 0 && i < nodes.Length);

            nodes[i].lenght = nodes[i].ancestor = 0;
            bool        b = true;
            Queue <int> q = new Queue <int>();

            q.Enqueue(i);
            if (edgesBetweenNeighbours[i] == -1)
            {
                edgesBetweenNeighbours[i] = 0;
            }
            else
            {
                b = false;
            }

            while (q.Count != 0)
            {
                int        u = q.Dequeue();
                List <int> l = container.GetAdjacentVertices(u);
                for (int j = 0; j < l.Count; ++j)
                {
                    if (nodes[l[j]].lenght == -1)
                    {
                        nodes[l[j]].lenght   = nodes[u].lenght + 1;
                        nodes[l[j]].ancestor = u;
                        q.Enqueue(l[j]);
                    }
                    else
                    {
                        if (nodes[u].lenght == 1 && nodes[l[j]].lenght == 1 && b)
                        {
                            ++edgesBetweenNeighbours[i];
                        }
                    }
                }
            }
            if (b)
            {
                edgesBetweenNeighbours[i] /= 2;
            }
        }