Пример #1
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);
        }
Пример #2
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);
        }
Пример #3
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);
        }
Пример #4
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;
        }
Пример #5
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;
        }
Пример #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]);
                    }
                    net.CreateEdge(v1, v2, EdgeType.Undirected);
                }
            });
            return net;
        }