Exemplo n.º 1
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);
     }
 }
Exemplo n.º 2
0
        //////////////////////////////////////////////////////////////////////////////////////////////

        /// <summary>
        /// Returns count of the edges incident to the start node, under the type constraints given
        /// </summary>
        public static int CountIncident(INode startNode, EdgeType incidentEdgeType, NodeType adjacentNodeType, int threadId)
        {
            int count = 0;
            foreach(IEdge edge in startNode.GetCompatibleOutgoing(incidentEdgeType))
            {
                INode adjacentNode = edge.Target;
                if(!adjacentNode.InstanceOf(adjacentNodeType))
                    continue;
                ++count;
            }
            foreach(IEdge edge in startNode.GetCompatibleIncoming(incidentEdgeType))
            {
                INode adjacentNode = edge.Source;
                if(!adjacentNode.InstanceOf(adjacentNodeType))
                    continue;
                if(adjacentNode == startNode)
                    continue; // count reflexive edge only once
                ++count;
            }
            return count;
        }
Exemplo n.º 3
0
 /// <summary>
 /// Returns count of the edges incoming to the start node, under the type constraints given
 /// </summary>
 public static int CountIncoming(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;
         ++count;
     }
     return count;
 }
Exemplo 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;
 }
Exemplo n.º 5
0
 /// <summary>
 /// Returns set of edges incoming to the start node, under the type constraints given
 /// </summary>
 public static Dictionary<IEdge, SetValueType> Incoming(INode startNode, EdgeType incomingEdgeType, NodeType sourceNodeType, int threadId)
 {
     Dictionary<IEdge, SetValueType> incomingEdgesSet = new Dictionary<IEdge, SetValueType>();
     foreach(IEdge edge in startNode.GetCompatibleIncoming(incomingEdgeType))
     {
         INode adjacentNode = edge.Source;
         if(!adjacentNode.InstanceOf(sourceNodeType))
             continue;
         incomingEdgesSet[edge] = null;
     }
     return incomingEdgesSet;
 }
Exemplo n.º 6
0
 private static IEnumerable<IEdge> BoundedReachableEdgesIncomingRec(INode startNode, int depth, EdgeType incidentEdgeType, NodeType adjacentNodeType, IGraph graph, Dictionary<IEdge, SetValueType> visitedEdges, Dictionary<INode, int> sourceNodesToMinDepth, IActionExecutionEnvironment actionEnv, int threadId)
 {
     if(depth <= 0)
         yield break;
     foreach(IEdge edge in startNode.GetCompatibleIncoming(incidentEdgeType))
     {
         ++actionEnv.PerformanceInfo.SearchStepsPerThread[threadId];
         INode adjacentNode = edge.Source;
         if(!adjacentNode.InstanceOf(adjacentNodeType))
             continue;
         if(!visitedEdges.ContainsKey(edge))
         {
             visitedEdges[edge] = null;
             yield return edge;
         }
         int nodeDepth;
         if(sourceNodesToMinDepth.TryGetValue(adjacentNode, out nodeDepth) && nodeDepth >= depth - 1)
             continue;
         sourceNodesToMinDepth[adjacentNode] = depth - 1;
         foreach(IEdge reachableEdge in BoundedReachableEdgesIncomingRec(adjacentNode, depth - 1, incidentEdgeType, adjacentNodeType, graph, visitedEdges, sourceNodesToMinDepth, actionEnv, threadId))
             yield return reachableEdge;
     }
 }
Exemplo 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;
 }
Exemplo n.º 8
0
 private static IEnumerable<INode> BoundedReachableRec(INode startNode, int depth, EdgeType incidentEdgeType, NodeType adjacentNodeType, IGraph graph, Dictionary<INode, int> adjacentNodesToMinDepth, IActionExecutionEnvironment actionEnv, int threadId)
 {
     if(depth <= 0)
         yield break;
     foreach(IEdge edge in startNode.GetCompatibleOutgoing(incidentEdgeType))
     {
         ++actionEnv.PerformanceInfo.SearchStepsPerThread[threadId];
         INode adjacentNode = edge.Target;
         if(!adjacentNode.InstanceOf(adjacentNodeType))
             continue;
         int nodeDepth;
         if(!adjacentNodesToMinDepth.TryGetValue(adjacentNode, out nodeDepth))
             yield return adjacentNode;
         if(adjacentNodesToMinDepth.TryGetValue(adjacentNode, out nodeDepth) && nodeDepth >= depth - 1)
             continue;
         adjacentNodesToMinDepth[adjacentNode] = depth - 1;
         foreach(INode node in BoundedReachableRec(adjacentNode, depth - 1, incidentEdgeType, adjacentNodeType, graph, adjacentNodesToMinDepth, actionEnv, threadId))
             yield return node;
     }
     foreach(IEdge edge in startNode.GetCompatibleIncoming(incidentEdgeType))
     {
         ++actionEnv.PerformanceInfo.SearchStepsPerThread[threadId];
         INode adjacentNode = edge.Source;
         if(!adjacentNode.InstanceOf(adjacentNodeType))
             continue;
         int nodeDepth;
         if(!adjacentNodesToMinDepth.TryGetValue(adjacentNode, out nodeDepth))
             yield return adjacentNode;
         if(adjacentNodesToMinDepth.TryGetValue(adjacentNode, out nodeDepth) && nodeDepth >= depth - 1)
             continue;
         adjacentNodesToMinDepth[adjacentNode] = depth - 1;
         foreach(INode node in BoundedReachableRec(adjacentNode, depth - 1, incidentEdgeType, adjacentNodeType, graph, adjacentNodesToMinDepth, actionEnv, threadId))
             yield return node;
     }
 }
