public static void buildGraphFromInitialState(IDirectedGraph <char> graph, string rawGraphData) { try { string[] verticeEdgeData = rawGraphData.Split(","); foreach (string verticeEdge in verticeEdgeData) { string verticeEdgeTrimmed = verticeEdge.Trim(); char vertecie1 = Char.Parse(verticeEdgeTrimmed.Substring(0, 1)); char vertecie2 = Char.Parse(verticeEdgeTrimmed.Substring(1, 1)); float weight = float.Parse(verticeEdgeTrimmed.Substring(2, verticeEdgeTrimmed.Length - 2)); graph.AddVertex(vertecie1); graph.AddVertex(vertecie2); graph.AddEdge(vertecie1, vertecie2, weight); } } catch (Exception) { Console.WriteLine("The graph data was passed in an incorrect form.\n\tFor a node A that connects to a node B with a weight of 5 pass data in like 'AB5'.\n\tSeparate data by columns: 'AB5, AC2'"); throw; } }
/// <summary> /// Adds sequence of vertices to the graph. /// </summary> /// <typeparam name="V"></typeparam> /// <typeparam name="E"></typeparam> /// <param name="graph"></param> /// <param name="vertices"></param> public static void AddVertices <V, E>(this IDirectedGraph <V, E> graph, IEnumerable <V> vertices) { using (Trace.Entering()) { foreach (V vertex in vertices) { graph.AddVertex(vertex); } } }