Esempio n. 1
0
 public static Dictionary<IEdge, SetValueType> ReachableEdgesOutgoing(IGraph graph, INode startNode, EdgeType outgoingEdgeType, NodeType targetNodeType, IActionExecutionEnvironment actionEnv, int threadId)
 {
     Dictionary<IEdge, SetValueType> outgoingEdgesSet = new Dictionary<IEdge, SetValueType>();
     ReachableEdgesOutgoing(startNode, outgoingEdgeType, targetNodeType, outgoingEdgesSet, graph, actionEnv, threadId);
     foreach(KeyValuePair<IEdge, SetValueType> kvp in outgoingEdgesSet)
     {
         IEdge edge = kvp.Key;
         graph.SetInternallyVisited(edge.Source, false, threadId);
         graph.SetInternallyVisited(edge.Target, false, threadId);
     }
     return outgoingEdgesSet;
 }
Esempio n. 2
0
 /// <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);
     }
 }
Esempio n. 3
0
 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);
     }
 }
Esempio n. 4
0
 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;
 }
Esempio n. 5
0
        //////////////////////////////////////////////////////////////////////////////////////////////

        /// <summary>
        /// Returns set of edges reachable from the start node, under the type constraints given
        /// </summary>
        public static Dictionary<IEdge, SetValueType> ReachableEdges(IGraph graph, INode startNode, EdgeType incidentEdgeType, NodeType adjacentNodeType, int threadId)
        {
            Dictionary<IEdge, SetValueType> incidentEdgesSet = new Dictionary<IEdge, SetValueType>();
            ReachableEdges(startNode, incidentEdgeType, adjacentNodeType, incidentEdgesSet, graph, threadId);
            foreach(KeyValuePair<IEdge, SetValueType> kvp in incidentEdgesSet)
            {
                IEdge edge = kvp.Key;
                graph.SetInternallyVisited(edge.Source, false, threadId);
                graph.SetInternallyVisited(edge.Target, false, threadId);
            }
            return incidentEdgesSet;
        }
Esempio n. 6
0
        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;
        }
Esempio n. 7
0
 /// <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;
 }
Esempio n. 8
0
 public static bool IsReachableEdgesIncoming(IGraph graph, INode startNode, IEdge endEdge, EdgeType incomingEdgeType, NodeType sourceNodeType, IActionExecutionEnvironment actionEnv, int threadId)
 {
     List<IGraphElement> visitedElems = new List<IGraphElement>((int)Math.Sqrt(graph.NumNodes));
     bool result = IsReachableEdgesIncoming(startNode, endEdge, incomingEdgeType, sourceNodeType, graph, visitedElems, actionEnv, threadId);
     for(int i = 0; i < visitedElems.Count; ++i)
         graph.SetInternallyVisited(visitedElems[i], false, threadId);
     return result;
 }
Esempio n. 9
0
        /// <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;
        }
Esempio n. 10
0
 /// <summary>
 /// Returns whether the end node is reachable from the start node, via incoming edges, under the type constraints given
 /// </summary>
 public static bool IsReachableIncoming(IGraph graph, INode startNode, INode endNode, EdgeType incomingEdgeType, NodeType sourceNodeType, int threadId)
 {
     List<INode> visitedNodes = new List<INode>((int)Math.Sqrt(graph.NumNodes));
     bool result = IsReachableIncoming(startNode, endNode, incomingEdgeType, sourceNodeType, graph, visitedNodes, threadId);
     for(int i = 0; i < visitedNodes.Count; ++i)
         graph.SetInternallyVisited(visitedNodes[i], false, threadId);
     return result;
 }
Esempio n. 11
0
 /// <summary>
 /// Returns whether the end edge is reachable from the start node, via outgoing edges, under the type constraints given
 /// </summary>
 public static bool IsReachableEdgesOutgoing(IGraph graph, INode startNode, IEdge endEdge, EdgeType outgoingEdgeType, NodeType targetNodeType, int threadId)
 {
     List<IGraphElement> visitedElems = new List<IGraphElement>((int)Math.Sqrt(graph.NumNodes));
     bool result = IsReachableEdgesOutgoing(startNode, endEdge, outgoingEdgeType, targetNodeType, graph, visitedElems, threadId);
     for(int i = 0; i < visitedElems.Count; ++i)
         graph.SetInternallyVisited(visitedElems[i], false, threadId);
     return result;
 }
Esempio n. 12
0
        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;
        }
Esempio n. 13
0
        /// <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;
        }
Esempio n. 14
0
 public static bool IsReachableOutgoing(IGraph graph, INode startNode, INode endNode, EdgeType outgoingEdgeType, NodeType targetNodeType, IActionExecutionEnvironment actionEnv, int threadId)
 {
     List<INode> visitedNodes = new List<INode>((int)Math.Sqrt(graph.NumNodes));
     bool result = IsReachableOutgoing(startNode, endNode, outgoingEdgeType, targetNodeType, graph, visitedNodes, actionEnv, threadId);
     for(int i = 0; i < visitedNodes.Count; ++i)
         graph.SetInternallyVisited(visitedNodes[i], false, threadId);
     return result;
 }
Esempio n. 15
0
 public static int CountReachableEdgesIncoming(IGraph graph, INode startNode, EdgeType incomingEdgeType, NodeType sourceNodeType, IActionExecutionEnvironment actionEnv, int threadId)
 {
     // todo: more performant implementation with internally visited used for marking and list for unmarking instead of hash set
     Dictionary<IEdge, SetValueType> incomingEdgesSet = new Dictionary<IEdge, SetValueType>();
     ReachableEdgesIncoming(startNode, incomingEdgeType, sourceNodeType, incomingEdgesSet, graph, actionEnv, threadId);
     foreach(KeyValuePair<IEdge, SetValueType> kvp in incomingEdgesSet)
     {
         IEdge edge = kvp.Key;
         graph.SetInternallyVisited(edge.Source, false);
         graph.SetInternallyVisited(edge.Target, false);
     }
     return incomingEdgesSet.Count;
 }
Esempio n. 16
0
 /// <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);
     }
 }