예제 #1
0
        public void MeasuresTest()
        {
            Console.WriteLine("Measures test begin...");

            var measures  = new Measures.Measures();
            var transform = new Transformation.Transformation();

            //var filePath = @"../../../../Data/aucs.mpx";
            //var networkName = "AUCS";

            //var mnet = IO.ReadMultilayer(filePath, networkName);
            //var f1 = transform.FlattenUnweighted(mnet, "Flattened", mnet.Layers, false, false);
            //var edges = mnet.EdgesByLayerPair[f1.Id][f1.Id];

            Console.WriteLine("Creating the network...");

            var mnet    = new MultilayerNetwork("Transformation Test");
            var byactor = mnet.NodesByActor;
            var a1      = mnet.AddActor("a1");
            var a2      = mnet.AddActor("a2");
            var a3      = mnet.AddActor("a3");
            var a4      = mnet.AddActor("a4");
            var a5      = mnet.AddActor("a5");
            var a6      = mnet.AddActor("a6");
            var i1      = mnet.AddActor("I1");
            var i2      = mnet.AddActor("I2");
            var i3      = mnet.AddActor("I3");
            var L1      = mnet.AddLayer("People 1", EdgeDirectionality.Undirected);
            var L2      = mnet.AddLayer("People 2", EdgeDirectionality.Undirected);
            var people  = new HashSet <Layer> {
                L1, L2
            };
            var L3   = mnet.AddLayer("Institutions", EdgeDirectionality.Undirected);
            var a1l1 = mnet.AddNode(a1, L1);
            var a2l1 = mnet.AddNode(a2, L1);
            var a3l1 = mnet.AddNode(a3, L1);
            var a4l1 = mnet.AddNode(a4, L1);
            var a5l1 = mnet.AddNode(a5, L1);
            var a1l2 = mnet.AddNode(a1, L2);
            var a2l2 = mnet.AddNode(a2, L2);
            var a3l2 = mnet.AddNode(a3, L2);
            var a4l2 = mnet.AddNode(a4, L2);
            var a5l2 = mnet.AddNode(a5, L2);
            var i1l3 = mnet.AddNode(i1, L3);
            var i2l3 = mnet.AddNode(i2, L3);
            var i3l3 = mnet.AddNode(i3, L3);

            mnet.AddEdge(a1l1, a2l1);
            mnet.AddEdge(a1l1, a3l1);
            mnet.AddEdge(a1l2, a2l2);
            mnet.AddEdge(a3l2, a4l2);
            mnet.AddEdge(a1l2, i1l3);
            mnet.AddEdge(a2l2, i1l3);
            mnet.AddEdge(a2l2, i2l3);
            mnet.AddEdge(a3l2, i2l3);
            mnet.AddEdge(a4l2, i2l3);
            mnet.AddEdge(a5l2, i3l3);
            Console.WriteLine("Creating network end.");

            Console.WriteLine("Adjaceny matrices test start...");

            var adj = mnet.ToAdjacencyMatrix();

            Console.WriteLine("Adjancency matrices test end.");


            //foreach (var layer in mnet.Layers)
            //{
            //    var nodes = mnet.NodesByLayer[layer.Id];
            //    //Console.WriteLine("{0}\t{1}\t{2}\t{3}\t", layer.Name, nodes.Count, measures.Density(mnet, layer), measures.AverageClusteringCoefficient(mnet, layer));
            //    Console.WriteLine("{0}\t{1}\t{2}\t{3}\t", layer.Name, nodes.Count, measures., measures.AverageClusteringCoefficient(mnet, layer));
            //}



            //var actor = mnet.GetActor("a1");
            //var nodes = mnet.GetNodes(actor);
            //Console.WriteLine("Actor: {0}\t Degree: {1},\t Neighborhood: {2},\t Connective Redundancy: {3},\t Exclusive Neighborhood: {4}", actor.Name,measures.Degree(mnet, actor, mnet.GetLayers(), EdgeMode.InOut),
            //    measures.NeighborhoodCentrality(mnet, actor, mnet.GetLayers(), EdgeMode.InOut),
            //    measures.ConnectiveRedundancy(mnet, actor, mnet.GetLayers(), EdgeMode.InOut),
            //    measures.ExclusiveNeighborhood(mnet, actor, mnet.GetLayers(), EdgeMode.InOut));



            Console.WriteLine("Done! " + mnet.ToString());
            Console.WriteLine("Measures test end.");
        }
