public CommunityStructure FindCommunityStructure(DGraph pGraph)
        {
            // Clone graph này ra để xử lý
            graph = pGraph.Clone();

            // Cộng đồng
            CommunityStructure tempCS = GetCommunityStructure();

            // Số cộng đồng
            int initCount      = tempCS.Count;
            int countCommunity = initCount;

            // Q
            _BestQ = 0;
            Q      = 0;

            // Tính edge betweenness lần đầu
            CalculateEdgeBetweenness(tempCS);

            // tính thuật toán
            int j = 0;

            while (true)
            {
                while (countCommunity <= initCount)
                {
                    WriteLog("Xóa lần " + j.ToString()); j++;
                    // Xóa cạnh có edge betweenness lớn nhất
                    List <DGraph> communities = RemoveMaxEdgeBetweenness(tempCS); // Xóa cạnh lớn nhất và cho biết community nào có cạnh được xóa

                    // Tính lại Edgebetweenness
                    CalculateEdgeBetweenness(tempCS, communities);

                    // Đếm lại số cộng đồng
                    tempCS         = GetCommunityStructure();
                    countCommunity = tempCS.Count;
                }

                initCount = countCommunity;

                // Tính Q
                Q = CalculateModularity(tempCS, pGraph);
                if (Q > _BestQ)
                {
                    _BestQ = Q;
                    Cs     = tempCS;
                }

                if (graph.Edges.Count == 0)
                {
                    break;
                }
            }

            return(this.Cs);
        }
Example #2
0
        public CommunityStructure FindCommunityStructure(DGraph pGraph)
        {
            // Clone graph này ra để xử lý
            graph = pGraph.Clone();

            // Cộng đồng
            CommunityStructure tempCS = GetCommunityStructure();

            // Số cộng đồng
            int initCount      = tempCS.Count;
            int countCommunity = initCount;

            // Tinh similarity cua tat ca cac node
            Dictionary <Node, List <Similarity> > hashMaxSimilarityNode = new Dictionary <Node, List <Similarity> >();

            // mỗi đỉnh là một community
            foreach (Node node in graph.Nodes)
            {
                // tinh similarity
                if (node.AdjacencyNodes.Count > 0)
                {
                    List <Similarity> lst = new List <Similarity>();

                    double max = double.MinValue;
                    foreach (Node neighborNode in node.AdjacencyNodes)
                    {
                        Similarity s = new Similarity();
                        s.node       = neighborNode;
                        s.similarity = ZLZSimilarity(node, neighborNode);

                        lst.Add(s);

                        if (s.similarity > max)
                        {
                            max = s.similarity;
                        }
                    }

                    // xử lý cái list đó trước rồi mới add vào
                    int n = lst.Count;
                    for (int i = 0; i < n; i++)
                    {
                        if (lst[i].similarity < max)
                        {
                            lst.RemoveAt(i);
                            n--;
                            i--;
                        }
                    }

                    if (lst.Count >= 2)
                    {
                    }

                    // add cái list này vào danh sách
                    hashMaxSimilarityNode.Add(node, lst);
                }

                // khoi tao cong dong
                DGraph com = new DGraph();
                com.Nodes.Add(node);
                tempCS.Add(com);
            }

            // chọn nút bất kì
            Random r          = new Random();
            int    nodeNumber = r.Next(0, graph.Nodes.Count);
            Node   initNode   = graph.Nodes[nodeNumber];

            return(this.Cs);
        }
Example #3
0
        public CommunityStructure FindCommunityStructure(DGraph pGraph)
        {
            // Clone graph này ra để xử lý
            originalGraph = pGraph;
            graph         = pGraph.Clone();

            // Cộng đồng
            CommunityStructure tempCS = GetCommunityStructure();

            // Số cộng đồng
            int initCount      = tempCS.Count;
            int countCommunity = initCount;

            // Q
            _BestVAD = 0;
            _VAD     = 0;
            _BestM   = 0;
            _M       = 0;

            // Tính edge betweenness lần đầu
            CalculateEdgeBetweenness(tempCS);
            CalculateVertexBetweenness(tempCS);

            WriteLog("Start CONGA algorithm");
            // tính thuật toán
            while (true)
            {
                while (countCommunity <= initCount)
                {
                    // Tìm tập hợp các đỉnh có vertex betweenness lớn hơn max edge betweenness:
                    // Thật chất là tìm max edge betweenness và max vertext betweenness
                    // Xóa cạnh có edge betweenness lớn nhất
                    RemoveEdgeOrSplitVertex(tempCS);

                    // Đếm lại số cộng đồng
                    tempCS = GetCommunityStructure();

                    countCommunity = tempCS.Count;

                    CalculateEdgeBetweenness(tempCS);
                    CalculateVertexBetweenness(tempCS);
                }

                initCount = countCommunity;

                // Tính Q = VAD
                if (_UseVAD)
                {
                    _VAD = CalculateVAD(tempCS);

                    if (_VAD > _BestVAD)
                    {
                        _BestVAD = _VAD;
                        Cs       = tempCS;
                    }
                }
                else
                {
                    _M = CalculateModularity(tempCS, originalGraph);

                    if (_M > _BestM)
                    {
                        _BestM = _M;
                        Cs     = tempCS;
                    }
                }

                if (graph.Edges.Count == 0)
                {
                    break;
                }
            }

            return(this.Cs);
        }