Exemplo n.º 9
0
 private static IEnumerable<IEdge> BoundedReachableEdgesRec(INode startNode, int depth, EdgeType incidentEdgeType, NodeType adjacentNodeType, IGraph graph, Dictionary<IEdge, SetValueType> visitedEdges, Dictionary<INode, int> adjacentNodesToMinDepth, int threadId)
 {
     if(depth <= 0)
         yield break;
     foreach(IEdge edge in startNode.GetCompatibleOutgoing(incidentEdgeType))
     {
         INode adjacentNode = edge.Target;
         if(!adjacentNode.InstanceOf(adjacentNodeType))
             continue;
         if(!visitedEdges.ContainsKey(edge))
         {
             visitedEdges[edge] = null;
             yield return edge;
         }
         int nodeDepth;
         if(adjacentNodesToMinDepth.TryGetValue(adjacentNode, out nodeDepth) && nodeDepth >= depth - 1)
             continue;
         adjacentNodesToMinDepth[adjacentNode] = depth - 1;
         foreach(IEdge reachableEdge in BoundedReachableEdgesRec(adjacentNode, depth - 1, incidentEdgeType, adjacentNodeType, graph, visitedEdges, adjacentNodesToMinDepth, threadId))
             yield return reachableEdge;
     }
     foreach(IEdge edge in startNode.GetCompatibleIncoming(incidentEdgeType))
     {
         INode adjacentNode = edge.Source;
         if(!adjacentNode.InstanceOf(adjacentNodeType))
             continue;
         if(!visitedEdges.ContainsKey(edge))
         {
             visitedEdges[edge] = null;
             yield return edge;
         }
         int nodeDepth;
         if(adjacentNodesToMinDepth.TryGetValue(adjacentNode, out nodeDepth) && nodeDepth >= depth - 1)
             continue;
         adjacentNodesToMinDepth[adjacentNode] = depth - 1;
         foreach(IEdge reachableEdge in BoundedReachableEdgesRec(adjacentNode, depth - 1, incidentEdgeType, adjacentNodeType, graph, visitedEdges, adjacentNodesToMinDepth, threadId))
             yield return reachableEdge;
     }
 }
Exemplo n.º 10
0
        private static IEnumerable<IEdge> ReachableEdgesIncomingRec(INode startNode, EdgeType incidentEdgeType, NodeType adjacentNodeType, IGraph graph, Dictionary<INode, SetValueType> visitedNodes, int threadId)
        {
            foreach(IEdge edge in startNode.GetCompatibleIncoming(incidentEdgeType))
            {
                INode adjacentNode = edge.Source;
                if(!adjacentNode.InstanceOf(adjacentNodeType))
                    continue;
                yield return edge;

                if(visitedNodes.ContainsKey(adjacentNode))
                    continue;
                visitedNodes.Add(adjacentNode, null);
                foreach(IEdge reachableEdge in ReachableEdgesIncomingRec(adjacentNode, incidentEdgeType, adjacentNodeType, graph, visitedNodes, threadId))
                    yield return reachableEdge;
            }
        }
Exemplo n.º 11
0
        private static IEnumerable<IEdge> ReachableEdgesIncomingRec(INode startNode, EdgeType incidentEdgeType, NodeType adjacentNodeType, IGraph graph, Dictionary<INode, SetValueType> visitedNodes, IActionExecutionEnvironment actionEnv, int threadId)
        {
            foreach(IEdge edge in startNode.GetCompatibleIncoming(incidentEdgeType))
            {
                ++actionEnv.PerformanceInfo.SearchStepsPerThread[threadId];
                INode adjacentNode = edge.Source;
                if(!adjacentNode.InstanceOf(adjacentNodeType))
                    continue;
                yield return edge;

                if(visitedNodes.ContainsKey(adjacentNode))
                    continue;
                visitedNodes.Add(adjacentNode, null);
                foreach(IEdge reachableEdge in ReachableEdgesIncomingRec(adjacentNode, incidentEdgeType, adjacentNodeType, graph, visitedNodes, actionEnv, threadId))
                    yield return reachableEdge;
            }
        }
