private void AddTown(string name) { if (!_routeNodes.ContainsKey(name)) { _routeNodes.Add(name, new Node(_routeNodes.Count, name)); } _matrix = null; }
private void AddRoute(string fromTown, string toTown, int distance) { var fromNode = FindNode(fromTown); var toNode = FindNode(toTown); if (fromNode == null || toNode == null) { return; } var edgeKey = GenerateEdgeKey(fromNode, toNode); if (_routeEdges.ContainsKey(edgeKey)) { return; } var edge = new Edge(fromNode, toNode, distance); _routeEdges.Add(edgeKey, edge); _matrix = null; }
public void ParseGraphString(string graphCsv) { var fragments = graphCsv.Split(','); foreach (var fragment in fragments) { var normalizedFragment = fragment.Trim(); if (normalizedFragment.Length <= 2) { continue; } var routeFrom = normalizedFragment[0].ToString(); var routeTo = normalizedFragment[1].ToString(); var distance = int.Parse(normalizedFragment.Substring(2)); AddTown(routeFrom); AddTown(routeTo); AddRoute(routeFrom, routeTo, distance); } _matrix = null; }