Пример #1
0
        void OnTypeInfotagsChanged(GraphElementType type)
        {
            if (type.IsNodeType)
            {
                if (dumpInfo.IsExcludedNodeType((NodeType)type))
                {
                    return;
                }

                foreach (INode node in graph.GetExactNodes((NodeType)type))
                {
                    ycompStream.Write("setNodeLabel \"n" + dumpInfo.GetElementName(node) + "\" \"" + GetElemLabel(node) + "\"\n");
                }
            }
            else
            {
                if (dumpInfo.IsExcludedEdgeType((EdgeType)type))
                {
                    return;
                }

                foreach (IEdge edge in graph.GetExactEdges((EdgeType)type))
                {
                    if (IsEdgeExcluded(edge))
                    {
                        return; // additionally checks incident nodes
                    }
                    ycompStream.Write("setEdgeLabel \"e" + dumpInfo.GetElementName(edge) + "\" \"" + GetElemLabel(edge) + "\"\n");
                }
            }
            isDirty = true;
        }
Пример #2
0
 protected GraphElement(GraphElementType type, string name)
 {
     ElementType = type;
     Name        = name;
 }
Пример #3
0
        /// <summary>
        /// Determines which homomorphy check operations are necessary
        /// at the operation of the given position within the scheduled search plan
        /// and appends them.
        /// </summary>
        private static void DetermineAndAppendHomomorphyChecks(IGraphModel model, ScheduledSearchPlan ssp, int j)
        {
            // take care of global homomorphy
            FillInGlobalHomomorphyPatternElements(ssp, j);

            ///////////////////////////////////////////////////////////////////////////
            // first handle special case pure homomorphy

            SearchPlanNode spn_j = (SearchPlanNode)ssp.Operations[j].Element;

            if (spn_j.ElementID == -1)
            {
                // inlined from independent for better matching, independent from the rest
                return;
            }

            bool homToAll = true;

            if (spn_j.NodeType == PlanNodeType.Node)
            {
                for (int i = 0; i < ssp.PatternGraph.nodesPlusInlined.Length; ++i)
                {
                    if (!ssp.PatternGraph.homomorphicNodes[spn_j.ElementID - 1, i])
                    {
                        homToAll = false;
                        break;
                    }
                }
            }
            else //(spn_j.NodeType == PlanNodeType.Edge)
            {
                for (int i = 0; i < ssp.PatternGraph.edgesPlusInlined.Length; ++i)
                {
                    if (!ssp.PatternGraph.homomorphicEdges[spn_j.ElementID - 1, i])
                    {
                        homToAll = false;
                        break;
                    }
                }
            }

            if (homToAll)
            {
                // operation is allowed to be homomorph with everything
                // no checks for isomorphy or restricted homomorphy needed at all
                return;
            }

            ///////////////////////////////////////////////////////////////////////////
            // no pure homomorphy, so we have restricted homomorphy or isomorphy
            // and need to inspect the operations before, together with the homomorphy matrix
            // for determining the necessary homomorphy checks

            GraphElementType[] types;
            bool[,] hom;

            if (spn_j.NodeType == PlanNodeType.Node)
            {
                types = model.NodeModel.Types;
                hom   = ssp.PatternGraph.homomorphicNodes;
            }
            else // (spn_j.NodeType == PlanNodeType.Edge)
            {
                types = model.EdgeModel.Types;
                hom   = ssp.PatternGraph.homomorphicEdges;
            }

            // order operation to check against all elements it's not allowed to be homomorph to

            // iterate through the operations before our position
            bool homomorphyPossibleAndAllowed = false;

            for (int i = 0; i < j; ++i)
            {
                // only check operations computing nodes or edges
                if (ssp.Operations[i].Type == SearchOperationType.Condition ||
                    ssp.Operations[i].Type == SearchOperationType.NegativePattern ||
                    ssp.Operations[i].Type == SearchOperationType.IndependentPattern ||
                    ssp.Operations[i].Type == SearchOperationType.Assign ||
                    ssp.Operations[i].Type == SearchOperationType.AssignVar ||
                    ssp.Operations[i].Type == SearchOperationType.DefToBeYieldedTo ||
                    ssp.Operations[i].Type == SearchOperationType.InlinedIndependentCheckForDuplicateMatch)
                {
                    continue;
                }

                SearchPlanNode spn_i = (SearchPlanNode)ssp.Operations[i].Element;

                if (spn_i.NodeType != spn_j.NodeType)
                {
                    // don't compare nodes with edges
                    continue;
                }

                if (spn_i.ElementID == -1)
                {
                    // inlined from independent for better matching, independent from the rest
                    continue;
                }

                // find out whether element types are disjoint
                GraphElementType type_i   = types[spn_i.PatternElement.TypeID];
                GraphElementType type_j   = types[spn_j.PatternElement.TypeID];
                bool             disjoint = true;
                foreach (GraphElementType subtype_i in type_i.SubOrSameTypes)
                {
                    if (type_j.IsA(subtype_i) || subtype_i.IsA(type_j)) // IsA==IsSuperTypeOrSameType
                    {
                        disjoint = false;
                        break;
                    }
                }

                if (disjoint)
                {
                    // don't check elements if their types are disjoint
                    continue;
                }

                // at this position we found out that spn_i and spn_j
                // might get matched to the same host graph element, i.e. homomorphy is possible

                // if that's ok we don't need to insert checks to prevent this from happening
                if (hom[spn_i.ElementID - 1, spn_j.ElementID - 1])
                {
                    homomorphyPossibleAndAllowed = true;
                    continue;
                }

                // otherwise the generated matcher code has to check
                // that pattern element j doesn't get bound to the same graph element
                // the pattern element i is already bound to
                if (ssp.Operations[j].Isomorphy.PatternElementsToCheckAgainst == null)
                {
                    ssp.Operations[j].Isomorphy.PatternElementsToCheckAgainst = new List <SearchPlanNode>();
                }
                ssp.Operations[j].Isomorphy.PatternElementsToCheckAgainst.Add(spn_i);

                // if spn_j might get matched to the same host graph element as spn_i and this is not allowed
                // make spn_i set the is-matched-bit so that spn_j can detect this situation
                ssp.Operations[i].Isomorphy.SetIsMatchedBit = true;
            }

            // only if elements, the operation must be isomorph to, were matched before
            // (otherwise there were only elements, the operation is allowed to be homomorph to,
            //  matched before, so no check needed here)
            if (ssp.Operations[j].Isomorphy.PatternElementsToCheckAgainst != null &&
                ssp.Operations[j].Isomorphy.PatternElementsToCheckAgainst.Count > 0)
            {
                // order operation to check whether the is-matched-bit is set
                ssp.Operations[j].Isomorphy.CheckIsMatchedBit = true;
            }

            // if no check for isomorphy was skipped due to homomorphy being allowed
            // pure isomorphy is to be guaranteed - simply check the is-matched-bit and be done
            // the pattern elements to check against are only needed
            // if spn_j is allowed to be homomorph to some elements but must be isomorph to some others
            if (ssp.Operations[j].Isomorphy.CheckIsMatchedBit && !homomorphyPossibleAndAllowed)
            {
                ssp.Operations[j].Isomorphy.PatternElementsToCheckAgainst = null;
            }
        }
