Ejemplo n.º 1
0
        /// <summary>
        /// The parse edges.
        /// </summary>
        /// <param name="graph">
        /// The graph.
        /// </param>
        /// <param name="xmlDoc">
        /// The xml doc.
        /// </param>
        /// <returns>
        /// Returns Graph object with added parsed edges.
        /// </returns>
        private static Graph ParseEdges(Graph graph, XmlDocument xmlDoc)
        {
            XmlNodeList xmlEdges = xmlDoc.GetElementsByTagName("edge");
            for (int i = 0; i < xmlEdges.Count; i++)
            {
                XmlNode xmlsNode = xmlEdges[i].ChildNodes.Item(0);
                XmlNode xmleNode = xmlEdges[i].ChildNodes.Item(1);
                XmlNode xmleCapacity = xmlEdges[i].ChildNodes.Item(2);
                if (xmlsNode != null && xmleNode != null && xmleCapacity != null)
                {
                    string xmlsNodeStr = xmlsNode.InnerText;
                    string xmleNodeStr = xmleNode.InnerText;
                    string xmleCapacityStr = xmleCapacity.InnerText;
                    int flow = int.Parse(xmleCapacityStr);
                    GraphNode startNode = graph.Nodes.FindByName(xmlsNodeStr);
                    GraphNode endNode = graph.Nodes.FindByName(xmleNodeStr);
                    graph.AddDirectedEdge(startNode, endNode, flow);
                }
            }

            return graph;
        }