Ejemplo n.º 1
0
        public void ZeroWeightsTest()
        {
            // creates network nodes
            const int num     = 10;
            var       network = new Network();

            for (var i = 0u; i < num; i++)
            {
                network.AddVertex(i);
            }

            // creates edges (full with 0 weight)
            for (var i = 0u; i < num; i++)
            {
                for (var j = i + 1; j < num; j++)
                {
                    network.AddEdge(new Connection(i, j, 0));
                }
            }
            Console.WriteLine(network);

            // creates and updates community algorithm
            var commAlgorithm = new CommunityAlgorithm(network);

            commAlgorithm.Update();
            commAlgorithm.DisplayNodesCommunities();
            commAlgorithm.DisplayCommunities();

            for (var i = 0u; i < num; i++)
            {
                Assert.AreEqual(i, commAlgorithm.NodesCommunities[i], $"Node {i} should be in community {i}.");
            }
            Assert.AreEqual(num, commAlgorithm.GetNumberCommunities(), $"Num. communities should be {num}.");
            Assert.AreEqual(0, commAlgorithm.GetModularity(), double.Epsilon, "Community modularity should be 0.");
        }
Ejemplo n.º 2
0
        public void CommunityGraphTest()
        {
            // creates network nodes
            const int num     = 10;
            var       network = new Network();

            for (var i = 0u; i < num; i++)
            {
                network.AddVertex(i);
            }
            Console.WriteLine(network);

            // creates and updates community algorithm
            var commAlgorithm = new CommunityAlgorithm(network);

            commAlgorithm.Update();
            commAlgorithm.DisplayNodesCommunities();
            commAlgorithm.DisplayCommunities();

            // gets community graph
            var communityGraph = commAlgorithm.GetCommunityNetwork();

            Console.WriteLine(communityGraph);

            Assert.AreEqual(0, communityGraph.EdgeCount, "Community graph should not contain edges.");
            Assert.AreEqual(num, communityGraph.VertexCount, $"Num. communities should be {num}.");
            Assert.AreEqual(0, communityGraph.TotalWeight, double.Epsilon, "Community graph total weight should be 0.");
        }
Ejemplo n.º 3
0
        public void NoConnectionsTest()
        {
            // creates network nodes
            const int num     = 10;
            var       network = new Network();

            for (var i = 0u; i < num; i++)
            {
                network.AddVertex(i);
            }
            Console.WriteLine(network);

            // creates and updates community algorithm
            var commAlgorithm = new CommunityAlgorithm(network);

            commAlgorithm.Update();
            commAlgorithm.DisplayNodesCommunities();
            commAlgorithm.DisplayCommunities();

            Assert.AreEqual(0, network.EdgeCount, "Network should not contain edges.");
            for (var i = 0u; i < num; i++)
            {
                Assert.AreEqual(i, commAlgorithm.NodesCommunities[i], $"Node {i} should be in community {i}.");
            }
            Assert.AreEqual(num, commAlgorithm.GetNumberCommunities(), $"Num. communities should be {num}.");
            Assert.AreEqual(0, commAlgorithm.GetModularity(), double.Epsilon, "Community modularity should be 0.");
        }
Ejemplo n.º 4
0
        private static void Update(CommunityAlgorithm communityAlg, CommunityTracker tracker)
        {
            communityAlg.Update();
            communityAlg.DisplayNodesCommunities();
            Console.WriteLine("Modularity: {0}", communityAlg.GetModularity());

            tracker.Update();
        }