Exemplo n.º 1
0
 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();
 }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 4
0
        public static void TryAddTypeRelation(Network n, Type v, Type w)
        {
            if(v == null || w == null || v.FullName == null || w.FullName == null)
                return;

            Vertex v_Vert = n.SearchVertex(v.FullName);
            Vertex w_Vert = n.SearchVertex(w.FullName);
            if(v_Vert != null && w_Vert != null)
                n.CreateEdge(v_Vert, w_Vert, EdgeType.DirectedAB);
        }
Exemplo n.º 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();
    }
Exemplo n.º 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;
        }
Exemplo n.º 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;
        }
Exemplo n.º 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;
        }