Esempio n. 1
0
        public void CLECCEqualsHalf()
        {
            // 0          4
            // | \      / |
            // |  2 -- 3  |
            // | /      \ |
            // 1          5
            var actors = ActorHelper.Get(6);
            var edges  = new List <Edge>
            {
                new Edge(actors[0], actors[1]),
                new Edge(actors[0], actors[2]),
                new Edge(actors[1], actors[2]),
                new Edge(actors[2], actors[3]),
                new Edge(actors[3], actors[4]),
                new Edge(actors[3], actors[5]),
                new Edge(actors[4], actors[5])
            };
            var edge   = edges[1];
            var layers = new List <Layer>
            {
                new Layer(edges),
                new Layer(edges),
            };
            var network = new Network(layers, actors);
            var clecc   = CLECC.GetCLECC(network, edge, 2);

            Assert.Equal(0.5, clecc);
        }
        /// <summary>
        /// Community detection based on CLECC (cross-layer edge clustering coefficient) measure.
        /// </summary>
        /// <param name="network">
        /// Network on which the community detection will be applied.
        /// </param>
        /// <param name="alpha">
        /// Minimum number of layers on which neighbouring node must be a neighbour with node x.
        /// </param>
        /// <param name="k">
        /// Number of Communities
        /// </param>
        /// <returns>List of communities.</returns>
        public List <Community> Apply(Network network, int alpha, int k)
        {
            var n          = CopyNetwork(network);
            var flattened  = new BasicFlattening().Flatten(n, true);
            var components = ConnectedComponents(flattened);

            while (k > components.Count())
            {
                var clecc = new Dictionary <Edge, double>();
                foreach (var edge in flattened.FirstLayer.Edges)
                {
                    clecc[edge] = CLECC.GetCLECC(n, edge, alpha);
                }

                var edgesToRemove = GetMinimumCLECCEdges(clecc);
                foreach (var edge in edgesToRemove)
                {
                    flattened.FirstLayer.Edges.Remove(edge);

                    foreach (var layer in n.Layers)
                    {
                        layer.Edges.RemoveAll(e => (e.Pair == edge.Pair) || (e.Reverse().Pair == edge.Pair));
                    }
                }

                components = ConnectedComponents(flattened);
            }

            return(ComponentsToCommunities(components));
        }