Exemplo n.º 12
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;
        }
Exemplo n.º 13
0
 public static bool IsIncoming(INode startNode, IEdge endEdge, EdgeType incomingEdgeType, NodeType sourceNodeType, int threadId)
 {
     foreach(IEdge edge in startNode.GetCompatibleIncoming(incomingEdgeType))
     {
         INode adjacentNode = edge.Source;
         if(!adjacentNode.InstanceOf(sourceNodeType))
             continue;
         if(edge == endEdge)
             return true;
     }
     return false;
 }
Exemplo n.º 14
0
        //////////////////////////////////////////////////////////////////////////////////////////////

        public static bool IsAdjacent(INode startNode, INode endNode, EdgeType incidentEdgeType, NodeType adjacentNodeType, int threadId)
        {
            foreach(IEdge edge in startNode.GetCompatibleOutgoing(incidentEdgeType))
            {
                INode adjacentNode = edge.Target;
                if(!adjacentNode.InstanceOf(adjacentNodeType))
                    continue;
                if(adjacentNode == endNode)
                    return true;
            }
            foreach(IEdge edge in startNode.GetCompatibleIncoming(incidentEdgeType))
            {
                INode adjacentNode = edge.Source;
                if(!adjacentNode.InstanceOf(adjacentNodeType))
                    continue;
                if(adjacentNode == endNode)
                    return true;
            }
            return false;
        }
Exemplo n.º 15
0
        /// <summary>
        /// Returns whether the end node is reachable from the start node, under the type constraints given
        /// </summary>
        private static bool IsReachable(INode startNode, INode endNode, EdgeType incidentEdgeType, NodeType adjacentNodeType, IGraph graph, List<INode> visitedNodes, int threadId)
        {
            bool result = false;

            foreach(IEdge edge in startNode.GetCompatibleOutgoing(incidentEdgeType))
            {
                INode adjacentNode = edge.Target;
                if(!adjacentNode.InstanceOf(adjacentNodeType))
                    continue;
                if(graph.IsInternallyVisited(adjacentNode, threadId))
                    continue;
                if(edge.Target == endNode)
                    return true;
                graph.SetInternallyVisited(adjacentNode, true, threadId);
                visitedNodes.Add(adjacentNode);
                result = IsReachable(adjacentNode, endNode, incidentEdgeType, adjacentNodeType, graph, visitedNodes, threadId);
                if(result == true)
                    break;
            }

            if(!result)
            {
                foreach(IEdge edge in startNode.GetCompatibleIncoming(incidentEdgeType))
                {
                    INode adjacentNode = edge.Source;
                    if(!adjacentNode.InstanceOf(adjacentNodeType))
                        continue;
                    if(graph.IsInternallyVisited(adjacentNode, threadId))
                        continue;
                    if(edge.Source == endNode)
                        return true;
                    graph.SetInternallyVisited(adjacentNode, true, threadId);
                    visitedNodes.Add(adjacentNode);
                    result = IsReachable(adjacentNode, endNode, incidentEdgeType, adjacentNodeType, graph, visitedNodes, threadId);
                    if(result == true)
                        break;
                }
            }

            return result;
        }
Exemplo n.º 16
0
        //////////////////////////////////////////////////////////////////////////////////////////////

        /// <summary>
        /// Returns set of nodes adjacent to the start node, under the type constraints given
        /// </summary>
        public static Dictionary<INode, SetValueType> Adjacent(INode startNode, EdgeType incidentEdgeType, NodeType adjacentNodeType, int threadId)
        {
            Dictionary<INode, SetValueType> adjacentNodesSet = new Dictionary<INode, SetValueType>();
            foreach(IEdge edge in startNode.GetCompatibleOutgoing(incidentEdgeType))
            {
                INode adjacentNode = edge.Target;
                if(!adjacentNode.InstanceOf(adjacentNodeType))
                    continue;
                adjacentNodesSet[adjacentNode] = null;
            }
            foreach(IEdge edge in startNode.GetCompatibleIncoming(incidentEdgeType))
            {
                INode adjacentNode = edge.Source;
                if(!adjacentNode.InstanceOf(adjacentNodeType))
                    continue;
                adjacentNodesSet[adjacentNode] = null;
            }
            return adjacentNodesSet;
        }