예제 #2
0
        private IO io = IO.Instance; //new IO();
        public void TransformationTest()
        {
            var transform = new Transformation.Transformation();

            Console.WriteLine("Transformation test begin...");
            Console.WriteLine("Creating the network...");

            var mnet   = new MultilayerNetwork("Transformation Test");
            var a1     = mnet.AddActor("a1");
            var a2     = mnet.AddActor("a2");
            var a3     = mnet.AddActor("a3");
            var a4     = mnet.AddActor("a4");
            var a5     = mnet.AddActor("a5");
            var a6     = mnet.AddActor("a6");
            var i1     = mnet.AddActor("I1");
            var i2     = mnet.AddActor("I2");
            var i3     = mnet.AddActor("I3");
            var L1     = mnet.AddLayer("People 1", EdgeDirectionality.Undirected);
            var L2     = mnet.AddLayer("People 2", EdgeDirectionality.Undirected);
            var people = new HashSet <Layer> {
                L1, L2
            };
            var L3   = mnet.AddLayer("Institutions", EdgeDirectionality.Undirected);
            var a1l1 = mnet.AddNode(a1, L1);
            var a2l1 = mnet.AddNode(a2, L1);
            var a3l1 = mnet.AddNode(a3, L1);
            var a4l1 = mnet.AddNode(a4, L1);
            var a5l1 = mnet.AddNode(a5, L1);
            var a1l2 = mnet.AddNode(a1, L2);
            var a2l2 = mnet.AddNode(a2, L2);
            var a3l2 = mnet.AddNode(a3, L2);
            var a4l2 = mnet.AddNode(a4, L2);
            var a5l2 = mnet.AddNode(a5, L2);
            var i1l3 = mnet.AddNode(i1, L3);
            var i2l3 = mnet.AddNode(i2, L3);
            var i3l3 = mnet.AddNode(i3, L3);

            mnet.AddEdge(a1l1, a2l1);
            mnet.AddEdge(a1l1, a3l1);
            mnet.AddEdge(a1l2, a2l2);
            mnet.AddEdge(a3l2, a4l2);
            mnet.AddEdge(a1l2, i1l3);
            mnet.AddEdge(a2l2, i1l3);
            mnet.AddEdge(a2l2, i2l3);
            mnet.AddEdge(a3l2, i2l3);
            mnet.AddEdge(a4l2, i2l3);
            mnet.AddEdge(a5l2, i3l3);
            Console.WriteLine("Creating network end.");


            Console.WriteLine("Flattening L1 and L2 (unweighted, only existing actors)...");
            var f1 = transform.FlattenUnweighted(mnet, "flattened1", people, false, false);

            if (mnet.IsDirected(f1, f1))
            {
                Console.WriteLine("Layer should be undirected");
            }
            if (mnet.GetNodes(f1).Count != 5)
            {
                Console.WriteLine("Wrong number of nodes");
            }
            if (mnet.GetEdges(f1, f1).Count != 3)
            {
                Console.WriteLine("Wrong number of edges");
            }
            Console.WriteLine("Done! " + mnet.ToString());
            Console.WriteLine();

            Console.WriteLine("Flattening L1 and L2 (unweighted, all actors)...");
            var f2 = transform.FlattenUnweighted(mnet, "flattened2", people, false, true);

            if (mnet.IsDirected(f2, f2))
            {
                Console.WriteLine("Layer should be undirected");
            }
            if (mnet.GetNodes(f2).Count != 9)
            {
                Console.WriteLine("Wrong number of nodes, {0}\t != {1}", mnet.GetNodes(f2).Count, 9);
            }
            if (mnet.GetEdges(f2, f2).Count != 3)
            {
                Console.WriteLine("Wrong number of edges");
            }
            Console.WriteLine("Done! " + mnet.ToString());
            Console.WriteLine();



            Console.WriteLine("Transformation test end.");
            Console.ReadLine();
        }