Example #1
0
        public void TestTwoActors()
        {
            var actors  = ActorHelper.Get(2);
            var network = new Network();

            network.Actors = actors;
            network.Layers.Add(new Layer
            {
                Edges = new List <Edge>
                {
                    new Edge(actors[0], actors[1])
                }
            });

            var expected = new List <Community>
            {
                new Community(actors[0]),
                new Community(actors[1]),
            };
            var actual = fluidC.Compute(network, 2)
                         .OrderBy(c => c.Actors.First().Name)
                         .ToList();

            Assert.Equal(actual.Count, expected.Count);

            Assert.Equal(actual[0].Actors.Count, expected[0].Actors.Count);
            Assert.Equal(actual[0].Actors[0], expected[0].Actors[0]);

            Assert.Equal(actual[1].Actors.Count, expected[1].Actors.Count);
            Assert.Equal(actual[1].Actors[0], expected[1].Actors[0]);
        }
Example #2
0
        public void TestArguments()
        {
            var actors  = ActorHelper.Get(10);
            var network = new Network();

            network.Actors = actors;
            network.Layers.Add(new Layer());

            // k <= 0
            Assert.Throws <ArgumentException>(() => fluidC.Compute(network, 0, 100));
            Assert.Throws <ArgumentException>(() => fluidC.Compute(network, -1, 100));

            // k > actors.Count
            Assert.Throws <ArgumentException>(() => fluidC.Compute(network, 11, 100));

            // maxIterations >= 1
            Assert.Throws <ArgumentException>(() => fluidC.Compute(network, 5, 0));
            Assert.Throws <ArgumentException>(() => fluidC.Compute(network, 5, 1));

            // layerCount != 1
            network.Layers.Add(new Layer());
            Assert.Throws <ArgumentException>(() => fluidC.Compute(network, 5, 10));

            network.Layers = new List <Layer>();
            Assert.Throws <ArgumentException>(() => fluidC.Compute(network, 5, 10));
        }
        public void OneLayer()
        {
            var actors = ActorHelper.Get(2);
            var edges  = new List <Edge> {
                new Edge(actors[0], actors[1])
            };
            var layer   = new Layer(edges);
            var network = new Network(layer, actors);
            var weights = new double[, ]
            {
                { 2.0 }
            };
            var flattened = weightedFlattening.Flatten(network, weights);

            Assert.NotNull(flattened);
            Assert.NotEmpty(flattened.FirstLayer.Edges);
            Assert.Collection(
                flattened.FirstLayer.Edges,
                e =>
            {
                Assert.Equal(actors[0], e.From);
                Assert.Equal(actors[1], e.To);
                Assert.Equal(2.0, e.Weight);
            }
                );
        }
        private Network GetNetwork()
        {
            // 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 layers = new List <Layer>
            {
                new Layer(edges),
                new Layer(edges),
            };

            return(new Network(layers, actors));
        }
Example #5
0
        public void TestTwoCliqueCommunities()
        {
            //    O           4
            //    | \       / |
            //    |  2  -- 3  |
            //    | /       \ |
            //    1           5

            var actors  = ActorHelper.Get(6);
            var network = new Network();
            var ed      = 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])
            };

            network.Actors = actors;
            network.Layers.Add(new Layer()
            {
                Edges = ed
            });

            var expected = new List <Community>
            {
                new Community(actors.GetRange(0, 3)),
                new Community(actors.GetRange(3, 3)),
            };
            var actual = fluidC.Compute(network, 2)
                         .OrderBy(c => c.Actors.First().Name)
                         .ToList();

            Assert.Collection(actual.OrderBy(a => a.Actors.First().Name),
                              c => Assert.Collection(c.Actors.OrderBy(a => a.Name),
                                                     a => Assert.Equal(actors[0], a),
                                                     a => Assert.Equal(actors[1], a),
                                                     a => Assert.Equal(actors[2], a)
                                                     ),
                              c => Assert.Collection(c.Actors.OrderBy(a => a.Name),
                                                     a => Assert.Equal(actors[3], a),
                                                     a => Assert.Equal(actors[4], a),
                                                     a => Assert.Equal(actors[5], a)
                                                     )
                              );
        }
        public void TwoLayersAndInterLayer()
        {
            var actors = ActorHelper.Get(2);
            var edges  = new List <Edge> {
                new Edge(actors[0], actors[1])
            };
            var layer1          = new Layer(edges);
            var layer2          = new Layer(edges);
            var interLayerEdges = new List <InterLayerEdge>
            {
                new InterLayerEdge
                {
                    From      = actors[0],
                    To        = actors[1],
                    LayerFrom = layer1,
                    LayerTo   = layer2,
                    Weight    = 1.0
                }
            };
            var network = new Network();

            network.Actors          = actors;
            network.InterLayerEdges = interLayerEdges;
            network.Layers          = new List <Layer> {
                layer1, layer2
            };
            var weights = new double[, ]
            {
                { 1.0, 3.0 },
                { 3.0, 2.0 },
            };
            var flattened = weightedFlattening.Flatten(network, weights);

            Assert.NotNull(flattened);
            Assert.NotEmpty(flattened.FirstLayer.Edges);
            Assert.Collection(flattened.FirstLayer.Edges,
                              e =>
            {
                Assert.Equal(actors[0], e.From);
                Assert.Equal(actors[1], e.To);
                Assert.Equal(6.0, e.Weight);
            }
                              );
        }