Пример #4
0
 public CConnection GRAPHELEMENTTYPE(GraphElementType type)
 {
     m_elementType = type;
     return(this);
 }
 public static bool ToBoolean(this GraphElementType value)
 {
     return(value != GraphElementType.ET_NA);
 }
 protected CGraphPrimitive(GraphElementType etype, CGraph owner = null)
 {
     m_algorithmOutput = new Dictionary <object, object>();
     M_ElementType     = etype;
     m_graph           = owner;
 }
Пример #7
0
        public void RetypingElement(IGraphElement oldElem, IGraphElement newElem)
        {
            bool             isNode  = oldElem is INode;
            GraphElementType oldType = oldElem.Type;
            GraphElementType newType = newElem.Type;

            // TODO: Add element, if old element was excluded, but new element is not
            if (isNode)
            {
                INode oldNode = (INode)oldElem;
                if (IsNodeExcluded(oldNode))
                {
                    return;
                }
            }
            else
            {
                IEdge oldEdge = (IEdge)oldElem;
                if (IsEdgeExcluded(oldEdge))
                {
                    return;
                }
                if (hiddenEdges.ContainsKey(oldEdge))
                {
                    return;       // TODO: Update group relation
                }
            }

            String elemKind       = isNode ? "Node" : "Edge";
            String elemNamePrefix = isNode ? "n" : "e";
            String oldName        = elemNamePrefix + graph.GetElementName(oldElem);

            ycompStream.Write("set" + elemKind + "Label \"" + oldName + "\" \"" + GetElemLabel(newElem) + "\"\n");

            // remove the old attributes
            foreach (AttributeType attrType in oldType.AttributeTypes)
            {
                String attrTypeString;
                String attrValueString;
                EncodeAttr(attrType, oldElem, out attrTypeString, out attrValueString);
                ycompStream.Write("clear" + elemKind + "Attr \"" + oldName + "\" \"" + attrType.OwnerType.Name + "::" + attrType.Name + " : "
                                  + attrTypeString + "\"\n");
            }
            // set the new attributes
            foreach (AttributeType attrType in newType.AttributeTypes)
            {
                String attrTypeString;
                String attrValueString;
                EncodeAttr(attrType, newElem, out attrTypeString, out attrValueString);
                ycompStream.Write("change" + elemKind + "Attr \"" + oldName + "\" \"" + attrType.OwnerType.Name + "::" + attrType.Name + " : "
                                  + attrTypeString + "\" \"" + attrValueString + "\"\n");
            }

            if (isNode)
            {
                String oldNr = realizers.GetNodeRealizer((NodeType)oldType, dumpInfo);
                String newNr = realizers.GetNodeRealizer((NodeType)newType, dumpInfo);
                if (oldNr != newNr)
                {
                    ChangeNode((INode)oldElem, newNr);
                }
            }
            else
            {
                String oldEr = realizers.GetEdgeRealizer((EdgeType)oldType, dumpInfo);
                String newEr = realizers.GetEdgeRealizer((EdgeType)newType, dumpInfo);
                if (oldEr != newEr)
                {
                    ChangeEdge((IEdge)oldElem, newEr);
                }
            }

            String newName = elemNamePrefix + graph.GetElementName(newElem);

            ycompStream.Write("rename" + elemKind + " \"" + oldName + "\" \"" + newName + "\"\n");

            isDirty = true;
        }
