/// <summary> /// Interpretation plan operations implementing the /// Implicit Source|Target|SourceOrTarget search plan operation /// are created and inserted into the interpretation plan at the insertion point /// </summary> private void buildImplicit( InterpretationPlan insertionPoint, int index, SearchPlanEdgeNode source, SearchPlanNodeNode target, ImplicitNodeType nodeType) { // get candidate = demanded node from edge insertionPoint = insertImplicitNodeFromEdge(insertionPoint, source, target, nodeType); // check connectedness of candidate SearchPlanNodeNode otherNodeOfOriginatingEdge = null; if (nodeType == ImplicitNodeType.Source) { otherNodeOfOriginatingEdge = source.PatternEdgeTarget; } if (nodeType == ImplicitNodeType.Target) { otherNodeOfOriginatingEdge = source.PatternEdgeSource; } if (source.PatternEdgeTarget == source.PatternEdgeSource) // reflexive sign needed in unfixed direction case, too { otherNodeOfOriginatingEdge = source.PatternEdgeSource; } insertionPoint = decideOnAndInsertCheckConnectednessOfImplicitNodeFromEdge(insertionPoint, target, source, otherNodeOfOriginatingEdge); // continue with next operation target.Visited = true; BuildInterpretationPlan(insertionPoint, index + 1); target.Visited = false; }
/////////////////////////////////////////////////////////////////////////////////// /// <summary> /// Inserts code to get an implicit node from an edge /// receives insertion point, returns new insertion point /// </summary> private InterpretationPlan insertImplicitNodeFromEdge( InterpretationPlan insertionPoint, SearchPlanEdgeNode edge, SearchPlanNodeNode currentNode, ImplicitNodeType nodeType) { int targetType = currentNode.PatternElement.TypeID; if (nodeType == ImplicitNodeType.Source) { currentNode.nodeMatcher = new InterpretationPlanImplicitSource(targetType, edge.edgeMatcher, currentNode); } else if (nodeType == ImplicitNodeType.Target) { currentNode.nodeMatcher = new InterpretationPlanImplicitTarget(targetType, edge.edgeMatcher, currentNode); } else { Debug.Assert(nodeType != ImplicitNodeType.TheOther); if (currentNodeIsSecondIncidentNodeOfEdge(currentNode, edge)) { currentNode.nodeMatcher = new InterpretationPlanImplicitTheOther(targetType, edge.edgeMatcher, edge.PatternEdgeSource == currentNode ? edge.PatternEdgeTarget.nodeMatcher : edge.PatternEdgeSource.nodeMatcher, currentNode); } else // edge connects to first incident node { if (edge.PatternEdgeSource == edge.PatternEdgeTarget) { // reflexive edge without direction iteration as we don't want 2 matches currentNode.nodeMatcher = new InterpretationPlanImplicitSource(targetType, edge.edgeMatcher, currentNode); } else { edge.directionVariable = new InterpretationPlanBothDirections(); insertionPoint.next = edge.directionVariable; insertionPoint = insertionPoint.next; currentNode.nodeMatcher = new InterpretationPlanImplicitSourceOrTarget(targetType, edge.edgeMatcher, edge.directionVariable, currentNode); } } } currentNode.nodeMatcher.prev = insertionPoint; insertionPoint.next = currentNode.nodeMatcher; insertionPoint = insertionPoint.next; return(insertionPoint); }
/////////////////////////////////////////////////////////////////////////////////// /// <summary> /// Inserts code to get an implicit node from an edge /// receives insertion point, returns new insertion point /// </summary> private InterpretationPlan insertImplicitNodeFromEdge( InterpretationPlan insertionPoint, SearchPlanEdgeNode edge, SearchPlanNodeNode currentNode, ImplicitNodeType nodeType) { int targetType = currentNode.PatternElement.TypeID; if (nodeType == ImplicitNodeType.Source) { currentNode.nodeMatcher = new InterpretationPlanImplicitSource(targetType, edge.edgeMatcher, currentNode); } else if(nodeType == ImplicitNodeType.Target) { currentNode.nodeMatcher = new InterpretationPlanImplicitTarget(targetType, edge.edgeMatcher, currentNode); } else { Debug.Assert(nodeType != ImplicitNodeType.TheOther); if (currentNodeIsSecondIncidentNodeOfEdge(currentNode, edge)) { currentNode.nodeMatcher = new InterpretationPlanImplicitTheOther(targetType, edge.edgeMatcher, edge.PatternEdgeSource == currentNode ? edge.PatternEdgeTarget.nodeMatcher : edge.PatternEdgeSource.nodeMatcher, currentNode); } else // edge connects to first incident node { if (edge.PatternEdgeSource == edge.PatternEdgeTarget) { // reflexive edge without direction iteration as we don't want 2 matches currentNode.nodeMatcher = new InterpretationPlanImplicitSource(targetType, edge.edgeMatcher, currentNode); } else { edge.directionVariable = new InterpretationPlanBothDirections(); insertionPoint.next = edge.directionVariable; insertionPoint = insertionPoint.next; currentNode.nodeMatcher = new InterpretationPlanImplicitSourceOrTarget(targetType, edge.edgeMatcher, edge.directionVariable, currentNode); } } } currentNode.nodeMatcher.prev = insertionPoint; insertionPoint.next = currentNode.nodeMatcher; insertionPoint = insertionPoint.next; return insertionPoint; }
/// <summary> /// Interpretation plan operations implementing the /// Implicit Source|Target|SourceOrTarget search plan operation /// are created and inserted into the interpretation plan at the insertion point /// </summary> private void buildImplicit( InterpretationPlan insertionPoint, int index, SearchPlanEdgeNode source, SearchPlanNodeNode target, ImplicitNodeType nodeType) { // get candidate = demanded node from edge insertionPoint = insertImplicitNodeFromEdge(insertionPoint, source, target, nodeType); // check connectedness of candidate SearchPlanNodeNode otherNodeOfOriginatingEdge = null; if (nodeType == ImplicitNodeType.Source) otherNodeOfOriginatingEdge = source.PatternEdgeTarget; if (nodeType == ImplicitNodeType.Target) otherNodeOfOriginatingEdge = source.PatternEdgeSource; if (source.PatternEdgeTarget == source.PatternEdgeSource) // reflexive sign needed in unfixed direction case, too otherNodeOfOriginatingEdge = source.PatternEdgeSource; insertionPoint = decideOnAndInsertCheckConnectednessOfImplicitNodeFromEdge(insertionPoint, target, source, otherNodeOfOriginatingEdge); // continue with next operation target.Visited = true; BuildInterpretationPlan(insertionPoint, index + 1); target.Visited = false; }
/// <summary> /// Inserts code to get an implicit node from an edge /// </summary> private SearchProgramOperation insertImplicitNodeFromEdge( SearchProgramOperation insertionPoint, SearchPlanEdgeNode edge, SearchPlanNodeNode currentNode, ImplicitNodeType nodeType, out SearchProgramOperation continuationPoint) { continuationPoint = null; GetCandidateByDrawing nodeFromEdge; if (nodeType == ImplicitNodeType.Source || nodeType == ImplicitNodeType.Target) { nodeFromEdge = new GetCandidateByDrawing( GetCandidateByDrawingType.NodeFromEdge, currentNode.PatternElement.Name, TypesHelper.XgrsTypeToCSharpTypeNodeEdge(model.NodeModel.Types[currentNode.PatternElement.TypeID].PackagePrefixedName), edge.PatternElement.Name, nodeType); insertionPoint = insertionPoint.Append(nodeFromEdge); } else { Debug.Assert(nodeType != ImplicitNodeType.TheOther); if (currentNodeIsSecondIncidentNodeOfEdge(currentNode, edge)) { nodeFromEdge = new GetCandidateByDrawing( GetCandidateByDrawingType.NodeFromEdge, currentNode.PatternElement.Name, TypesHelper.XgrsTypeToCSharpTypeNodeEdge(model.NodeModel.Types[currentNode.PatternElement.TypeID].PackagePrefixedName), edge.PatternElement.Name, edge.PatternEdgeSource == currentNode ? edge.PatternEdgeTarget.PatternElement.Name : edge.PatternEdgeSource.PatternElement.Name, ImplicitNodeType.TheOther); insertionPoint = insertionPoint.Append(nodeFromEdge); } else // edge connects to first incident node { if (edge.PatternEdgeSource == edge.PatternEdgeTarget) { // reflexive edge without direction iteration as we don't want 2 matches nodeFromEdge = new GetCandidateByDrawing( GetCandidateByDrawingType.NodeFromEdge, currentNode.PatternElement.Name, TypesHelper.XgrsTypeToCSharpTypeNodeEdge(model.NodeModel.Types[currentNode.PatternElement.TypeID].PackagePrefixedName), edge.PatternElement.Name, ImplicitNodeType.Source); insertionPoint = insertionPoint.Append(nodeFromEdge); } else { BothDirectionsIteration directionsIteration = new BothDirectionsIteration(edge.PatternElement.Name); directionsIteration.NestedOperationsList = new SearchProgramList(directionsIteration); continuationPoint = insertionPoint.Append(directionsIteration); insertionPoint = directionsIteration.NestedOperationsList; nodeFromEdge = new GetCandidateByDrawing( GetCandidateByDrawingType.NodeFromEdge, currentNode.PatternElement.Name, TypesHelper.XgrsTypeToCSharpTypeNodeEdge(model.NodeModel.Types[currentNode.PatternElement.TypeID].PackagePrefixedName), edge.PatternElement.Name, ImplicitNodeType.SourceOrTarget); insertionPoint = insertionPoint.Append(nodeFromEdge); } } } if (continuationPoint == null) continuationPoint = insertionPoint; return insertionPoint; }
/// <summary> /// Search program operations implementing the /// Implicit Source|Target|SourceOrTarget search plan operation /// are created and inserted into search program /// </summary> private SearchProgramOperation buildImplicit( SearchProgramOperation insertionPoint, int currentOperationIndex, SearchPlanEdgeNode source, SearchPlanNodeNode target, IsomorphyInformation isomorphy, ImplicitNodeType nodeType) { // get candidate = demanded node from edge SearchProgramOperation continuationPoint; insertionPoint = insertImplicitNodeFromEdge(insertionPoint, source, target, nodeType, out continuationPoint); if (continuationPoint == insertionPoint) continuationPoint = null; // check type of candidate insertionPoint = decideOnAndInsertCheckType(insertionPoint, target); // check connectedness of candidate SearchProgramOperation continuationPointAfterConnectednessCheck; SearchPlanNodeNode otherNodeOfOriginatingEdge = null; if (nodeType == ImplicitNodeType.Source) otherNodeOfOriginatingEdge = source.PatternEdgeTarget; if (nodeType == ImplicitNodeType.Target) otherNodeOfOriginatingEdge = source.PatternEdgeSource; if (source.PatternEdgeTarget == source.PatternEdgeSource) // reflexive sign needed in unfixed direction case, too otherNodeOfOriginatingEdge = source.PatternEdgeSource; insertionPoint = decideOnAndInsertCheckConnectednessOfImplicitNodeFromEdge( insertionPoint, target, source, otherNodeOfOriginatingEdge, out continuationPointAfterConnectednessCheck); if (continuationPoint == null && continuationPointAfterConnectednessCheck != insertionPoint) continuationPoint = continuationPointAfterConnectednessCheck; // check candidate for isomorphy string negativeIndependentNamePrefix = NegativeIndependentNamePrefix(patternGraphWithNestingPatterns.Peek()); if (isomorphy.CheckIsMatchedBit) { CheckCandidateForIsomorphy checkIsomorphy = new CheckCandidateForIsomorphy( target.PatternElement.Name, isomorphy.PatternElementsToCheckAgainstAsListOfStrings(), negativeIndependentNamePrefix, true, isoSpaceNeverAboveMaxIsoSpace, isomorphy.Parallel, isomorphy.LockForAllThreads); insertionPoint = insertionPoint.Append(checkIsomorphy); } // check candidate for global isomorphy if (programType == SearchProgramType.Subpattern || programType == SearchProgramType.AlternativeCase || programType == SearchProgramType.Iterated) { if(!isomorphy.TotallyHomomorph) { CheckCandidateForIsomorphyGlobal checkIsomorphy = new CheckCandidateForIsomorphyGlobal( target.PatternElement.Name, isomorphy.GloballyHomomorphPatternElementsAsListOfStrings(), true, isoSpaceNeverAboveMaxIsoSpace, isomorphy.Parallel); insertionPoint = insertionPoint.Append(checkIsomorphy); } } // check candidate for pattern path isomorphy if(patternGraphWithNestingPatterns.Peek().isPatternGraphOnPathFromEnclosingPatternpath) { CheckCandidateForIsomorphyPatternPath checkIsomorphy = new CheckCandidateForIsomorphyPatternPath( target.PatternElement.Name, true, patternGraphWithNestingPatterns.Peek().isPatternpathLocked, getCurrentLastMatchAtPreviousNestingLevel()); insertionPoint = insertionPoint.Append(checkIsomorphy); } // accept candidate (write isomorphy information) if (isomorphy.SetIsMatchedBit) { AcceptCandidate acceptCandidate = new AcceptCandidate( target.PatternElement.Name, negativeIndependentNamePrefix, true, isoSpaceNeverAboveMaxIsoSpace, isomorphy.Parallel, isomorphy.LockForAllThreads); insertionPoint = insertionPoint.Append(acceptCandidate); } // mark element as visited target.Visited = true; //--------------------------------------------------------------------------- // build next operation insertionPoint = BuildScheduledSearchPlanOperationIntoSearchProgram( currentOperationIndex + 1, insertionPoint); //--------------------------------------------------------------------------- // unmark element for possibly following run target.Visited = false; // abandon candidate (restore isomorphy information) if (isomorphy.SetIsMatchedBit) { // only if isomorphy information was previously written AbandonCandidate abandonCandidate = new AbandonCandidate( target.PatternElement.Name, negativeIndependentNamePrefix, true, isoSpaceNeverAboveMaxIsoSpace, isomorphy.Parallel, isomorphy.LockForAllThreads); insertionPoint = insertionPoint.Append(abandonCandidate); } if (continuationPoint != null) insertionPoint = continuationPoint; return insertionPoint; }
public GetCandidateByDrawing( GetCandidateByDrawingType type, string patternElementName, string patternElementTypeName, string startingPointEdgeName, string theOtherPatternElementName, ImplicitNodeType nodeType) { Debug.Assert(type == GetCandidateByDrawingType.NodeFromEdge); Debug.Assert(nodeType == ImplicitNodeType.TheOther); Type = type; PatternElementName = patternElementName; PatternElementTypeName = patternElementTypeName; StartingPointEdgeName = startingPointEdgeName; TheOtherPatternElementName = theOtherPatternElementName; NodeType = nodeType; }