public void EpidemicSyncTest()
 {
     Network n = new Network();
     Vertex a = n.CreateVertex();
     Vertex b = n.CreateVertex();
     n.CreateEdge(a, b);
     Kuramoto sync = new Kuramoto(n, 2d);
     sync.WriteTimeSeries(null);
     sync.Stop();
 }
Beispiel #2
0
        /// <summary>
        /// Loads a network from a textfile in which each edge is given by a line of whitespace- or comma-seperated strings representing two nodes
        /// </summary>
        /// <param name="path">
        /// The path of the textfile
        /// </param>
        /// <returns>
        /// The network
        /// </returns>
        public static Network LoadFromEdgeFile(string path)
        {
            // First read all lines
            string[] lines = System.IO.File.ReadAllLines(path);

            Network net = new Network();

            // Then process them in parallel
            System.Threading.Tasks.Parallel.ForEach(lines, s =>
            {
                string[] vertices = s.Split(' ', '\t');
                if (vertices.Length >= 2)
                {
                    Vertex v1 = net.SearchVertex(vertices[0]);
                    Vertex v2 = net.SearchVertex(vertices[1]);

                    // this needs to be atomic
                    lock (net)
                    {
                        if (v1 == null)
                        {
                            v1 = net.CreateVertex(vertices[0]);
                        }
                        if (v2 == null)
                        {
                            v2 = net.CreateVertex(vertices[1]);
                        }
                    }
                    Edge e = net.CreateEdge(v1, v2, EdgeType.Undirected);
                    if (vertices.Length == 3)
                    {
                        try {
                            e.Weight = float.Parse(vertices[2]);
                        }
                        catch
                        {
                            Logger.AddMessage(LogEntryType.Warning, "Could not parse edge weight.");
                        }
                    }
                }
            });
            return(net);
        }
Beispiel #3
0
        public static Network LoadFromCXF(string filename)
        {
            string[] cxf = System.IO.File.ReadAllLines(filename);
            Network  n   = new Network();

            foreach (string s in cxf)
            {
                string type = s.Substring(0, s.IndexOf(":"));
                if (type == "node")
                {
                    string label = ExtractNodeLabel(s);
                    n.CreateVertex(label);
//					if(colorizer!= null && extractColor(s)!=Color.Empty)
                    //	colorizer[v] = extractColor(s);
                }
                else if (type == "edge")
                {
                    string sourceLabel = ExtractSourceLabel(s);
                    string targetLabel = ExtractTargetLabel(s);
                    n.CreateEdge(n.SearchVertex(sourceLabel), n.SearchVertex(targetLabel));
                }
            }
            return(n);
        }