Пример #8
0
        public void RetypingElement(IGraphElement oldElem, IGraphElement newElem)
        {
            bool             isNode  = oldElem is INode;
            GraphElementType oldType = oldElem.Type;
            GraphElementType newType = newElem.Type;

            if (isNode)
            {
                if (dumpInfo.IsExcludedNodeType((NodeType)oldType))
                {
                    return;
                }
            }
            else
            {
                if (dumpInfo.IsExcludedEdgeType((EdgeType)oldType))
                {
                    return;
                }
            }

            String elemKind       = isNode ? "Node" : "Edge";
            String elemNamePrefix = isNode ? "n" : "e";
            String name           = elemNamePrefix + graph.GetElementName(oldElem);

            ycompStream.Write("set" + elemKind + "Label \"" + name + "\" \"" + GetElemLabel(newElem) + "\"\n");

            // remove the old attributes
            foreach (AttributeType attrType in oldType.AttributeTypes)
            {
                ycompStream.Write("clear" + elemKind + "Attr \"" + name + "\" \"" + attrType.OwnerType.Name + "::"
                                  + attrType.Name + " : " + GetKindName(attrType) + "\"\n");
            }
            // set the new attributes
            foreach (AttributeType attrType in newType.AttributeTypes)
            {
                object attr       = newElem.GetAttribute(attrType.Name);
                String attrString = (attr != null) ? attr.ToString() : "<Not initialized>";
                ycompStream.Write("change" + elemKind + "Attr \"" + name + "\" \"" + attrType.OwnerType.Name + "::"
                                  + attrType.Name + " : " + GetKindName(attrType) + "\" \"" + attrString + "\"\n");
            }

            if (isNode)
            {
                String oldNr = GetNodeRealizer((NodeType)oldType);
                String newNr = GetNodeRealizer((NodeType)newType);
                if (oldNr != newNr)
                {
                    ChangeNode((INode)oldElem, newNr);
                }
            }
            else
            {
                String oldEr = GetEdgeRealizer((EdgeType)oldType);
                String newEr = GetEdgeRealizer((EdgeType)newType);
                if (oldEr != newEr)
                {
                    ChangeEdge((IEdge)oldElem, newEr);
                }
            }
            isDirty = true;
        }