/// <summary> /// Calculates the edge set from the adjacency information stored in the GraphNodes of the current search space. /// </summary> private GraphEdgeSet ComputeEdges() { var edgeSet = new GraphEdgeSet(_nodeStates.SearchSpaceSize); // Go through all nodes and their neigbors ... foreach (var node in _nodeStates.SearchSpace) { foreach (var neighbor in node.Adjacent) { var current = neighbor; var previous = node; var path = new HashSet <ushort>(); // Skip nodes with degree 2 that are not target nodes and instead traverse through them. while (current.Adjacent.Count == 2 && (current.DistancesIndex < 0 || !_nodeStates.IsTarget(current.DistancesIndex))) { path.Add(current.Id); var tmp = current; // Because the current node has degree 2, there is exactly one node adjacent that is not the previous one. current = current.Adjacent.First(n => n != previous); previous = tmp; } // Now create an edge if // - current is in the search space // - the edge is not reflexive // - the edge is the shortest path between both nodes if (current.DistancesIndex >= 0 && node != current && path.SetEquals(_data.DistanceLookup.GetShortestPath(node.DistancesIndex, current.DistancesIndex))) { edgeSet.Add(node.DistancesIndex, current.DistancesIndex, _data.DistanceLookup[node.DistancesIndex, current.DistancesIndex]); } } } return(edgeSet); }
/// <summary> /// Calculates the edge set from the adjacency information stored in the GraphNodes of the current search space. /// </summary> private GraphEdgeSet ComputeEdges() { var edgeSet = new GraphEdgeSet(_nodeStates.SearchSpaceSize); // Go through all nodes and their neigbors ... foreach (var node in _nodeStates.SearchSpace) { foreach (var neighbor in node.Adjacent) { var current = neighbor; var previous = node; var path = new HashSet<ushort>(); // Skip nodes with degree 2 that are not target nodes and instead traverse through them. while (current.Adjacent.Count == 2 && (current.DistancesIndex < 0 || !_nodeStates.IsTarget(current.DistancesIndex))) { path.Add(current.Id); var tmp = current; // Because the current node has degree 2, there is exactly one node adjacent that is not the previous one. current = current.Adjacent.First(n => n != previous); previous = tmp; } // Now create an edge if // - current is in the search space // - the edge is not reflexive // - the edge is the shortest path between both nodes if (current.DistancesIndex >= 0 && node != current && path.SetEquals(_data.DistanceLookup.GetShortestPath(node.DistancesIndex, current.DistancesIndex))) { edgeSet.Add(node.DistancesIndex, current.DistancesIndex, _data.DistanceLookup[node.DistancesIndex, current.DistancesIndex]); } } } return edgeSet; }