Beispiel #4
0
        /// <summary>
        /// The entry point of the program, where the program control starts and ends.
        /// </summary>
        /// <param name='args'>
        /// The command-line arguments.
        /// </param>
        public static void Main(string[] args)
        {
            int limit = 0;
            // Print usage information
            if (args.Length<3)
            {
                Console.WriteLine("Usage: MonoParser [class_number] [scan_path] [output_file]");
                Console.WriteLine("\t path: \tPath of the directory to scan for assemblies");
                Console.WriteLine("\t output_file: \tPath of the graphML file to produce for the resulting network");
                return;
            }

            // Some error handling
            if (!System.IO.Directory.Exists(args[1]))
            {
                Console.WriteLine("Error: The given scan_path '{0}' is not a valid directory", args[1]);
                return;
            }

            limit = Int32.Parse(args[0]);

            try
            {
                System.IO.File.CreateText(args[2]);
            }
            catch(System.IO.IOException)
            {
                Console.WriteLine("Error: Cannot write to the specified output_file");
                return;
            }

            // The network
            Network n = new Network();

            // Scan the assemblies
            List<Assembly> assemblies = new List<Assembly>();
            foreach(string s in System.IO.Directory.GetFiles(args[1], "*.dll", System.IO.SearchOption.AllDirectories))
            {
                Assembly a = Assembly.LoadFile(s);
                assemblies.Add(a);
            }

            Console.WriteLine("Found {0} assemblies", assemblies.Count);

            // Scan for classes
            foreach(Assembly a in assemblies)
                foreach(Type t in a.GetTypes())
                    if(t.FullName!="System.Object")
                        if((t.IsClass || t.IsInterface || t.IsAbstract) && n.VertexCount < limit)
                            n.CreateVertex(t.FullName);

            Console.WriteLine("Found {0} classes", n.VertexCount);

            // Scan for class relations
            foreach(Assembly a in assemblies)
                foreach(Type t in a.GetTypes())
                    if(t.IsClass || t.IsInterface || t.IsAbstract)
                    {
                        Type baseType = t.BaseType;
                        TryAddTypeRelation(n, baseType, t);

                        foreach(Type i in t.GetInterfaces())
                        TryAddTypeRelation(n, i, t);
                    }

                    /*
                        foreach(PropertyInfo p in t.GetProperties())
                            TryAddTypeRelation(n, t, p.PropertyType);

                        foreach(FieldInfo f in t.GetFields())
                            TryAddTypeRelation(n, t, f.FieldType);

                        foreach(MethodInfo m in t.GetMethods())
                        {
                            ParameterInfo[] info = m.GetParameters();

                            MethodBody mb = m.GetMethodBody();

                            mb.

                            if(mb != null)
                                foreach(LocalVariableInfo i in m.GetMethodBody().LocalVariables)
                                    TryAddTypeRelation(n, t, i.LocalType);
                        }
                    */

                    //}

            Console.WriteLine("Found {0} types and {1} connections", n.VertexCount, n.EdgeCount);

            // n.ReduceToLargestConnectedComponent();

            int maxDegree = int.MinValue;
            Vertex maxVertex = null;

            foreach(Vertex v in n.Vertices)
            {
                if(v.Degree > maxDegree)
                {
                    maxDegree = v.Degree;
                    maxVertex = v;
                }
            }

            Console.WriteLine(maxVertex.Label);

            Console.WriteLine("{0} vertices and {1} connections", n.VertexCount, n.EdgeCount);

            Network.SaveToGraphML(args[2], n);

            //NetworkVisualizer.Start(n, new FruchtermanReingoldLayout(10));
        }
Beispiel #5
0
    public static void Main(string[] args)
    {
        hierarchy = new Network();
        root = hierarchy.CreateVertex();
        root.Tag = NodeType.Root;
        c[root] = Color.Orange;

        // Assign node types and estimates
        for (int i = 0; i<individuals; i++)
        {
            Vertex aggregate = hierarchy.CreateVertex();
            hierarchy.CreateEdge(root, aggregate, EdgeType.DirectedAB);
            c[aggregate] = Color.Black;
            Aggregates.Add(aggregate);
            aggregate.Tag = NodeType.Aggregate;

            Vertex individual = hierarchy.CreateVertex();
            individual.Tag = NodeType.Individual;

            Variance[individual] = r.NextDouble();
            c[individual] = Color.FromArgb(255 - (int) (255d  * Variance[individual]), (int) (255d * Variance[individual]), 0);

            hierarchy.CreateEdge(aggregate, individual, EdgeType.DirectedAB);
            Individuals.Add(individual);

        }

        Application.Init();
        slider = new ConsensusHierarchy.TemperatureWindow();
        slider.Show();
        System.Threading.ThreadPool.QueueUserWorkItem( delegate(object o) {
            FruchtermanReingoldLayout layout = new FruchtermanReingoldLayout(15);
            NETGen.Visualization.NetworkVisualizer.Start(hierarchy, layout, c, 800, 600);
            layout.DoLayoutAsync();

            Logger.ShowInfos = false;

            while(true)
            {
                Change();
                c.RecomputeColors(new Func<Vertex,Color>(v => {
                    if (((NodeType)v.Tag) == NodeType.Aggregate)
                    {
                        if(v.OutDegree==0)
                            return Color.White;
                        else
                            return Color.Black;
                    }
                    else
                        return c[v];
                }));

                c.RecomputeColors(new Func<Edge,Color>(e => {
                    if (((NodeType)e.Target.Tag) == NodeType.Aggregate && e.Target.OutDegree==0)
                            return Color.White;
                    else
                        return c.DefaultEdgeColor;
                }));
                NetworkVisualizer.Layout.DoLayout();
            }
        });
        Application.Run();
    }
