/// <summary> /// Returns the nodes the spanning tree includes. /// </summary> public HashSet <ushort> GetUsedNodes() { var nodes = new HashSet <ushort>(); foreach (var edge in SpanningEdges) { // Shortest paths are saved in DistanceLookup, so we can use those. var path = _distances.GetShortestPath(edge.Inside, edge.Outside); // Save nodes into the HashSet, the set only saves each node once. nodes.Add(edge.Inside.Id); nodes.Add(edge.Outside.Id); nodes.UnionWith(path); } return(nodes); }
public void DijkstraUnconnected() { // 0 -- 1 2 -- 3 // | / // | / // 4 -- 5 bool[,] graph2 = { {false, true, false, false, false, false}, {true, false, false, false, false, false}, {false, false, false, true, false, true}, {false, false, true, false, false, true}, {false, false, false, false, false, true}, {false, false, true, true, true, false}, }; SearchGraph searchGraph2 = SearchGraphFromData(graph2); Dictionary<int, GraphNode> graphNodes2 = GetGraphNodesIdIndex(searchGraph2); var mstNodes2 = new List<GraphNode> { graphNodes2[0], graphNodes2[2], graphNodes2[4], graphNodes2[3] }; var distances = new DistanceLookup(graphNodes2.Values.ToArray()); Assert.IsNull(distances.GetShortestPath(mstNodes2[0].DistancesIndex, mstNodes2[3].DistancesIndex)); }