public static Dictionary<IEdge, SetValueType> Edges(IGraph graph, EdgeType edgeType, IActionExecutionEnvironment actionEnv, int threadId) { Dictionary<IEdge, SetValueType> edgesSet = new Dictionary<IEdge, SetValueType>(); foreach(IEdge edge in graph.GetCompatibleEdges(edgeType)) { ++actionEnv.PerformanceInfo.SearchStepsPerThread[threadId]; edgesSet[edge] = null; } return edgesSet; }
public static Dictionary<INode, SetValueType> Nodes(IGraph graph, NodeType nodeType, IActionExecutionEnvironment actionEnv, int threadId) { Dictionary<INode, SetValueType> nodesSet = new Dictionary<INode, SetValueType>(); foreach(INode node in graph.GetCompatibleNodes(nodeType)) { ++actionEnv.PerformanceInfo.SearchStepsPerThread[threadId]; nodesSet[node] = null; } return nodesSet; }
public static int CountEdges(IGraph graph, EdgeType edgeType, IActionExecutionEnvironment actionEnv, int threadId) { return graph.GetNumCompatibleEdges(edgeType); }
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; }
public static Dictionary<INode, SetValueType> ReachableIncoming(INode startNode, EdgeType incomingEdgeType, NodeType sourceNodeType, IActionExecutionEnvironment actionEnv, int threadId) { Dictionary<INode, SetValueType> sourceNodesSet = new Dictionary<INode, SetValueType>(); ReachableIncoming(startNode, incomingEdgeType, sourceNodeType, sourceNodesSet, actionEnv, threadId); return sourceNodesSet; }
/// <summary> /// Fills set of nodes reachable from the start node via incoming edges, under the type constraints given, in a depth-first walk /// </summary> private static void ReachableIncoming(INode startNode, EdgeType incomingEdgeType, NodeType sourceNodeType, Dictionary<INode, SetValueType> sourceNodesSet, IActionExecutionEnvironment actionEnv, int threadId) { 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(sourceNodesSet.ContainsKey(adjacentNode)) continue; sourceNodesSet[adjacentNode] = null; ReachableIncoming(adjacentNode, incomingEdgeType, sourceNodeType, sourceNodesSet, actionEnv, threadId); } }
public static Dictionary<IEdge, SetValueType> Incoming(INode startNode, EdgeType incomingEdgeType, NodeType sourceNodeType, IActionExecutionEnvironment actionEnv, int threadId) { Dictionary<IEdge, SetValueType> incomingEdgesSet = new Dictionary<IEdge, SetValueType>(); foreach(IEdge edge in startNode.Incoming) { ++actionEnv.PerformanceInfo.SearchStepsPerThread[threadId]; if(!edge.InstanceOf(incomingEdgeType)) continue; INode adjacentNode = edge.Source; if(!adjacentNode.InstanceOf(sourceNodeType)) continue; incomingEdgesSet[edge] = null; } return incomingEdgesSet; }
public object ApplyFunctionMethod(IActionExecutionEnvironment actionEnv, IGraph graph, string name, object[] arguments) { throw new NotImplementedException("The method or operation is not implemented."); }
public static bool IsBoundedReachableOutgoing(IGraph graph, INode startNode, INode endNode, int depth, EdgeType outgoingEdgeType, NodeType targetNodeType, IActionExecutionEnvironment actionEnv, int threadId) { Dictionary<INode, int> targetNodesToMinDepth = new Dictionary<INode, int>(); bool result = IsBoundedReachableOutgoing(startNode, endNode, depth, outgoingEdgeType, targetNodeType, graph, targetNodesToMinDepth, actionEnv, threadId); return result; }
public StatisticsSource(IGraph graph, IActionExecutionEnvironment actionEnv) { this.graph = graph; this.actionEnv = actionEnv; }
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; }
public static bool IsBoundedReachable(IGraph graph, INode startNode, INode endNode, int depth, EdgeType incidentEdgeType, NodeType adjacentNodeType, IActionExecutionEnvironment actionEnv, int threadId) { Dictionary<INode, int> adjacentNodesToMinDepth = new Dictionary<INode, int>(); bool result = IsBoundedReachable(startNode, endNode, depth, incidentEdgeType, adjacentNodeType, graph, adjacentNodesToMinDepth, actionEnv, threadId); return result; }
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; }
public static bool IsIncoming(INode startNode, IEdge endEdge, EdgeType incomingEdgeType, NodeType sourceNodeType, IActionExecutionEnvironment actionEnv, int threadId) { 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(edge == endEdge) return true; } return false; }
public static bool IsAdjacentOutgoing(INode startNode, INode endNode, EdgeType outgoingEdgeType, NodeType targetNodeType, IActionExecutionEnvironment actionEnv, int threadId) { 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(adjacentNode == endNode) return true; } return false; }
/// <summary> /// Executes the procedure method given by its name. /// Throws an exception if the method does not exists or the parameters are of wrong types. /// </summary> /// <param name="actionEnv">The current action execution environment.</param> /// <param name="graph">The current graph.</param> /// <param name="name">The name of the procedure method to apply.</param> /// <param name="arguments">An array with the arguments to the method.</param> /// <returns>An array with the return values of procedure application. Only valid until the next call of this method.</returns> public abstract object[] ApplyProcedureMethod(IActionExecutionEnvironment actionEnv, IGraph graph, string name, object[] arguments);
public static bool IsBoundedReachableEdgesIncoming(IGraph graph, INode startNode, IEdge endEdge, int depth, EdgeType incomingEdgeType, NodeType sourceNodeType, IActionExecutionEnvironment actionEnv, int threadId) { Dictionary<INode, int> sourceNodesToMinDepth = new Dictionary<INode, int>(); bool result = IsBoundedReachableEdgesIncoming(startNode, endEdge, depth, incomingEdgeType, sourceNodeType, graph, sourceNodesToMinDepth, actionEnv, threadId); return result; }
/// <summary> /// Applies this procedure with the given action environment on the given graph. /// Takes the arguments as inputs. /// Returns an array of output values. /// Attention: at the next call of Apply, the array returned from previous call is overwritten with the new return values. /// </summary> public abstract object[] Apply(IActionExecutionEnvironment actionEnv, IGraph graph, object[] argument);
public static int CountIncoming(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; ++count; } return count; }
public static Dictionary<IEdge, SetValueType> Outgoing(INode startNode, EdgeType outgoingEdgeType, NodeType targetNodeType, IActionExecutionEnvironment actionEnv, int threadId) { Dictionary<IEdge, SetValueType> outgoingEdgesSet = new Dictionary<IEdge, SetValueType>(); foreach(IEdge edge in startNode.Outgoing) { ++actionEnv.PerformanceInfo.SearchStepsPerThread[threadId]; if(!edge.InstanceOf(outgoingEdgeType)) continue; INode adjacentNode = edge.Target; if(!adjacentNode.InstanceOf(targetNodeType)) continue; outgoingEdgesSet[edge] = null; } return outgoingEdgesSet; }
public static Dictionary<INode, SetValueType> ReachableOutgoing(INode startNode, EdgeType outgoingEdgeType, NodeType targetNodeType, IActionExecutionEnvironment actionEnv, int threadId) { Dictionary<INode, SetValueType> targetNodesSet = new Dictionary<INode, SetValueType>(); ReachableOutgoing(startNode, outgoingEdgeType, targetNodeType, targetNodesSet, actionEnv, threadId); return targetNodesSet; }
/// <summary> /// Returns whether the end edge is reachable from the start node within the given depth, via incoming edges, under the type constraints given /// </summary> private static bool IsBoundedReachableEdgesIncoming(INode startNode, IEdge endEdge, int depth, EdgeType incomingEdgeType, NodeType sourceNodeType, IGraph graph, Dictionary<INode, int> adjacentNodesToMinDepth, IActionExecutionEnvironment actionEnv, int threadId) { if(depth <= 0) return false; bool result = false; foreach(IEdge edge in startNode.Incoming) { ++actionEnv.PerformanceInfo.SearchSteps; if(!edge.InstanceOf(incomingEdgeType)) continue; INode adjacentNode = edge.Source; if(!adjacentNode.InstanceOf(sourceNodeType)) continue; if(edge == endEdge) return true; int nodeDepth; if(adjacentNodesToMinDepth.TryGetValue(adjacentNode, out nodeDepth) && nodeDepth >= depth - 1) continue; adjacentNodesToMinDepth[adjacentNode] = depth - 1; result = IsBoundedReachableEdgesIncoming(adjacentNode, endEdge, depth - 1, incomingEdgeType, sourceNodeType, graph, adjacentNodesToMinDepth, actionEnv, threadId); if(result == true) break; } return result; }
/// <summary> /// Filters the matches of a multi rule all call or multi rule backtracking construct /// (i.e. matches obtained from different rules, that implement a match class). /// </summary> /// <param name="actionEnv">The action execution environment, required by the filter implementation.</param> /// <param name="matches">The combined list of all matches of all rules (implementing the same match class; to inspect and filter)</param> /// <param name="filter">The filter to apply</param> public abstract void Filter(IActionExecutionEnvironment actionEnv, IList <IMatch> matches, FilterCallWithArguments filter);
public static Dictionary<INode, SetValueType> Reachable(INode startNode, EdgeType incidentEdgeType, NodeType adjacentNodeType, IActionExecutionEnvironment actionEnv, int threadId) { Dictionary<INode, SetValueType> adjacentNodesSet = new Dictionary<INode, SetValueType>(); Reachable(startNode, incidentEdgeType, adjacentNodeType, adjacentNodesSet, actionEnv, threadId); return adjacentNodesSet; }
public static IEnumerable<IEdge> ReachableEdgesOutgoing(INode startNode, EdgeType incidentEdgeType, NodeType adjacentNodeType, IGraph graph, IActionExecutionEnvironment actionEnv, int threadId) { Dictionary<INode, SetValueType> visitedNodes = new Dictionary<INode, SetValueType>((int)Math.Sqrt(graph.NumNodes)); visitedNodes.Add(startNode, null); foreach(IEdge edge in ReachableEdgesOutgoingRec(startNode, incidentEdgeType, adjacentNodeType, graph, visitedNodes, actionEnv, threadId)) yield return edge; }
/// <summary> /// Fills set of nodes reachable from the start node via outgoing edges, under the type constraints given, in a depth-first walk /// </summary> private static void ReachableOutgoing(INode startNode, EdgeType outgoingEdgeType, NodeType targetNodeType, IDictionary<INode, SetValueType> targetNodesSet, IActionExecutionEnvironment actionEnv, int threadId) { 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(targetNodesSet.ContainsKey(adjacentNode)) continue; targetNodesSet[adjacentNode] = null; ReachableOutgoing(adjacentNode, outgoingEdgeType, targetNodeType, targetNodesSet, actionEnv, threadId); } }
private static IEnumerable<IEdge> ReachableEdgesOutgoingRec(INode startNode, EdgeType incidentEdgeType, NodeType adjacentNodeType, IGraph graph, Dictionary<INode, SetValueType> visitedNodes, IActionExecutionEnvironment actionEnv, int threadId) { foreach(IEdge edge in startNode.GetCompatibleOutgoing(incidentEdgeType)) { ++actionEnv.PerformanceInfo.SearchStepsPerThread[threadId]; INode adjacentNode = edge.Target; if(!adjacentNode.InstanceOf(adjacentNodeType)) continue; yield return edge; if(visitedNodes.ContainsKey(adjacentNode)) continue; visitedNodes.Add(adjacentNode, null); foreach(IEdge reachableEdge in ReachableEdgesOutgoingRec(adjacentNode, incidentEdgeType, adjacentNodeType, graph, visitedNodes, actionEnv, threadId)) yield return reachableEdge; } }
public static int CountNodes(IGraph graph, NodeType nodeType, IActionExecutionEnvironment actionEnv, int threadId) { return graph.GetNumCompatibleNodes(nodeType); }
private static IEnumerable<INode> BoundedReachableIncomingRec(INode startNode, int depth, EdgeType incidentEdgeType, NodeType adjacentNodeType, IGraph graph, 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; int nodeDepth; if(!sourceNodesToMinDepth.TryGetValue(adjacentNode, out nodeDepth)) yield return adjacentNode; if(sourceNodesToMinDepth.TryGetValue(adjacentNode, out nodeDepth) && nodeDepth >= depth - 1) continue; sourceNodesToMinDepth[adjacentNode] = depth - 1; foreach(INode node in BoundedReachableIncomingRec(adjacentNode, depth - 1, incidentEdgeType, adjacentNodeType, graph, sourceNodesToMinDepth, actionEnv, threadId)) yield return node; } }
public static int CountReachableIncoming(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<INode, SetValueType> sourceNodesSet = new Dictionary<INode, SetValueType>(); ReachableIncoming(startNode, incomingEdgeType, sourceNodeType, sourceNodesSet, actionEnv, threadId); return sourceNodesSet.Count; }
public static IEnumerable<INode> BoundedReachableOutgoing(INode startNode, int depth, EdgeType incidentEdgeType, NodeType adjacentNodeType, IGraph graph, IActionExecutionEnvironment actionEnv, int threadId) { Dictionary<INode, int> targetNodesToMinDepth = new Dictionary<INode, int>(); foreach(INode node in BoundedReachableOutgoingRec(startNode, depth, incidentEdgeType, adjacentNodeType, graph, targetNodesToMinDepth, actionEnv, threadId)) yield return node; }
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); } }
public static IEnumerable<IEdge> BoundedReachableEdgesOutgoing(INode startNode, int depth, EdgeType incidentEdgeType, NodeType adjacentNodeType, IGraph graph, IActionExecutionEnvironment actionEnv, int threadId) { Dictionary<IEdge, SetValueType> visitedEdges = new Dictionary<IEdge, SetValueType>(); Dictionary<INode, int> targetNodesToMinDepth = new Dictionary<INode, int>(); foreach(IEdge edge in BoundedReachableEdgesOutgoingRec(startNode, depth, incidentEdgeType, adjacentNodeType, graph, visitedEdges, targetNodesToMinDepth, actionEnv, threadId)) yield return edge; }
/// <summary> /// Executes the function method given by its name. /// Throws an exception if the method does not exists or the parameters are of wrong types. /// </summary> /// <param name="actionEnv">The current action execution environment.</param> /// <param name="graph">The current graph.</param> /// <param name="name">The name of the function method to apply.</param> /// <param name="arguments">An array with the arguments to the method.</param> /// <returns>The return value of function application.</returns> public abstract object ApplyFunctionMethod(IActionExecutionEnvironment actionEnv, IGraph graph, string name, object[] arguments);
private static IEnumerable<IEdge> BoundedReachableEdgesOutgoingRec(INode startNode, int depth, EdgeType incidentEdgeType, NodeType adjacentNodeType, IGraph graph, Dictionary<IEdge, SetValueType> visitedEdges, Dictionary<INode, int> targetNodesToMinDepth, 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; if(!visitedEdges.ContainsKey(edge)) { visitedEdges[edge] = null; yield return edge; } int nodeDepth; if(targetNodesToMinDepth.TryGetValue(adjacentNode, out nodeDepth) && nodeDepth >= depth - 1) continue; targetNodesToMinDepth[adjacentNode] = depth - 1; foreach(IEdge reachableEdge in BoundedReachableEdgesOutgoingRec(adjacentNode, depth - 1, incidentEdgeType, adjacentNodeType, graph, visitedEdges, targetNodesToMinDepth, actionEnv, threadId)) yield return reachableEdge; } }
public override object[] ApplyProcedureMethod(IActionExecutionEnvironment actionEnv, IGraph graph, string name, object[] arguments) { throw new Exception("The method or operation is not implemented."); }
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; }
/// <summary> /// Applies this procedure with the given action environment on the given graph. /// Takes the parameters from paramBindings as inputs. /// Returns an array of output values. /// Attention: at the next call of Apply, the array returned from previous call is overwritten with the new return values. /// </summary> public abstract object[] Apply(IActionExecutionEnvironment actionEnv, IGraph graph, ProcedureInvocationParameterBindings paramBindings);
/// <summary> /// Applies this function with the given action environment on the given graph. /// Takes the parameters from paramBindings as inputs. /// Returns the one output value. /// </summary> public abstract object Apply(IActionExecutionEnvironment actionEnv, IGraph graph, FunctionInvocationParameterBindings paramBindings);