public void addShortestPath(MetroPath newPath) { MetroPath tmpPath = getShortestPath(newPath.startNode.ToString(),newPath.endNode.ToString()); if (tmpPath == null) { if (_shortestPathCollection.ContainsKey(newPath.startNode.ToString())) { _shortestPathCollection[newPath.startNode.ToString()].Add(newPath.endNode.ToString(), newPath); } else { Dictionary<string, MetroPath> tmpD = new Dictionary<string, MetroPath>(); tmpD.Add(newPath.endNode.Name, newPath); _shortestPathCollection.Add(newPath.startNode.Name, tmpD); } } else { tmpPath.changeLinks(newPath); tmpPath.totalWeight = newPath.totalWeight; } }
//用于计算最短路径时更改最短路径的links public void changeLinks(MetroPath path) { this.links.Clear(); this.links.AddRange(path.links); }