Beispiel #6
0
        /// <summary>
        /// Loads a network from a textfile in which each edge is given by a line of whitespace- or comma-seperated strings representing two nodes
        /// </summary>
        /// <param name="path">
        /// The path of the textfile
        /// </param>
        /// <returns>
        /// The network
        /// </returns>
        public static Network LoadFromEdgeFile(string path)
        {
            // First read all lines
            string[] lines = System.IO.File.ReadAllLines(path);

            Network net = new Network();

            // Then process them in parallel
            System.Threading.Tasks.Parallel.ForEach(lines, s =>
            {
                string[] vertices = s.Split(' ', '\t');
                if(vertices.Length>=2)
                {
                    Vertex v1 = net.SearchVertex(vertices[0]);
                    Vertex v2 = net.SearchVertex(vertices[1]);

                    // this needs to be atomic
                    lock(net)
                    {
                        if(v1 == null)
                            v1 = net.CreateVertex(vertices[0]);
                        if (v2 == null)
                            v2 = net.CreateVertex(vertices[1]);
                    }
                    Edge e = net.CreateEdge(v1, v2, EdgeType.Undirected);
                    if (vertices.Length==3) {
                        try {
                            e.Weight = float.Parse(vertices[2]);
                        }
                        catch
                        {
                            Logger.AddMessage(LogEntryType.Warning, "Could not parse edge weight.");
                        }
                    }
                }
            });
            return net;
        }
Beispiel #7
0
        public static Network LoadFromCXF(string filename)
        {
            string[] cxf = System.IO.File.ReadAllLines(filename);
            Network n = new Network();

            foreach(string s in cxf)
            {
                string type = s.Substring(0, s.IndexOf(":"));
                if(type=="node")
                {
                    string label = ExtractNodeLabel(s);
                    n.CreateVertex(label);
            //					if(colorizer!= null && extractColor(s)!=Color.Empty)
                    //	colorizer[v] = extractColor(s);
                }
                else if (type=="edge")
                {
                    string sourceLabel = ExtractSourceLabel (s);
                    string targetLabel = ExtractTargetLabel (s);
                    n.CreateEdge(n.SearchVertex(sourceLabel), n.SearchVertex(targetLabel));
                }
            }
            return n;
        }
Beispiel #8
0
        /// <summary>
        /// Loads a network from a textfile in which each edge is given by a line of whitespace- or comma-seperated strings representing two nodes
        /// </summary>
        /// <param name="path">
        /// The path of the textfile
        /// </param>
        /// <returns>
        /// The network
        /// </returns>
        public static Network LoadFromEdgeFile(string path)
        {
            // First read all lines
            string[] lines = System.IO.File.ReadAllLines(path);

            Network net = new Network();

            // Then process them in parallel
            System.Threading.Tasks.Parallel.ForEach(lines, s =>
            {
                string[] vertices = s.Split(' ', '\t', ',');
                if(vertices.Length==2)
                {
                    Vertex v1 = net.SearchVertex(vertices[0]);
                    Vertex v2 = net.SearchVertex(vertices[1]);

                    // this needs to be atomic
                    lock(net)
                    {
                        if(v1 == null)
                            v1 = net.CreateVertex(vertices[0]);
                        if (v2 == null)
                            v2 = net.CreateVertex(vertices[1]);
                    }
                    net.CreateEdge(v1, v2, EdgeType.Undirected);
                }
            });
            return net;
        }