/// <summary> /// Search program operations implementing the /// setup parallelized PickFromStorageDependent search plan operation /// are created and inserted into search program /// </summary> private SearchProgramOperation buildParallelPickFromStorageDependentSetup( SearchProgramOperation insertionPoint, SearchPlanNode source, SearchPlanNode target, StorageAccess storage) { bool isNode = target.NodeType == PlanNodeType.Node; bool isDict = storage.Attribute.Attribute.Kind == AttributeKind.SetAttr || storage.Attribute.Attribute.Kind == AttributeKind.MapAttr; string negativeIndependentNamePrefix = ""; PatternGraph patternGraph = patternGraphWithNestingPatterns.Peek(); // iterate available storage elements string iterationType; if(isDict) if(storage.Attribute.Attribute.Kind == AttributeKind.SetAttr) { iterationType = "System.Collections.Generic.KeyValuePair<" + TypesHelper.XgrsTypeToCSharpType(storage.Attribute.Attribute.ValueType.GetKindName(), model) + "," + "de.unika.ipd.grGen.libGr.SetValueType" + ">"; } else { iterationType = "System.Collections.Generic.KeyValuePair<" + TypesHelper.XgrsTypeToCSharpType(storage.Attribute.Attribute.KeyType.GetKindName(), model) + "," + TypesHelper.XgrsTypeToCSharpType(storage.Attribute.Attribute.ValueType.GetKindName(), model) + ">"; } else iterationType = TypesHelper.XgrsTypeToCSharpType(storage.Attribute.Attribute.ValueType.GetKindName(), model); GetCandidateByIterationParallelSetup elementsIteration = new GetCandidateByIterationParallelSetup( GetCandidateByIterationType.StorageAttributeElements, target.PatternElement.Name, source.PatternElement.Name, source.PatternElement.typeName, storage.Attribute.Attribute.Name, iterationType, isDict, isNode, rulePatternClassName, patternGraph.name, parameterNames, wasIndependentInlined(patternGraph, indexOfSchedule), emitProfiling, packagePrefixedActionName, !firstLoopPassed); return insertionPoint.Append(elementsIteration); }
/// <summary> /// Search program operations implementing the /// SubPreset search plan operation /// are created and inserted into search program /// </summary> private SearchProgramOperation buildSubPreset( SearchProgramOperation insertionPoint, int currentOperationIndex, SearchPlanNode target, IsomorphyInformation isomorphy) { bool isNode = target.NodeType == PlanNodeType.Node; string negativeIndependentNamePrefix = NegativeIndependentNamePrefix(patternGraphWithNestingPatterns.Peek()); Debug.Assert(negativeIndependentNamePrefix == "", "Top-level subpattern preset in negative/independent search plan"); // get candidate from inputs GetCandidateByDrawing fromInputs = new GetCandidateByDrawing( GetCandidateByDrawingType.FromSubpatternConnections, target.PatternElement.Name, isNode); insertionPoint = insertionPoint.Append(fromInputs); // mark element as visited target.Visited = true; //--------------------------------------------------------------------------- // build next operation insertionPoint = BuildScheduledSearchPlanOperationIntoSearchProgram( currentOperationIndex + 1, insertionPoint); //--------------------------------------------------------------------------- // unmark element for possibly following run target.Visited = false; return insertionPoint; }
/// <summary> /// Search program operations implementing the /// setup parallelized PickFromStorage search plan operation /// are created and inserted into search program /// </summary> private SearchProgramOperation buildParallelPickFromStorageSetup( SearchProgramOperation insertionPoint, SearchPlanNode target, StorageAccess storage) { bool isNode = target.NodeType == PlanNodeType.Node; bool isDict = TypesHelper.DotNetTypeToXgrsType(storage.Variable.type).StartsWith("set") || TypesHelper.DotNetTypeToXgrsType(storage.Variable.type).StartsWith("map"); string negativeIndependentNamePrefix = ""; PatternGraph patternGraph = patternGraphWithNestingPatterns.Peek(); // iterate available storage elements string iterationType; if(isDict) iterationType = "System.Collections.Generic.KeyValuePair<" + TypesHelper.GetStorageKeyTypeName(storage.Variable.type) + "," + TypesHelper.GetStorageValueTypeName(storage.Variable.type) + ">"; else iterationType = TypesHelper.GetStorageKeyTypeName(storage.Variable.type); GetCandidateByIterationParallelSetup elementsIteration = new GetCandidateByIterationParallelSetup( GetCandidateByIterationType.StorageElements, target.PatternElement.Name, storage.Variable.Name, iterationType, isDict, isNode, rulePatternClassName, patternGraph.Name, parameterNames, wasIndependentInlined(patternGraph, indexOfSchedule), emitProfiling, packagePrefixedActionName, !firstLoopPassed); return insertionPoint.Append(elementsIteration); }
private String GetDumpName(SearchPlanNode node) { if(node.NodeType == PlanNodeType.Root) return "root"; else if(node.NodeType == PlanNodeType.Node) return "node_" + node.PatternElement.Name; else return "edge_" + node.PatternElement.Name; }
private void DumpEdge(StreamWriter sw, SearchOperationType opType, SearchPlanNode source, SearchPlanNode target, float cost, bool markRed) { String typeStr = " #"; switch(opType) { case SearchOperationType.Outgoing: typeStr = "--"; break; case SearchOperationType.Incoming: typeStr = "->"; break; case SearchOperationType.Incident: typeStr = "<->"; break; case SearchOperationType.ImplicitSource: typeStr = "IS"; break; case SearchOperationType.ImplicitTarget: typeStr = "IT"; break; case SearchOperationType.Implicit: typeStr = "IM"; break; case SearchOperationType.Lookup: typeStr = " *"; break; case SearchOperationType.ActionPreset: typeStr = " p"; break; case SearchOperationType.NegIdptPreset: typeStr = "np"; break; case SearchOperationType.SubPreset: typeStr = "sp"; break; } sw.WriteLine("edge:{{sourcename:\"{0}\" targetname:\"{1}\" label:\"{2} / {3:0.00}\"{4}}}", GetDumpName(source), GetDumpName(target), typeStr, cost, markRed ? " color:red" : ""); }
/// <summary> /// Search program operations implementing the /// parallelized PickFromIndex search plan operation /// are created and inserted into search program /// </summary> private SearchProgramOperation buildParallelPickFromIndex( SearchProgramOperation insertionPoint, int currentOperationIndex, SearchPlanNode target, IndexAccess index, IsomorphyInformation isomorphy) { bool isNode = target.NodeType == PlanNodeType.Node; string negativeIndependentNamePrefix = ""; string iterationType = TypesHelper.TypeName(index.Index is AttributeIndexDescription ? ((AttributeIndexDescription)index.Index).GraphElementType : ((IncidenceCountIndexDescription)index.Index).StartNodeType); string indexSetType = NamesOfEntities.IndexSetType(model.ModelName); // iterate available index elements GetCandidateByIterationParallel elementsIteration; if(index is IndexAccessEquality) { IndexAccessEquality indexEquality = (IndexAccessEquality)index; SourceBuilder equalityExpression = new SourceBuilder(); indexEquality.Expr.Emit(equalityExpression); elementsIteration = new GetCandidateByIterationParallel( GetCandidateByIterationType.IndexElements, target.PatternElement.Name, index.Index.Name, iterationType, indexSetType, IndexAccessType.Equality, equalityExpression.ToString(), isNode, emitProfiling, packagePrefixedActionName, !firstLoopPassed); } else if(index is IndexAccessAscending) { IndexAccessAscending indexAscending = (IndexAccessAscending)index; SourceBuilder fromExpression = new SourceBuilder(); if(indexAscending.From != null) indexAscending.From.Emit(fromExpression); SourceBuilder toExpression = new SourceBuilder(); if(indexAscending.To != null) indexAscending.To.Emit(toExpression); elementsIteration = new GetCandidateByIterationParallel( GetCandidateByIterationType.IndexElements, target.PatternElement.Name, index.Index.Name, iterationType, indexSetType, IndexAccessType.Ascending, indexAscending.From != null ? fromExpression.ToString() : null, indexAscending.IncludingFrom, indexAscending.To != null ? toExpression.ToString() : null, indexAscending.IncludingTo, isNode, emitProfiling, packagePrefixedActionName, !firstLoopPassed); } else //if(index is IndexAccessDescending) { IndexAccessDescending indexDescending = (IndexAccessDescending)index; SourceBuilder fromExpression = new SourceBuilder(); if(indexDescending.From != null) indexDescending.From.Emit(fromExpression); SourceBuilder toExpression = new SourceBuilder(); if(indexDescending.To != null) indexDescending.To.Emit(toExpression); elementsIteration = new GetCandidateByIterationParallel( GetCandidateByIterationType.IndexElements, target.PatternElement.Name, index.Index.Name, iterationType, indexSetType, IndexAccessType.Descending, indexDescending.From != null ? fromExpression.ToString() : null, indexDescending.IncludingFrom, indexDescending.To != null ? toExpression.ToString() : null, indexDescending.IncludingTo, isNode, emitProfiling, packagePrefixedActionName, !firstLoopPassed); } firstLoopPassed = true; SearchProgramOperation continuationPoint = insertionPoint.Append(elementsIteration); elementsIteration.NestedOperationsList = new SearchProgramList(elementsIteration); insertionPoint = elementsIteration.NestedOperationsList; // check type of candidate insertionPoint = decideOnAndInsertCheckType(insertionPoint, target); // check connectedness of candidate SearchProgramOperation continuationPointAfterConnectednessCheck; if(isNode) { insertionPoint = decideOnAndInsertCheckConnectednessOfNodeFromLookupOrPickOrMap( insertionPoint, (SearchPlanNodeNode)target, out continuationPointAfterConnectednessCheck); } else { insertionPoint = decideOnAndInsertCheckConnectednessOfEdgeFromLookupOrPickOrMap( insertionPoint, (SearchPlanEdgeNode)target, out continuationPointAfterConnectednessCheck); } // check candidate for isomorphy if(isomorphy.CheckIsMatchedBit) { CheckCandidateForIsomorphy checkIsomorphy = new CheckCandidateForIsomorphy( target.PatternElement.Name, isomorphy.PatternElementsToCheckAgainstAsListOfStrings(), negativeIndependentNamePrefix, isNode, isoSpaceNeverAboveMaxIsoSpace, isomorphy.Parallel, isomorphy.LockForAllThreads); insertionPoint = insertionPoint.Append(checkIsomorphy); } // accept candidate (write isomorphy information) if(isomorphy.SetIsMatchedBit) { AcceptCandidate acceptCandidate = new AcceptCandidate( target.PatternElement.Name, negativeIndependentNamePrefix, isNode, 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, isNode, isoSpaceNeverAboveMaxIsoSpace, isomorphy.Parallel, isomorphy.LockForAllThreads); insertionPoint = insertionPoint.Append(abandonCandidate); } // everything nested within candidate iteration built by now - // continue at the end of the list after storage iteration insertionPoint = continuationPoint; return insertionPoint; }
/// <summary> /// Decides which check type operation to build and inserts it into search program /// </summary> private SearchProgramOperation decideOnAndInsertCheckType( SearchProgramOperation insertionPoint, SearchPlanNode target) { bool isNode = target.NodeType == PlanNodeType.Node; ITypeModel typeModel = isNode ? (ITypeModel)model.NodeModel : (ITypeModel)model.EdgeModel; if (target.PatternElement.IsAllowedType != null) { // the allowed types are given by an array for checking against them Debug.Assert(target.PatternElement.AllowedTypes != null); if (target.PatternElement.AllowedTypes.Length <= MAXIMUM_NUMBER_OF_TYPES_TO_CHECK_BY_TYPE_ID) { string[] typeIDs = new string[target.PatternElement.AllowedTypes.Length]; for (int i = 0; i < target.PatternElement.AllowedTypes.Length; ++i) { typeIDs[i] = target.PatternElement.AllowedTypes[i].TypeID.ToString(); } CheckCandidateForType checkType = new CheckCandidateForType( CheckCandidateForTypeType.ByTypeID, target.PatternElement.Name, typeIDs, isNode); insertionPoint = insertionPoint.Append(checkType); } else { string inlinedPatternClassName = null; string inlinedPatternElementName = null; if(target.PatternElement.originalElement != null) { inlinedPatternClassName = target.PatternElement.originalSubpatternEmbedding.matchingPatternOfEmbeddedGraph.GetType().Name; inlinedPatternElementName = target.PatternElement.originalElement.name; } CheckCandidateForType checkType = new CheckCandidateForType( CheckCandidateForTypeType.ByIsAllowedType, target.PatternElement.Name, inlinedPatternClassName ?? rulePatternClassName, inlinedPatternElementName ?? target.PatternElement.Name, isNode); insertionPoint = insertionPoint.Append(checkType); } return insertionPoint; } if (target.PatternElement.AllowedTypes == null) { // the pattern element type and all subtypes are allowed GrGenType targetType = typeModel.Types[target.PatternElement.TypeID]; if (targetType == typeModel.RootType) { // every type matches the root type == element type -> no check needed return insertionPoint; } if (targetType.subOrSameGrGenTypes.Length <= MAXIMUM_NUMBER_OF_TYPES_TO_CHECK_BY_TYPE_ID) { // the target type has no sub types, it must be exactly this type string[] typeIDs = new string[targetType.subOrSameGrGenTypes.Length]; for (int i = 0; i < targetType.subOrSameGrGenTypes.Length; ++i) { typeIDs[i] = targetType.subOrSameGrGenTypes[i].TypeID.ToString(); } CheckCandidateForType checkType = new CheckCandidateForType( CheckCandidateForTypeType.ByTypeID, target.PatternElement.Name, typeIDs, isNode); insertionPoint = insertionPoint.Append(checkType); } else { CheckCandidateForType checkType = new CheckCandidateForType( CheckCandidateForTypeType.ByIsMyType, target.PatternElement.Name, TypesHelper.PrefixedTypeFromType(typeModel.TypeTypes[target.PatternElement.TypeID]), isNode); insertionPoint = insertionPoint.Append(checkType); } return insertionPoint; } // the allowed types are given by allowed types array // if there are multiple ones, is allowed types must have been not null before Debug.Assert(target.PatternElement.AllowedTypes.Length > 1, "More than one allowed type"); if (target.PatternElement.AllowedTypes.Length == 0) { // no type allowed CheckCandidateFailed checkFailed = new CheckCandidateFailed(); insertionPoint = insertionPoint.Append(checkFailed); } else // (target.PatternElement.AllowedTypes.Length == 1) { // only one type allowed string[] typeIDs = new string[1]; typeIDs[0] = target.PatternElement.AllowedTypes[0].TypeID.ToString(); CheckCandidateForType checkType = new CheckCandidateForType( CheckCandidateForTypeType.ByTypeID, target.PatternElement.Name, typeIDs, isNode); insertionPoint = insertionPoint.Append(checkType); } return insertionPoint; }
/// <summary> /// Search program operations implementing the /// Identity search plan operation /// are created and inserted into search program /// </summary> private SearchProgramOperation buildIdentity( SearchProgramOperation insertionPoint, int currentOperationIndex, SearchPlanNode source, SearchPlanNode target, IsomorphyInformation isomorphy) { // check candidate is identical to other element CheckCandidateForIdentity checkIdentical = new CheckCandidateForIdentity( target.PatternElement.Name, source.PatternElement.Name); insertionPoint = insertionPoint.Append(checkIdentical); //--------------------------------------------------------------------------- // build next operation insertionPoint = BuildScheduledSearchPlanOperationIntoSearchProgram( currentOperationIndex + 1, insertionPoint); //--------------------------------------------------------------------------- return insertionPoint; }
/// <summary> /// Search program operations implementing the /// MapWithStorage search plan operation /// are created and inserted into search program /// </summary> private SearchProgramOperation buildMapWithStorage( SearchProgramOperation insertionPoint, int currentOperationIndex, SearchPlanNode target, StorageAccess storage, StorageAccessIndex index, IsomorphyInformation isomorphy) { bool isNode = target.NodeType == PlanNodeType.Node; string negativeIndependentNamePrefix = NegativeIndependentNamePrefix(patternGraphWithNestingPatterns.Peek()); // storage muss ein container typ nach graph element sein, index muss ein elementarer typ sein if(storage.Variable != null) ; // neu if(storage.GlobalVariable != null) ; // neu if(storage.Attribute != null) ; // das kann hier nicht auftreten if(index.Variable != null) ; // neu if(index.GlobalVariable != null) ; // neu if(index.Attribute != null) ; // das kann hier nicht auftreten if(index.GraphElement != null) ; // das kann hier nicht auftreten return insertionPoint; }
/// <summary> /// Search program operations implementing the /// Cast search plan operation /// are created and inserted into search program /// </summary> private SearchProgramOperation buildCast( SearchProgramOperation insertionPoint, int currentOperationIndex, SearchPlanNode source, SearchPlanNode target, IsomorphyInformation isomorphy) { bool isNode = target.NodeType == PlanNodeType.Node; string negativeIndependentNamePrefix = NegativeIndependentNamePrefix(patternGraphWithNestingPatterns.Peek()); // get candidate from other element (the cast is simply the following type check) GetCandidateByDrawing fromOtherElementForCast = new GetCandidateByDrawing( GetCandidateByDrawingType.FromOtherElementForCast, target.PatternElement.Name, source.PatternElement.Name, isNode); insertionPoint = insertionPoint.Append(fromOtherElementForCast); // check type of candidate insertionPoint = decideOnAndInsertCheckType(insertionPoint, target); // check connectedness of candidate SearchProgramOperation continuationPointAfterConnectednessCheck; if(isNode) { insertionPoint = decideOnAndInsertCheckConnectednessOfNodeFromLookupOrPickOrMap( insertionPoint, (SearchPlanNodeNode)target, out continuationPointAfterConnectednessCheck); } else { insertionPoint = decideOnAndInsertCheckConnectednessOfEdgeFromLookupOrPickOrMap( insertionPoint, (SearchPlanEdgeNode)target, out continuationPointAfterConnectednessCheck); } // check candidate for isomorphy if(isomorphy.CheckIsMatchedBit) { CheckCandidateForIsomorphy checkIsomorphy = new CheckCandidateForIsomorphy( target.PatternElement.Name, isomorphy.PatternElementsToCheckAgainstAsListOfStrings(), negativeIndependentNamePrefix, isNode, 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(), isNode, isoSpaceNeverAboveMaxIsoSpace, isomorphy.Parallel); insertionPoint = insertionPoint.Append(checkIsomorphy); } } // check candidate for pattern path isomorphy if(patternGraphWithNestingPatterns.Peek().isPatternGraphOnPathFromEnclosingPatternpath) { CheckCandidateForIsomorphyPatternPath checkIsomorphy = new CheckCandidateForIsomorphyPatternPath( target.PatternElement.Name, isNode, patternGraphWithNestingPatterns.Peek().isPatternpathLocked, getCurrentLastMatchAtPreviousNestingLevel()); insertionPoint = insertionPoint.Append(checkIsomorphy); } // accept candidate (write isomorphy information) if(isomorphy.SetIsMatchedBit) { AcceptCandidate acceptCandidate = new AcceptCandidate( target.PatternElement.Name, negativeIndependentNamePrefix, isNode, 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, isNode, isoSpaceNeverAboveMaxIsoSpace, isomorphy.Parallel, isomorphy.LockForAllThreads); insertionPoint = insertionPoint.Append(abandonCandidate); } return insertionPoint; }
/// <summary> /// Search program operations implementing the /// Assign search plan operation /// are created and inserted into search program /// </summary> private SearchProgramOperation buildAssign( SearchProgramOperation insertionPoint, int currentOperationIndex, SearchPlanNode source, SearchPlanNode target, IsomorphyInformation isomorphy) { bool isNode = target.NodeType == PlanNodeType.Node; string negativeIndependentNamePrefix = NegativeIndependentNamePrefix(patternGraphWithNestingPatterns.Peek()); // get candidate from other element (the cast is simply the following type check) GetCandidateByDrawing fromOtherElementForAssign = new GetCandidateByDrawing( GetCandidateByDrawingType.FromOtherElementForAssign, target.PatternElement.Name, source.PatternElement.Name, isNode); insertionPoint = insertionPoint.Append(fromOtherElementForAssign); // check type of candidate insertionPoint = decideOnAndInsertCheckType(insertionPoint, target); // check connectedness of candidate SearchProgramOperation continuationPointAfterConnectednessCheck; if(isNode) { insertionPoint = decideOnAndInsertCheckConnectednessOfNodeFromLookupOrPickOrMap( insertionPoint, (SearchPlanNodeNode)target, out continuationPointAfterConnectednessCheck); } else { insertionPoint = decideOnAndInsertCheckConnectednessOfEdgeFromLookupOrPickOrMap( insertionPoint, (SearchPlanEdgeNode)target, out continuationPointAfterConnectednessCheck); } // mark element as visited target.Visited = true; //--------------------------------------------------------------------------- // build next operation insertionPoint = BuildScheduledSearchPlanOperationIntoSearchProgram( currentOperationIndex + 1, insertionPoint); //--------------------------------------------------------------------------- // unmark element for possibly following run target.Visited = false; return insertionPoint; }
/// <summary> /// Search program operations implementing the /// PickByUnique or PickByUniqueDependent search plan operation /// are created and inserted into search program /// </summary> private SearchProgramOperation buildPickByUnique( SearchProgramOperation insertionPoint, int currentOperationIndex, SearchPlanNode target, UniqueLookup uniqueLookup, IsomorphyInformation isomorphy) { bool isNode = target.NodeType == PlanNodeType.Node; string negativeIndependentNamePrefix = NegativeIndependentNamePrefix(patternGraphWithNestingPatterns.Peek()); SourceBuilder expression = new SourceBuilder(); uniqueLookup.Expr.Emit(expression); // get candidate from unique index, only creates variable to hold it, get is fused with check for index membership GetCandidateByDrawing elementByUnique = new GetCandidateByDrawing( GetCandidateByDrawingType.MapByUnique, target.PatternElement.Name, expression.ToString(), isNode); insertionPoint = insertionPoint.Append(elementByUnique); // check existence of candidate in unique map CheckCandidateMapByUnique checkElementInUniqueMap = new CheckCandidateMapByUnique( target.PatternElement.Name, isNode); insertionPoint = insertionPoint.Append(checkElementInUniqueMap); // check type of candidate insertionPoint = decideOnAndInsertCheckType(insertionPoint, target); // check connectedness of candidate SearchProgramOperation continuationPointAfterConnectednessCheck; if(isNode) { insertionPoint = decideOnAndInsertCheckConnectednessOfNodeFromLookupOrPickOrMap( insertionPoint, (SearchPlanNodeNode)target, out continuationPointAfterConnectednessCheck); } else { insertionPoint = decideOnAndInsertCheckConnectednessOfEdgeFromLookupOrPickOrMap( insertionPoint, (SearchPlanEdgeNode)target, out continuationPointAfterConnectednessCheck); } if(continuationPointAfterConnectednessCheck == insertionPoint) continuationPointAfterConnectednessCheck = null; // check candidate for isomorphy if(isomorphy.CheckIsMatchedBit) { CheckCandidateForIsomorphy checkIsomorphy = new CheckCandidateForIsomorphy( target.PatternElement.Name, isomorphy.PatternElementsToCheckAgainstAsListOfStrings(), negativeIndependentNamePrefix, isNode, 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(), isNode, isoSpaceNeverAboveMaxIsoSpace, isomorphy.Parallel); insertionPoint = insertionPoint.Append(checkIsomorphy); } } // check candidate for pattern path isomorphy if(patternGraphWithNestingPatterns.Peek().isPatternGraphOnPathFromEnclosingPatternpath) { CheckCandidateForIsomorphyPatternPath checkIsomorphy = new CheckCandidateForIsomorphyPatternPath( target.PatternElement.Name, isNode, patternGraphWithNestingPatterns.Peek().isPatternpathLocked, getCurrentLastMatchAtPreviousNestingLevel()); insertionPoint = insertionPoint.Append(checkIsomorphy); } // accept candidate (write isomorphy information) if(isomorphy.SetIsMatchedBit) { AcceptCandidate acceptCandidate = new AcceptCandidate( target.PatternElement.Name, negativeIndependentNamePrefix, isNode, 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, isNode, isoSpaceNeverAboveMaxIsoSpace, isomorphy.Parallel, isomorphy.LockForAllThreads); insertionPoint = insertionPoint.Append(abandonCandidate); } if(continuationPointAfterConnectednessCheck != null) insertionPoint = continuationPointAfterConnectednessCheck; return insertionPoint; }
/// <summary> /// Search program operations implementing the /// PickFromStorage search plan operation /// are created and inserted into search program /// </summary> private SearchProgramOperation buildPickFromStorage( SearchProgramOperation insertionPoint, int currentOperationIndex, SearchPlanNode target, StorageAccess storage, IsomorphyInformation isomorphy) { bool isNode = target.NodeType == PlanNodeType.Node; bool isDict = TypesHelper.DotNetTypeToXgrsType(storage.Variable.type).StartsWith("set") || TypesHelper.DotNetTypeToXgrsType(storage.Variable.type).StartsWith("map"); string negativeIndependentNamePrefix = NegativeIndependentNamePrefix(patternGraphWithNestingPatterns.Peek()); // iterate available storage elements string iterationType; if(isDict) iterationType = "System.Collections.Generic.KeyValuePair<" + TypesHelper.GetStorageKeyTypeName(storage.Variable.type) + "," + TypesHelper.GetStorageValueTypeName(storage.Variable.type) + ">"; else iterationType = TypesHelper.GetStorageKeyTypeName(storage.Variable.type); GetCandidateByIteration elementsIteration = new GetCandidateByIteration( GetCandidateByIterationType.StorageElements, target.PatternElement.Name, storage.Variable.Name, iterationType, isDict, isNode, parallelized, emitProfiling, packagePrefixedActionName, !firstLoopPassed); firstLoopPassed = true; SearchProgramOperation continuationPoint = insertionPoint.Append(elementsIteration); elementsIteration.NestedOperationsList = new SearchProgramList(elementsIteration); insertionPoint = elementsIteration.NestedOperationsList; // check type of candidate insertionPoint = decideOnAndInsertCheckType(insertionPoint, target); // check connectedness of candidate SearchProgramOperation continuationPointAfterConnectednessCheck; if(isNode) { insertionPoint = decideOnAndInsertCheckConnectednessOfNodeFromLookupOrPickOrMap( insertionPoint, (SearchPlanNodeNode)target, out continuationPointAfterConnectednessCheck); } else { insertionPoint = decideOnAndInsertCheckConnectednessOfEdgeFromLookupOrPickOrMap( insertionPoint, (SearchPlanEdgeNode)target, out continuationPointAfterConnectednessCheck); } // check candidate for isomorphy if(isomorphy.CheckIsMatchedBit) { CheckCandidateForIsomorphy checkIsomorphy = new CheckCandidateForIsomorphy( target.PatternElement.Name, isomorphy.PatternElementsToCheckAgainstAsListOfStrings(), negativeIndependentNamePrefix, isNode, 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(), isNode, isoSpaceNeverAboveMaxIsoSpace, isomorphy.Parallel); insertionPoint = insertionPoint.Append(checkIsomorphy); } } // check candidate for pattern path isomorphy if(patternGraphWithNestingPatterns.Peek().isPatternGraphOnPathFromEnclosingPatternpath) { CheckCandidateForIsomorphyPatternPath checkIsomorphy = new CheckCandidateForIsomorphyPatternPath( target.PatternElement.Name, isNode, patternGraphWithNestingPatterns.Peek().isPatternpathLocked, getCurrentLastMatchAtPreviousNestingLevel()); insertionPoint = insertionPoint.Append(checkIsomorphy); } // accept candidate (write isomorphy information) if(isomorphy.SetIsMatchedBit) { AcceptCandidate acceptCandidate = new AcceptCandidate( target.PatternElement.Name, negativeIndependentNamePrefix, isNode, 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, isNode, isoSpaceNeverAboveMaxIsoSpace, isomorphy.Parallel, isomorphy.LockForAllThreads); insertionPoint = insertionPoint.Append(abandonCandidate); } // everything nested within candidate iteration built by now - // continue at the end of the list after storage iteration nesting level insertionPoint = continuationPoint; if(storage.Variable != null) ; // alt, siehe oben if(storage.GlobalVariable != null) ; // neu -- wenn es ein container-typ ist iterieren, wenn es ein elementarer typ ist eine einfache zuweisung -- und kein != null handling if(storage.Attribute != null) ; // das kann hier nicht auftreten return insertionPoint; }
/// <summary> /// Search program operations implementing the /// Lookup search plan operation /// are created and inserted into search program /// </summary> private SearchProgramOperation buildLookup( SearchProgramOperation insertionPoint, int currentOperationIndex, SearchPlanNode target, IsomorphyInformation isomorphy) { bool isNode = target.NodeType == PlanNodeType.Node; string negativeIndependentNamePrefix = NegativeIndependentNamePrefix(patternGraphWithNestingPatterns.Peek()); // decide on and insert operation determining type of candidate SearchProgramOperation continuationPointAfterTypeIteration; SearchProgramOperation insertionPointAfterTypeIteration = decideOnAndInsertGetType(insertionPoint, target, out continuationPointAfterTypeIteration); insertionPoint = insertionPointAfterTypeIteration; #if RANDOM_LOOKUP_LIST_START // insert list heads randomization, thus randomized lookup RandomizeListHeads randomizeListHeads = new RandomizeListHeads( RandomizeListHeadsTypes.GraphElements, target.PatternElement.Name, isNode); insertionPoint = insertionPoint.Append(randomizeListHeads); #endif // iterate available graph elements GetCandidateByIteration elementsIteration = new GetCandidateByIteration( GetCandidateByIterationType.GraphElements, target.PatternElement.Name, isNode, parallelized, emitProfiling, packagePrefixedActionName, !firstLoopPassed); firstLoopPassed = true; SearchProgramOperation continuationPoint = insertionPoint.Append(elementsIteration); elementsIteration.NestedOperationsList = new SearchProgramList(elementsIteration); insertionPoint = elementsIteration.NestedOperationsList; // check connectedness of candidate SearchProgramOperation continuationPointAfterConnectednessCheck; if (isNode) { insertionPoint = decideOnAndInsertCheckConnectednessOfNodeFromLookupOrPickOrMap( insertionPoint, (SearchPlanNodeNode)target, out continuationPointAfterConnectednessCheck); } else { insertionPoint = decideOnAndInsertCheckConnectednessOfEdgeFromLookupOrPickOrMap( insertionPoint, (SearchPlanEdgeNode)target, out continuationPointAfterConnectednessCheck); } // check candidate for isomorphy if (isomorphy.CheckIsMatchedBit) { CheckCandidateForIsomorphy checkIsomorphy = new CheckCandidateForIsomorphy( target.PatternElement.Name, isomorphy.PatternElementsToCheckAgainstAsListOfStrings(), negativeIndependentNamePrefix, isNode, 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(), isNode, isoSpaceNeverAboveMaxIsoSpace, isomorphy.Parallel); insertionPoint = insertionPoint.Append(checkIsomorphy); } } // check candidate for pattern path isomorphy if (patternGraphWithNestingPatterns.Peek().isPatternGraphOnPathFromEnclosingPatternpath) { CheckCandidateForIsomorphyPatternPath checkIsomorphy = new CheckCandidateForIsomorphyPatternPath( target.PatternElement.Name, isNode, patternGraphWithNestingPatterns.Peek().isPatternpathLocked, getCurrentLastMatchAtPreviousNestingLevel()); insertionPoint = insertionPoint.Append(checkIsomorphy); } // accept candidate (write isomorphy information) if (isomorphy.SetIsMatchedBit) { AcceptCandidate acceptCandidate = new AcceptCandidate( target.PatternElement.Name, negativeIndependentNamePrefix, isNode, 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, isNode, isoSpaceNeverAboveMaxIsoSpace, isomorphy.Parallel, isomorphy.LockForAllThreads); insertionPoint = insertionPoint.Append(abandonCandidate); } // everything nested within candidate iteration built by now - // continue at the end of the list at type iteration nesting level insertionPoint = continuationPoint; // everything nested within type iteration built by now // continue at the end of the list handed in if (insertionPointAfterTypeIteration != continuationPointAfterTypeIteration) { // if type was drawn then the if is not entered (insertion point==continuation point) // thus we continue at the continuation point of the candidate iteration // otherwise if type was iterated // we continue at the continuation point of the type iteration insertionPoint = continuationPointAfterTypeIteration; } return insertionPoint; }
/// <summary> /// Search program operations implementing the /// parallelized PickFromStorageDependent search plan operation /// are created and inserted into search program /// </summary> private SearchProgramOperation buildParallelPickFromStorageDependent( SearchProgramOperation insertionPoint, int currentOperationIndex, SearchPlanNode source, SearchPlanNode target, StorageAccess storage, IsomorphyInformation isomorphy) { bool isNode = target.NodeType == PlanNodeType.Node; bool isDict = storage.Attribute.Attribute.Kind == AttributeKind.SetAttr || storage.Attribute.Attribute.Kind == AttributeKind.MapAttr; string negativeIndependentNamePrefix = ""; // iterate available storage elements string iterationType; if(isDict) if(storage.Attribute.Attribute.Kind == AttributeKind.SetAttr) { iterationType = "System.Collections.Generic.KeyValuePair<" + TypesHelper.XgrsTypeToCSharpType(storage.Attribute.Attribute.ValueType.GetKindName(), model) + "," + "de.unika.ipd.grGen.libGr.SetValueType" + ">"; } else { iterationType = "System.Collections.Generic.KeyValuePair<" + TypesHelper.XgrsTypeToCSharpType(storage.Attribute.Attribute.KeyType.GetKindName(), model) + "," + TypesHelper.XgrsTypeToCSharpType(storage.Attribute.Attribute.ValueType.GetKindName(), model) + ">"; } else iterationType = TypesHelper.XgrsTypeToCSharpType(storage.Attribute.Attribute.ValueType.GetKindName(), model); GetCandidateByIterationParallel elementsIteration = new GetCandidateByIterationParallel( GetCandidateByIterationType.StorageAttributeElements, target.PatternElement.Name, source.PatternElement.Name, source.PatternElement.typeName, storage.Attribute.Attribute.Name, iterationType, isDict, isNode, emitProfiling, packagePrefixedActionName, !firstLoopPassed); firstLoopPassed = true; SearchProgramOperation continuationPoint = insertionPoint.Append(elementsIteration); elementsIteration.NestedOperationsList = new SearchProgramList(elementsIteration); insertionPoint = elementsIteration.NestedOperationsList; // check type of candidate insertionPoint = decideOnAndInsertCheckType(insertionPoint, target); // check connectedness of candidate SearchProgramOperation continuationPointAfterConnectednessCheck; if(isNode) { insertionPoint = decideOnAndInsertCheckConnectednessOfNodeFromLookupOrPickOrMap( insertionPoint, (SearchPlanNodeNode)target, out continuationPointAfterConnectednessCheck); } else { insertionPoint = decideOnAndInsertCheckConnectednessOfEdgeFromLookupOrPickOrMap( insertionPoint, (SearchPlanEdgeNode)target, out continuationPointAfterConnectednessCheck); } // check candidate for isomorphy if(isomorphy.CheckIsMatchedBit) { CheckCandidateForIsomorphy checkIsomorphy = new CheckCandidateForIsomorphy( target.PatternElement.Name, isomorphy.PatternElementsToCheckAgainstAsListOfStrings(), negativeIndependentNamePrefix, isNode, isoSpaceNeverAboveMaxIsoSpace, isomorphy.Parallel, isomorphy.LockForAllThreads); insertionPoint = insertionPoint.Append(checkIsomorphy); } // accept candidate (write isomorphy information) if(isomorphy.SetIsMatchedBit) { AcceptCandidate acceptCandidate = new AcceptCandidate( target.PatternElement.Name, negativeIndependentNamePrefix, isNode, 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, isNode, isoSpaceNeverAboveMaxIsoSpace, isomorphy.Parallel, isomorphy.LockForAllThreads); insertionPoint = insertionPoint.Append(abandonCandidate); } // everything nested within candidate iteration built by now - // continue at the end of the list after storage iteration nesting level insertionPoint = continuationPoint; return insertionPoint; }
/// <summary> /// Search program operations implementing the /// MapWithStorageDependent search plan operation /// are created and inserted into search program /// </summary> private SearchProgramOperation buildMapWithStorageDependent( SearchProgramOperation insertionPoint, int currentOperationIndex, SearchPlanNode source, SearchPlanNode target, StorageAccess storage, StorageAccessIndex index, IsomorphyInformation isomorphy) { bool isNode = target.NodeType == PlanNodeType.Node; string negativeIndependentNamePrefix = NegativeIndependentNamePrefix(patternGraphWithNestingPatterns.Peek()); // storage muss ein container typ nach graph element sein, index muss ein elementarer typ sein if(storage.Variable != null && index.Variable != null) ;// das kann hier nicht auftreten; if(storage.Variable != null && index.GlobalVariable != null) ;// das kann hier nicht auftreten; if(storage.Variable != null && index.Attribute != null) ;// neu if(storage.Variable != null && index.GraphElement != null) ;// alt, siehe unten if(storage.GlobalVariable != null && index.Variable != null) ;// das kann hier nicht auftreten; if(storage.GlobalVariable != null && index.GlobalVariable != null) ;// das kann hier nicht auftreten; if(storage.GlobalVariable != null && index.Attribute != null) ;// neu if(storage.GlobalVariable != null && index.GraphElement != null) ;// neu if(storage.Attribute != null && index.Variable != null) ;// neu if(storage.Attribute != null && index.GlobalVariable != null) ;// neu if(storage.Attribute != null && index.Attribute != null) ;// kann nicht auftreten, 2 abhängigkeiten if(storage.Attribute != null && index.GraphElement != null) ;// kann nicht auftreten, 2 anhängigkeiten // get candidate from storage-map, only creates variable to hold it, get is fused with check for map membership GetCandidateByDrawing elementFromStorage = new GetCandidateByDrawing( GetCandidateByDrawingType.MapWithStorage, target.PatternElement.Name, source.PatternElement.Name, storage.Variable.Name, TypesHelper.GetStorageValueTypeName(storage.Variable.type), isNode); insertionPoint = insertionPoint.Append(elementFromStorage); // check existence of candidate in storage map CheckCandidateMapWithStorage checkElementInStorage = new CheckCandidateMapWithStorage( target.PatternElement.Name, source.PatternElement.Name, storage.Variable.Name, TypesHelper.GetStorageKeyTypeName(storage.Variable.type), isNode); insertionPoint = insertionPoint.Append(checkElementInStorage); // check type of candidate insertionPoint = decideOnAndInsertCheckType(insertionPoint, target); // check connectedness of candidate SearchProgramOperation continuationPointAfterConnectednessCheck; if(isNode) { insertionPoint = decideOnAndInsertCheckConnectednessOfNodeFromLookupOrPickOrMap( insertionPoint, (SearchPlanNodeNode)target, out continuationPointAfterConnectednessCheck); } else { insertionPoint = decideOnAndInsertCheckConnectednessOfEdgeFromLookupOrPickOrMap( insertionPoint, (SearchPlanEdgeNode)target, out continuationPointAfterConnectednessCheck); } if(continuationPointAfterConnectednessCheck == insertionPoint) continuationPointAfterConnectednessCheck = null; // check candidate for isomorphy if(isomorphy.CheckIsMatchedBit) { CheckCandidateForIsomorphy checkIsomorphy = new CheckCandidateForIsomorphy( target.PatternElement.Name, isomorphy.PatternElementsToCheckAgainstAsListOfStrings(), negativeIndependentNamePrefix, isNode, 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(), isNode, isoSpaceNeverAboveMaxIsoSpace, isomorphy.Parallel); insertionPoint = insertionPoint.Append(checkIsomorphy); } } // check candidate for pattern path isomorphy if(patternGraphWithNestingPatterns.Peek().isPatternGraphOnPathFromEnclosingPatternpath) { CheckCandidateForIsomorphyPatternPath checkIsomorphy = new CheckCandidateForIsomorphyPatternPath( target.PatternElement.Name, isNode, patternGraphWithNestingPatterns.Peek().isPatternpathLocked, getCurrentLastMatchAtPreviousNestingLevel()); insertionPoint = insertionPoint.Append(checkIsomorphy); } // accept candidate (write isomorphy information) if(isomorphy.SetIsMatchedBit) { AcceptCandidate acceptCandidate = new AcceptCandidate( target.PatternElement.Name, negativeIndependentNamePrefix, isNode, 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, isNode, isoSpaceNeverAboveMaxIsoSpace, isomorphy.Parallel, isomorphy.LockForAllThreads); insertionPoint = insertionPoint.Append(abandonCandidate); } if(continuationPointAfterConnectednessCheck != null) insertionPoint = continuationPointAfterConnectednessCheck; return insertionPoint; }
/// <summary> /// Search program operations implementing the /// setup parallelized PickFromIndex search plan operation /// are created and inserted into search program /// </summary> private SearchProgramOperation buildParallelPickFromIndexSetup( SearchProgramOperation insertionPoint, SearchPlanNode target, IndexAccess index) { bool isNode = target.NodeType == PlanNodeType.Node; string negativeIndependentNamePrefix = ""; PatternGraph patternGraph = patternGraphWithNestingPatterns.Peek(); string iterationType = TypesHelper.TypeName(index.Index is AttributeIndexDescription ? ((AttributeIndexDescription)index.Index).GraphElementType : ((IncidenceCountIndexDescription)index.Index).StartNodeType); string indexSetType = NamesOfEntities.IndexSetType(model.ModelName); // iterate available index elements GetCandidateByIterationParallelSetup elementsIteration; if(index is IndexAccessEquality) { IndexAccessEquality indexEquality = (IndexAccessEquality)index; SourceBuilder equalityExpression = new SourceBuilder(); indexEquality.Expr.Emit(equalityExpression); elementsIteration = new GetCandidateByIterationParallelSetup( GetCandidateByIterationType.IndexElements, target.PatternElement.Name, index.Index.Name, iterationType, indexSetType, IndexAccessType.Equality, equalityExpression.ToString(), isNode, rulePatternClassName, patternGraph.name, parameterNames, wasIndependentInlined(patternGraph, indexOfSchedule), emitProfiling, packagePrefixedActionName, !firstLoopPassed); } else if(index is IndexAccessAscending) { IndexAccessAscending indexAscending = (IndexAccessAscending)index; SourceBuilder fromExpression = new SourceBuilder(); if(indexAscending.From != null) indexAscending.From.Emit(fromExpression); SourceBuilder toExpression = new SourceBuilder(); if(indexAscending.To != null) indexAscending.To.Emit(toExpression); elementsIteration = new GetCandidateByIterationParallelSetup( GetCandidateByIterationType.IndexElements, target.PatternElement.Name, index.Index.Name, iterationType, indexSetType, IndexAccessType.Ascending, indexAscending.From != null ? fromExpression.ToString() : null, indexAscending.IncludingFrom, indexAscending.To != null ? toExpression.ToString() : null, indexAscending.IncludingTo, isNode, rulePatternClassName, patternGraph.name, parameterNames, wasIndependentInlined(patternGraph, indexOfSchedule), emitProfiling, packagePrefixedActionName, !firstLoopPassed); } else //if(index is IndexAccessDescending) { IndexAccessDescending indexDescending = (IndexAccessDescending)index; SourceBuilder fromExpression = new SourceBuilder(); if(indexDescending.From != null) indexDescending.From.Emit(fromExpression); SourceBuilder toExpression = new SourceBuilder(); if(indexDescending.To != null) indexDescending.To.Emit(toExpression); elementsIteration = new GetCandidateByIterationParallelSetup( GetCandidateByIterationType.IndexElements, target.PatternElement.Name, index.Index.Name, iterationType, indexSetType, IndexAccessType.Descending, indexDescending.From != null ? fromExpression.ToString() : null, indexDescending.IncludingFrom, indexDescending.To != null ? toExpression.ToString() : null, indexDescending.IncludingTo, isNode, rulePatternClassName, patternGraph.name, parameterNames, wasIndependentInlined(patternGraph, indexOfSchedule), emitProfiling, packagePrefixedActionName, !firstLoopPassed); } return insertionPoint.Append(elementsIteration); }
/// <summary> /// Search program operations implementing the /// WriteParallelPreset search plan operation /// are created and inserted into search program /// </summary> private SearchProgramOperation buildWriteParallelPreset( SearchProgramOperation insertionPoint, int currentOperationIndex, SearchPlanNode target) { bool isNode = target.NodeType == PlanNodeType.Node; // write parallel preset WriteParallelPreset writePreset = new WriteParallelPreset( target.PatternElement.Name, isNode); insertionPoint = insertionPoint.Append(writePreset); //--------------------------------------------------------------------------- // build next operation insertionPoint = BuildScheduledSearchPlanOperationIntoSearchProgram( currentOperationIndex + 1, insertionPoint); //--------------------------------------------------------------------------- return insertionPoint; }
/// <summary> /// Decides which get type operation to use and inserts it /// returns new insertion point and continuation point /// for continuing buildup after the stuff nested within type iteration was built /// if type drawing was sufficient, insertion point == continuation point /// </summary> private SearchProgramOperation decideOnAndInsertGetType( SearchProgramOperation insertionPoint, SearchPlanNode target, out SearchProgramOperation continuationPoint) { bool isNode = target.NodeType == PlanNodeType.Node; ITypeModel typeModel = isNode ? (ITypeModel)model.NodeModel : (ITypeModel)model.EdgeModel; if (target.PatternElement.AllowedTypes == null) { // the pattern element type and all subtypes are allowed if (typeModel.Types[target.PatternElement.TypeID].HasSubTypes) { // more than the type itself -> we've to iterate them GetTypeByIteration typeIteration = new GetTypeByIteration( GetTypeByIterationType.AllCompatible, target.PatternElement.Name, TypesHelper.PrefixedTypeFromType(typeModel.TypeTypes[target.PatternElement.TypeID]), isNode); continuationPoint = insertionPoint.Append(typeIteration); typeIteration.NestedOperationsList = new SearchProgramList(typeIteration); insertionPoint = typeIteration.NestedOperationsList; } else { // only the type itself -> no iteration needed GetTypeByDrawing typeDrawing = new GetTypeByDrawing( target.PatternElement.Name, target.PatternElement.TypeID.ToString(), isNode); insertionPoint = insertionPoint.Append(typeDrawing); continuationPoint = insertionPoint; } } else //(target.PatternElement.AllowedTypes != null) { // the allowed types are given explicitely if (target.PatternElement.AllowedTypes.Length != 1) { // more than one allowed type -> we've to iterate them GetTypeByIteration typeIteration = new GetTypeByIteration( GetTypeByIterationType.ExplicitelyGiven, target.PatternElement.Name, rulePatternClassName, isNode); continuationPoint = insertionPoint.Append(typeIteration); typeIteration.NestedOperationsList = new SearchProgramList(typeIteration); insertionPoint = typeIteration.NestedOperationsList; } else { // only one allowed type -> no iteration needed GetTypeByDrawing typeDrawing = new GetTypeByDrawing( target.PatternElement.Name, target.PatternElement.AllowedTypes[0].TypeID.ToString(), isNode); insertionPoint = insertionPoint.Append(typeDrawing); continuationPoint = insertionPoint; } } return insertionPoint; }
/// <summary> /// Search program operations implementing the /// ParallelPreset search plan operation /// are created and inserted into search program /// </summary> private SearchProgramOperation buildParallelPreset( SearchProgramOperation insertionPoint, int currentOperationIndex, SearchPlanNode target) { bool isNode = target.NodeType == PlanNodeType.Node; // get candidate from parallelization preset GetCandidateByDrawing fromInputs = new GetCandidateByDrawing( GetCandidateByDrawingType.FromParallelizationTask, target.PatternElement.Name, isNode); insertionPoint = insertionPoint.Append(fromInputs); // mark element as visited target.Visited = true; //--------------------------------------------------------------------------- // build next operation insertionPoint = BuildScheduledSearchPlanOperationIntoSearchProgram( currentOperationIndex + 1, insertionPoint); //--------------------------------------------------------------------------- // unmark element for possibly following run target.Visited = false; return insertionPoint; }
/// <summary> /// Search program operations implementing the /// ActionPreset search plan operation /// are created and inserted into search program /// </summary> private SearchProgramOperation buildActionPreset( SearchProgramOperation insertionPoint, int currentOperationIndex, SearchPlanNode target, IsomorphyInformation isomorphy) { bool isNode = target.NodeType == PlanNodeType.Node; string negativeIndependentNamePrefix = NegativeIndependentNamePrefix(patternGraphWithNestingPatterns.Peek()); Debug.Assert(negativeIndependentNamePrefix == "", "Top-level maybe preset in negative/independent search plan"); Debug.Assert(programType != SearchProgramType.Subpattern, "Maybe preset in subpattern"); Debug.Assert(programType != SearchProgramType.AlternativeCase, "Maybe preset in alternative"); Debug.Assert(programType != SearchProgramType.Iterated, "Maybe preset in iterated"); // get candidate from inputs GetCandidateByDrawing fromInputs = new GetCandidateByDrawing( GetCandidateByDrawingType.FromInputs, target.PatternElement.Name, isNode); insertionPoint = insertionPoint.Append(fromInputs); // check type of candidate insertionPoint = decideOnAndInsertCheckType(insertionPoint, target); // check candidate for isomorphy if (isomorphy.CheckIsMatchedBit) { CheckCandidateForIsomorphy checkIsomorphy = new CheckCandidateForIsomorphy( target.PatternElement.Name, isomorphy.PatternElementsToCheckAgainstAsListOfStrings(), negativeIndependentNamePrefix, isNode, isoSpaceNeverAboveMaxIsoSpace, isomorphy.Parallel, isomorphy.LockForAllThreads); insertionPoint = insertionPoint.Append(checkIsomorphy); } // accept candidate (write isomorphy information) if (isomorphy.SetIsMatchedBit) { AcceptCandidate acceptCandidate = new AcceptCandidate( target.PatternElement.Name, negativeIndependentNamePrefix, isNode, 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, isNode, isoSpaceNeverAboveMaxIsoSpace, isomorphy.Parallel, isomorphy.LockForAllThreads); insertionPoint = insertionPoint.Append(abandonCandidate); } return insertionPoint; }
/// <summary> /// Search program operations implementing the /// setup parallelized Lookup search plan operation /// are created and inserted into search program /// </summary> private SearchProgramOperation buildParallelLookupSetup( SearchProgramOperation insertionPoint, SearchPlanNode target) { bool isNode = target.NodeType == PlanNodeType.Node; string negativeIndependentNamePrefix = ""; PatternGraph patternGraph = patternGraphWithNestingPatterns.Peek(); // decide on and insert operation determining type of candidate SearchProgramOperation continuationPointAfterTypeIteration; SearchProgramOperation insertionPointAfterTypeIteration = decideOnAndInsertGetType(insertionPoint, target, out continuationPointAfterTypeIteration); insertionPoint = insertionPointAfterTypeIteration; // iterate available graph elements GetCandidateByIterationParallelSetup elementsIteration = new GetCandidateByIterationParallelSetup( GetCandidateByIterationType.GraphElements, target.PatternElement.Name, isNode, rulePatternClassName, patternGraph.name, parameterNames, insertionPointAfterTypeIteration != continuationPointAfterTypeIteration, wasIndependentInlined(patternGraph, indexOfSchedule), emitProfiling, packagePrefixedActionName, !firstLoopPassed); return insertionPoint.Append(elementsIteration); }
private void DumpNode(StreamWriter sw, SearchPlanNode node) { if(node.NodeType == PlanNodeType.Edge) sw.WriteLine("node:{{title:\"{0}\" label:\"{1} : {2}\" shape:ellipse}}", GetDumpName(node), node.PatternElement.TypeID, node.PatternElement.Name); else sw.WriteLine("node:{{title:\"{0}\" label:\"{1} : {2}\"}}", GetDumpName(node), node.PatternElement.TypeID, node.PatternElement.Name); }
/// <summary> /// Search program operations implementing the /// parallelized Lookup search plan operation /// are created and inserted into search program /// </summary> private SearchProgramOperation buildParallelLookup( SearchProgramOperation insertionPoint, int currentOperationIndex, SearchPlanNode target, IsomorphyInformation isomorphy) { bool isNode = target.NodeType == PlanNodeType.Node; string negativeIndependentNamePrefix = ""; #if RANDOM_LOOKUP_LIST_START // insert list heads randomization, thus randomized lookup RandomizeListHeads randomizeListHeads = new RandomizeListHeads( RandomizeListHeadsTypes.GraphElements, target.PatternElement.Name, isNode); insertionPoint = insertionPoint.Append(randomizeListHeads); #endif // iterate available graph elements GetCandidateByIterationParallel elementsIteration = new GetCandidateByIterationParallel( GetCandidateByIterationType.GraphElements, target.PatternElement.Name, isNode, emitProfiling, packagePrefixedActionName, !firstLoopPassed); firstLoopPassed = true; SearchProgramOperation continuationPoint = insertionPoint.Append(elementsIteration); elementsIteration.NestedOperationsList = new SearchProgramList(elementsIteration); insertionPoint = elementsIteration.NestedOperationsList; // check connectedness of candidate SearchProgramOperation continuationPointAfterConnectednessCheck; if(isNode) { insertionPoint = decideOnAndInsertCheckConnectednessOfNodeFromLookupOrPickOrMap( insertionPoint, (SearchPlanNodeNode)target, out continuationPointAfterConnectednessCheck); } else { insertionPoint = decideOnAndInsertCheckConnectednessOfEdgeFromLookupOrPickOrMap( insertionPoint, (SearchPlanEdgeNode)target, out continuationPointAfterConnectednessCheck); } // check candidate for isomorphy if(isomorphy.CheckIsMatchedBit) { CheckCandidateForIsomorphy checkIsomorphy = new CheckCandidateForIsomorphy( target.PatternElement.Name, isomorphy.PatternElementsToCheckAgainstAsListOfStrings(), negativeIndependentNamePrefix, isNode, isoSpaceNeverAboveMaxIsoSpace, isomorphy.Parallel, isomorphy.LockForAllThreads); insertionPoint = insertionPoint.Append(checkIsomorphy); } // accept candidate (write isomorphy information) if(isomorphy.SetIsMatchedBit) { AcceptCandidate acceptCandidate = new AcceptCandidate( target.PatternElement.Name, negativeIndependentNamePrefix, isNode, 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, isNode, isoSpaceNeverAboveMaxIsoSpace, isomorphy.Parallel, isomorphy.LockForAllThreads); insertionPoint = insertionPoint.Append(abandonCandidate); } // everything nested within candidate iteration built by now - // continue at the end of the list after candidate iteration insertionPoint = continuationPoint; return insertionPoint; }
/// <summary> /// Generate search plan graph out of the plan graph, /// search plan graph only contains edges chosen by the MSA algorithm. /// Edges in search plan graph are given in the nodes by outgoing list, as needed for scheduling, /// in contrast to incoming list in plan graph, as needed for MSA computation. /// </summary> /// <param name="planGraph">The source plan graph</param> /// <returns>A new search plan graph</returns> public SearchPlanGraph GenerateSearchPlanGraph(PlanGraph planGraph) { SearchPlanNode searchPlanRoot = new SearchPlanNode("search plan root"); SearchPlanNode[] searchPlanNodes = new SearchPlanNode[planGraph.Nodes.Length]; SearchPlanEdge[] searchPlanEdges = new SearchPlanEdge[planGraph.Nodes.Length - 1 + 1]; // +1 for root Dictionary<PlanNode, SearchPlanNode> planToSearchPlanNode = // for generating edges new Dictionary<PlanNode, SearchPlanNode>(planGraph.Nodes.Length); planToSearchPlanNode.Add(planGraph.Root, searchPlanRoot); // generate the search plan graph nodes, same as plan graph nodes, // representing pattern graph nodes and edges int i = 0; foreach(PlanNode planNode in planGraph.Nodes) { if(planNode.NodeType == PlanNodeType.Edge) searchPlanNodes[i] = new SearchPlanEdgeNode(planNode, null, null); else searchPlanNodes[i] = new SearchPlanNodeNode(planNode); planToSearchPlanNode.Add(planNode, searchPlanNodes[i]); ++i; } // generate the search plan graph edges, // that are the plan graph edges chosen by the MSA algorithm, in reversed direction // and add references to originating pattern elements i = 0; foreach(PlanNode planNode in planGraph.Nodes) { PlanEdge planEdge = planNode.IncomingMSAEdge; searchPlanEdges[i] = new SearchPlanEdge(planEdge.Type, planToSearchPlanNode[planEdge.Source], planToSearchPlanNode[planEdge.Target], planEdge.Cost); planToSearchPlanNode[planEdge.Source].OutgoingEdges.Add(searchPlanEdges[i]); if(planNode.NodeType == PlanNodeType.Edge) { SearchPlanEdgeNode searchPlanEdgeNode = (SearchPlanEdgeNode) planToSearchPlanNode[planNode]; SearchPlanNode patElem; if(planEdge.Target.PatternEdgeSource != null && planToSearchPlanNode.TryGetValue(planEdge.Target.PatternEdgeSource, out patElem)) { searchPlanEdgeNode.PatternEdgeSource = (SearchPlanNodeNode) patElem; searchPlanEdgeNode.PatternEdgeSource.OutgoingPatternEdges.Add(searchPlanEdgeNode); } if(planEdge.Target.PatternEdgeTarget != null && planToSearchPlanNode.TryGetValue(planEdge.Target.PatternEdgeTarget, out patElem)) { searchPlanEdgeNode.PatternEdgeTarget = (SearchPlanNodeNode) patElem; searchPlanEdgeNode.PatternEdgeTarget.IncomingPatternEdges.Add(searchPlanEdgeNode); } } ++i; } return new SearchPlanGraph(searchPlanRoot, searchPlanNodes, searchPlanEdges); }
/// <summary> /// Search program operations implementing the /// NegIdptPreset search plan operation /// are created and inserted into search program /// </summary> private SearchProgramOperation buildNegIdptPreset( SearchProgramOperation insertionPoint, int currentOperationIndex, SearchPlanNode target, IsomorphyInformation isomorphy) { bool isNode = target.NodeType == PlanNodeType.Node; string negativeIndependentNamePrefix = NegativeIndependentNamePrefix(patternGraphWithNestingPatterns.Peek()); Debug.Assert(negativeIndependentNamePrefix != "", "Negative/Independent preset in top-level search plan"); // an inlined independet preset is differently named, must be assigned first if(target.PatternElement.PresetBecauseOfIndependentInlining) { // get candidate from other element (the cast is simply the following type check) GetCandidateByDrawing inlinedIndependentPreset = new GetCandidateByDrawing( GetCandidateByDrawingType.FromOtherElementForAssign, target.PatternElement.Name, target.PatternElement.Name + "_inlined_" + patternGraphWithNestingPatterns.Peek().Name, isNode); insertionPoint = insertionPoint.Append(inlinedIndependentPreset); } // check candidate for isomorphy if (isomorphy.CheckIsMatchedBit) { CheckCandidateForIsomorphy checkIsomorphy = new CheckCandidateForIsomorphy( target.PatternElement.Name, isomorphy.PatternElementsToCheckAgainstAsListOfStrings(), negativeIndependentNamePrefix, isNode, isoSpaceNeverAboveMaxIsoSpace, isomorphy.Parallel, isomorphy.LockForAllThreads); insertionPoint = insertionPoint.Append(checkIsomorphy); } // accept candidate (write isomorphy information) if (isomorphy.SetIsMatchedBit) { AcceptCandidate acceptCandidate = new AcceptCandidate( target.PatternElement.Name, negativeIndependentNamePrefix, isNode, 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, isNode, isoSpaceNeverAboveMaxIsoSpace, isomorphy.Parallel, isomorphy.LockForAllThreads); insertionPoint = insertionPoint.Append(abandonCandidate); } return insertionPoint; }