/// <summary> /// Fills set of edges reachable from the start node, under the type constraints given, in a depth-first walk /// </summary> private static void ReachableEdges(INode startNode, EdgeType incidentEdgeType, NodeType adjacentNodeType, Dictionary<IEdge, SetValueType> incidentEdgesSet, IGraph graph, int threadId) { foreach(IEdge edge in startNode.GetCompatibleOutgoing(incidentEdgeType)) { INode adjacentNode = edge.Target; if(!adjacentNode.InstanceOf(adjacentNodeType)) continue; incidentEdgesSet[edge] = null; if(graph.IsInternallyVisited(adjacentNode, threadId)) continue; graph.SetInternallyVisited(adjacentNode, true, threadId); ReachableEdges(adjacentNode, incidentEdgeType, adjacentNodeType, incidentEdgesSet, graph, threadId); } foreach(IEdge edge in startNode.GetCompatibleIncoming(incidentEdgeType)) { INode adjacentNode = edge.Source; if(!adjacentNode.InstanceOf(adjacentNodeType)) continue; incidentEdgesSet[edge] = null; if(graph.IsInternallyVisited(adjacentNode, threadId)) continue; graph.SetInternallyVisited(adjacentNode, true, threadId); ReachableEdges(adjacentNode, incidentEdgeType, adjacentNodeType, incidentEdgesSet, graph, threadId); } }
private static void ReachableEdges(INode startNode, EdgeType incidentEdgeType, NodeType adjacentNodeType, Dictionary<IEdge, SetValueType> incidentEdgesSet, IGraph graph, IActionExecutionEnvironment actionEnv, int threadId) { foreach(IEdge edge in startNode.Outgoing) { ++actionEnv.PerformanceInfo.SearchStepsPerThread[threadId]; if(!edge.InstanceOf(incidentEdgeType)) continue; INode adjacentNode = edge.Target; if(!adjacentNode.InstanceOf(adjacentNodeType)) continue; incidentEdgesSet[edge] = null; if(graph.IsInternallyVisited(adjacentNode, threadId)) continue; graph.SetInternallyVisited(adjacentNode, true, threadId); ReachableEdges(adjacentNode, incidentEdgeType, adjacentNodeType, incidentEdgesSet, graph, actionEnv, threadId); } foreach(IEdge edge in startNode.Incoming) { ++actionEnv.PerformanceInfo.SearchStepsPerThread[threadId]; if(!edge.InstanceOf(incidentEdgeType)) continue; INode adjacentNode = edge.Source; if(!adjacentNode.InstanceOf(adjacentNodeType)) continue; incidentEdgesSet[edge] = null; if(graph.IsInternallyVisited(adjacentNode, threadId)) continue; graph.SetInternallyVisited(adjacentNode, true, threadId); ReachableEdges(adjacentNode, incidentEdgeType, adjacentNodeType, incidentEdgesSet, graph, actionEnv, threadId); } }
/// <summary> /// Returns the count of the nodes adjacent to the start node via incoming edges, under the type constraints given /// </summary> public static int CountAdjacentIncoming(IGraph graph, INode startNode, EdgeType incidentEdgeType, NodeType adjacentNodeType, int threadId) { int count = 0; foreach(IEdge edge in startNode.GetCompatibleIncoming(incidentEdgeType)) { INode adjacentNode = edge.Source; if(!adjacentNode.InstanceOf(adjacentNodeType)) continue; if(graph.IsInternallyVisited(adjacentNode, threadId)) continue; graph.SetInternallyVisited(adjacentNode, true, threadId); ++count; } foreach(IEdge edge in startNode.GetCompatibleIncoming(incidentEdgeType)) { INode adjacentNode = edge.Source; if(!adjacentNode.InstanceOf(adjacentNodeType)) continue; graph.SetInternallyVisited(adjacentNode, false, threadId); } return count; }
public static int CountAdjacentIncoming(IGraph graph, INode startNode, EdgeType incidentEdgeType, NodeType adjacentNodeType, IActionExecutionEnvironment actionEnv, int threadId) { int count = 0; foreach(IEdge edge in startNode.Incoming) { ++actionEnv.PerformanceInfo.SearchStepsPerThread[threadId]; if(!edge.InstanceOf(incidentEdgeType)) continue; INode adjacentNode = edge.Source; if(!adjacentNode.InstanceOf(adjacentNodeType)) continue; if(graph.IsInternallyVisited(adjacentNode, threadId)) continue; graph.SetInternallyVisited(adjacentNode, true, threadId); ++count; } foreach(IEdge edge in startNode.GetCompatibleIncoming(incidentEdgeType)) { INode adjacentNode = edge.Source; if(!adjacentNode.InstanceOf(adjacentNodeType)) continue; graph.SetInternallyVisited(adjacentNode, false, threadId); } return count; }
private static bool IsReachableEdgesIncoming(INode startNode, IEdge endEdge, EdgeType incomingEdgeType, NodeType sourceNodeType, IGraph graph, List<IGraphElement> visitedElems, IActionExecutionEnvironment actionEnv, int threadId) { bool result = false; foreach(IEdge edge in startNode.Incoming) { ++actionEnv.PerformanceInfo.SearchStepsPerThread[threadId]; if(!edge.InstanceOf(incomingEdgeType)) continue; INode adjacentNode = edge.Source; if(!adjacentNode.InstanceOf(sourceNodeType)) continue; if(graph.IsInternallyVisited(edge, threadId)) continue; graph.SetInternallyVisited(edge, true, threadId); visitedElems.Add(edge); if(edge.Source == endEdge) return true; if(graph.IsInternallyVisited(adjacentNode, threadId)) continue; graph.SetInternallyVisited(adjacentNode, true, threadId); visitedElems.Add(adjacentNode); result = IsReachableEdgesIncoming(adjacentNode, endEdge, incomingEdgeType, sourceNodeType, graph, visitedElems, actionEnv, threadId); if(result == true) break; } return result; }
/// <summary> /// Returns whether the end edge is reachable from the start node, via incoming edges, under the type constraints given /// </summary> private static bool IsReachableEdgesIncoming(INode startNode, IEdge endEdge, EdgeType incomingEdgeType, NodeType sourceNodeType, IGraph graph, List<IGraphElement> visitedElems, int threadId) { bool result = false; foreach(IEdge edge in startNode.GetCompatibleIncoming(incomingEdgeType)) { INode adjacentNode = edge.Source; if(!adjacentNode.InstanceOf(sourceNodeType)) continue; if(graph.IsInternallyVisited(edge, threadId)) continue; graph.SetInternallyVisited(edge, true, threadId); visitedElems.Add(edge); if(edge.Source == endEdge) return true; if(graph.IsInternallyVisited(adjacentNode, threadId)) continue; graph.SetInternallyVisited(adjacentNode, true, threadId); visitedElems.Add(adjacentNode); result = IsReachableEdgesIncoming(adjacentNode, endEdge, incomingEdgeType, sourceNodeType, graph, visitedElems, threadId); if(result == true) break; } return result; }
private static bool IsReachableOutgoing(INode startNode, INode endNode, EdgeType outgoingEdgeType, NodeType targetNodeType, IGraph graph, List<INode> visitedNodes, IActionExecutionEnvironment actionEnv, int threadId) { bool result = false; foreach(IEdge edge in startNode.Outgoing) { ++actionEnv.PerformanceInfo.SearchStepsPerThread[threadId]; if(!edge.InstanceOf(outgoingEdgeType)) continue; INode adjacentNode = edge.Target; if(!adjacentNode.InstanceOf(targetNodeType)) continue; if(graph.IsInternallyVisited(adjacentNode, threadId)) continue; if(edge.Target == endNode) return true; graph.SetInternallyVisited(adjacentNode, true, threadId); visitedNodes.Add(adjacentNode); result = IsReachableOutgoing(adjacentNode, endNode, outgoingEdgeType, targetNodeType, graph, visitedNodes, actionEnv, threadId); if(result == true) break; } return result; }
/// <summary> /// Returns whether the end node is reachable from the start node, via outgoing edges, under the type constraints given /// </summary> private static bool IsReachableOutgoing(INode startNode, INode endNode, EdgeType outgoingEdgeType, NodeType targetNodeType, IGraph graph, List<INode> visitedNodes, int threadId) { bool result = false; foreach(IEdge edge in startNode.GetCompatibleOutgoing(outgoingEdgeType)) { INode adjacentNode = edge.Target; if(!adjacentNode.InstanceOf(targetNodeType)) continue; if(graph.IsInternallyVisited(adjacentNode, threadId)) continue; if(edge.Target == endNode) return true; graph.SetInternallyVisited(adjacentNode, true, threadId); visitedNodes.Add(adjacentNode); result = IsReachableOutgoing(adjacentNode, endNode, outgoingEdgeType, targetNodeType, graph, visitedNodes, threadId); if(result == true) break; } return result; }
/// <summary> /// Fills set of outgoing edges reachable from the start node, under the type constraints given, in a depth-first walk /// </summary> private static void ReachableEdgesOutgoing(INode startNode, EdgeType outgoingEdgeType, NodeType targetNodeType, Dictionary<IEdge, SetValueType> outgoingEdgesSet, IGraph graph, int threadId) { foreach(IEdge edge in startNode.GetCompatibleOutgoing(outgoingEdgeType)) { INode adjacentNode = edge.Target; if(!adjacentNode.InstanceOf(targetNodeType)) continue; outgoingEdgesSet[edge] = null; if(graph.IsInternallyVisited(adjacentNode, threadId)) continue; graph.SetInternallyVisited(adjacentNode, true, threadId); ReachableEdgesOutgoing(adjacentNode, outgoingEdgeType, targetNodeType, outgoingEdgesSet, graph, threadId); } }