Пример #1
0
        private void AddNode(int layer, DAG.Node parentNode, int vertexIndex,
                             List <DAG.Arc> layerArcs, List <DAG.Arc> usedArcs,
                             List <DAG.Node> nextLayer)
        {
            // look up the mapping or create a new mapping for the vertex index
            int mappedVertexIndex;

            if (vertexMapping.ContainsKey(vertexIndex))
            {
                mappedVertexIndex = vertexMapping[vertexIndex];
            }
            else
            {
                vertexMapping[vertexIndex] = vertexCount;
                mappedVertexIndex          = vertexCount;
                vertexCount++;
            }

            // find an existing node if there is one
            var arc = new DAG.Arc(parentNode.vertexIndex, mappedVertexIndex);

            if (usedArcs.Contains(arc))
            {
                return;
            }
            DAG.Node existingNode = null;
            foreach (var otherNode in nextLayer)
            {
                if (otherNode.vertexIndex == mappedVertexIndex)
                {
                    existingNode = otherNode;
                    break;
                }
            }

            // if there isn't, make a new node and add it to the layer
            if (existingNode == null)
            {
                existingNode = dag.MakeNode(mappedVertexIndex, layer);
                nextLayer.Add(existingNode);
            }

            // add the edge label to the node's edge label list
            int originalParentIndex =
                GetOriginalVertexIndex(parentNode.vertexIndex);
            string edgeLabel = GetEdgeLabel(originalParentIndex, vertexIndex);
            int    edgeColor = ConvertEdgeLabelToColor(edgeLabel);

            existingNode.AddEdgeColor(parentNode.vertexIndex, edgeColor);
            parentNode.AddEdgeColor(mappedVertexIndex, edgeColor);

            dag.AddRelation(existingNode, parentNode);
            layerArcs.Add(arc);
        }
Пример #2
0
        /// <summary>
        /// Recursively print the signature into the buffer.
        /// </summary>
        /// <param name="buffer">the string buffer to print into</param>
        /// <param name="node">the current node of the signature</param>
        /// <param name="parent">the parent node, or null</param>
        /// <param name="arcs">the list of already visited arcs</param>
        private void Print(StringBuilder buffer, DAG.Node node, DAG.Node parent, List <DAG.Arc> arcs)
        {
            int vertexIndex = GetOriginalVertexIndex(node.vertexIndex);

            // print out any symbol for the edge in the input graph
            if (parent != null)
            {
                int parentVertexIndex = GetOriginalVertexIndex(parent.vertexIndex);
                buffer.Append(GetEdgeLabel(vertexIndex, parentVertexIndex));
            }

            // print out the text that represents the node itself
            buffer.Append(AbstractVertexSignature.StartNodeSymbolChar);
            buffer.Append(GetVertexSymbol(vertexIndex));
            int color = dag.ColorFor(node.vertexIndex);

            if (color != -1)
            {
                buffer.Append(',').Append(color);
            }
            buffer.Append(AbstractVertexSignature.EndNodeSymbolChar);

            // Need to sort the children here, so that they are printed in an order
            // according to their invariants.
            node.children.Sort(dag.nodeComparator);

            // now print the sorted children, surrounded by branch symbols
            bool addedBranchSymbol = false;

            foreach (var child in node.children)
            {
                DAG.Arc arc = new DAG.Arc(node.vertexIndex, child.vertexIndex);
                if (arcs.Contains(arc))
                {
                    continue;
                }
                else
                {
                    if (!addedBranchSymbol)
                    {
                        buffer.Append(AbstractVertexSignature.StartBranchSymbolChar);
                        addedBranchSymbol = true;
                    }
                    arcs.Add(arc);
                    Print(buffer, child, node, arcs);
                }
            }
            if (addedBranchSymbol)
            {
                buffer.Append(AbstractVertexSignature.EndBranchSymbolChar);
            }
        }