예제 #1
0
        public override void Init()
        {
            // Create output graph
            AddOutputGraph(m_condensedGraph);

            // TODO!!!  Check the existence of none unique nodes per condensed node
            // TODO!!!!!
            CIt_GraphEdges it = new CIt_GraphEdges(m_sourceGraph);
            CGraphEdge     edge, newEdge;
            CGraphNode     newNode;

            CCondensedGraph newgraph = new CCondensedGraph(originalGraph);

            // Add condensed nodes
            foreach (List <CGraphNode> condensedNodeContent in condensedNodeContents)
            {
                newNode = newgraph.CreateGraphNode(condensedNodeContent);
            }
            // Add condensed edges
            for (edge = it.Begin(); !it.End(); edge = it.Next())
            {
                // Map the original graph edge to a condensed graph edge
                newEdge = newgraph.AddCondensedEdge(edge);
                if (newEdge != null)
                {
                }
            }
            return(newgraph);
        }
예제 #2
0
        public override StringBuilder Print()
        {
            StringBuilder FAText = new StringBuilder(1000);

            // Output Nodes
            CIt_GraphNodes itn = new CIt_GraphNodes(m_graph);

            for (itn.Begin(); !itn.End(); itn.Next())
            {
                FAText.Append(itn.M_CurrentItem.M_Label);
                if (!itn.M_LastItem)
                {
                    FAText.Append(", ");
                }
                else
                {
                    FAText.Append("\n\n");
                }
            }

            // Output edges
            CIt_GraphEdges ite = new CIt_GraphEdges(m_graph);

            for (ite.Begin(); !ite.End(); ite.Next())
            {
                FAText.Append("\n" + ite.M_CurrentItem.M_Source.M_Label + "---" + m_FAInfo.Info(ite.M_CurrentItem).M_TransitionCharSet.ToString() + "---->" +
                              ite.M_CurrentItem.M_Target.M_Label);
            }

            return(FAText);
        }
예제 #3
0
        public override int Run()
        {
            Init();

            CIt_GraphEdges ite = new CIt_GraphEdges(mGraph);

            for (int i = 0; i < mGraph.M_NumberOfNodes - 1; i++)
            {
#if DEBUG
                Console.WriteLine("Iteration : {0}", i);
#endif
                for (ite.Begin(); !ite.End(); ite.Next())
                {
                    Relax(ite.M_CurrentItem.M_Source, ite.M_CurrentItem.M_Target);
                }
            }

            for (ite.Begin(); !ite.End(); ite.Next())
            {
                if (Distance(ite.M_CurrentItem.M_Target) > Distance(ite.M_CurrentItem.M_Source) +
                    Weight(ite.M_CurrentItem.M_Source, ite.M_CurrentItem.M_Target))
                {
                    throw new Exception("The graph contains negative cycles");
                }
            }
            GeneratePaths();
#if DEBUG
            Debug();
#endif
            return(0);
        }
        public override void Init()
        {
            //Initialize the algorithm information
            CIt_GraphEdges itg = new CIt_GraphEdges(m_sourceGraphs[0]);

            for (itg.Begin(); !itg.End(); itg.Next())
            {
                // Mark the edges unvisited
                //CreateInfo(itg.M_CurrentItem,new EdgeInfo_DFS(0),this);
            }

            // Iterate over all possible edges of the graph
            for (itg.Begin(); !itg.End(); itg.Next())
            {
                Visit(itg.M_CurrentItem);
            }
        }
        /// <summary>
        /// Returns a string that contains the element and its info contents
        /// </summary>
        /// <returns></returns>
        public override string ToString()
        {
            StringBuilder sBuilder = new StringBuilder();
            string        s        = "";

            switch (M_ElementType)
            {
            case GraphElementType.ET_NODE:
                s = "Node ";
                break;

            case GraphElementType.ET_EDGE:
                s = "Edge ";
                break;

            case GraphElementType.ET_GRAPH:
                s = "Graph ";
                break;
            }
            sBuilder.Append(s + M_Label + ":");
            sBuilder.AppendLine();

            foreach (KeyValuePair <object, object> key in m_algorithmOutput)
            {
                sBuilder.Append("key :" + key.Key.ToString());
                sBuilder.Append("info :" + key.Value.ToString());
            }

            if (M_ElementType == GraphElementType.ET_GRAPH)
            {
                CIt_GraphNodes itn = new CIt_GraphNodes(this as CGraph);
                for (itn.Begin(); !itn.End(); itn.Next())
                {
                    sBuilder.Append(itn.M_CurrentItem.ToString());
                    sBuilder.AppendLine();
                }
                CIt_GraphEdges itg = new CIt_GraphEdges(this as CGraph);
                for (itg.Begin(); !itg.End(); itg.Next())
                {
                    sBuilder.Append(itg.M_CurrentItem.ToString());
                    sBuilder.AppendLine();
                }
            }
            return(sBuilder.ToString());
        }
예제 #6
0
        public override StringBuilder Print()
        {
            StringBuilder  bucket = new StringBuilder(1000);
            CIt_GraphEdges ite    = new CIt_GraphEdges(m_DFA);

            bucket.Append(m_DFA.M_Initial.M_Label);
            for (ite.Begin(); !ite.End(); ite.Next())
            {
                bucket.Append("\\" + ite.M_CurrentItem.M_Source.M_Label + "-" + ite.M_CurrentItem.M_Target.M_Label);
                bucket.Append(m_DFA.GetFAEdgeInfo(ite.M_CurrentItem).ToString());
            }

            foreach (var fstate in m_DFA.GetFinalStates())
            {
                bucket.Append("(" + fstate.M_Label + ")");
            }
            return(bucket);
        }
        public override StringBuilder Print()
        {
            StringBuilder  graphvizStringBuilder = new StringBuilder(1000);
            string         header             = "digraph G" + m_graph.M_SerialNumber + "{\r\n";
            string         graphedge_operator = "->";
            CIt_GraphNodes itn = new CIt_GraphNodes(m_graph);
            CIt_GraphEdges itg = new CIt_GraphEdges(m_graph);
            FA             fa  = m_graph as FA;

            // Print header if necessary
            // Print the header if the graph is printed alone independently and not
            // in the context for example of a multigraph printing
            if (!m_options.IsSet(ThompsonOptions.TO_COMBINEGRAPHS))
            {
                graphvizStringBuilder.Append(header);
            }

            for (itn.Begin(); !itn.End(); itn.Next())
            {
                if (fa.GetFinalStates().Count != 0 && fa.GetFinalStates().Contains(itn.M_CurrentItem))
                {
                    graphvizStringBuilder.Append("\"" + itn.M_CurrentItem.M_Label + "\" [peripheries=2];\n");
                }
                else if (itn.M_CurrentItem == fa.M_Initial)
                {
                    graphvizStringBuilder.Append("\"" + itn.M_CurrentItem.M_Label + "\" [style=filled,fillcolor=green];\n");
                }
                else if (m_thompsonInfo.IsNodeClosureEntrance(itn.M_CurrentItem))
                {
                    graphvizStringBuilder.Append("\"" + itn.M_CurrentItem.M_Label + "\" [style=filled,fillcolor=red];\n");
                }
                else if (m_thompsonInfo.IsNodeClosureExit(itn.M_CurrentItem))
                {
                    graphvizStringBuilder.Append("\"" + itn.M_CurrentItem.M_Label + "\" [style=filled,fillcolor=purple];\n");
                }
                else
                {
                    graphvizStringBuilder.Append("\"" + itn.M_CurrentItem.M_Label + "\";\n");
                }
            }

            // Print all edges of the graph
            for (itg.Begin(); !itg.End(); itg.Next())
            {
                CGraphEdge g = itg.M_CurrentItem;

                string source, target;
                source = g.M_Source.M_Label;
                target = g.M_Target.M_Label;

                graphvizStringBuilder.AppendFormat("\"{0}\"" + graphedge_operator + "\"{1}\"",
                                                   source, target);
                string s = m_FAInfo.Info(g).M_TransitionCharSet?.ToString();
                if (s != null)
                {
                    graphvizStringBuilder.AppendFormat(" [style = bold, label = \"" + m_FAInfo.Info(g).M_TransitionCharSet?.ToString() + "\"]");
                }
                else
                {
                    if (m_thompsonInfo.IsNodeClosureExit(g.M_Source) &&
                        m_thompsonInfo.IsNodeClosureEntrance(g.M_Target))
                    {
                        graphvizStringBuilder.AppendFormat(" [color=red,style = bold, label = \"" + m_FAInfo.Info(g).M_TransitionCharSet?.ToString() + "\"]");
                    }
                }

                graphvizStringBuilder.Append(";\r\n");
            }

            // Print footer if necessary
            // Print the header if the graph is printed alone independently and not
            // in the context for example of a multigraph printing
            if (!m_options.IsSet(ThompsonOptions.TO_COMBINEGRAPHS))
            {
                graphvizStringBuilder.Append("}\r\n");
            }

            return(graphvizStringBuilder);
        }
예제 #8
0
        /// <summary>
        /// Prints the graph into a StringBuilder object.
        /// Optionally the header and footer of the .dot file can be ommited for use of the
        /// graph edges in the multi layer graph printer.
        /// </summary>
        /// <param name="onlyedges">if set to <c>true</c> [onlyedges] the graph is printed as a standalone graph.</param>
        /// <returns></returns>
        /// <exception cref="System.NotImplementedException"></exception>
        public override StringBuilder Print()
        {
            // Allocate a stringbuiler object and allocate space for 1000 characters
            StringBuilder  graphvizStringBuilder = new StringBuilder(1000);
            string         graphedge_operator    = " ";
            string         header           = "";
            string         headerProperties = "";
            CIt_GraphNodes itn = new CIt_GraphNodes(m_graph);
            CIt_GraphEdges itg = new CIt_GraphEdges(m_graph);
            FA             fa  = m_graph as FA;

            switch (m_graph.M_GraphType)
            {
            case GraphType.GT_UNDIRECTED:
                graphedge_operator = "--";
                header             = "graph G" + m_graph.M_SerialNumber + "{\r\n";
                header            += headerProperties;
                break;

            case GraphType.GT_DIRECTED:
                graphedge_operator = "->";
                header             = "digraph G" + m_graph.M_SerialNumber + "{\r\n";
                header            += headerProperties;
                break;

            case GraphType.GT_MIXED:
                break;
            }

            // Print header if necessary
            // Print the header if the graph is printed alone independently and not
            // in the context for example of a multigraph printing
            if (!m_options.IsSet(ThompsonOptions.TO_COMBINEGRAPHS))
            {
                graphvizStringBuilder.Append(header);
            }


            // Print all  nodes
            for (itn.Begin(); !itn.End(); itn.Next())
            {
                if (fa.GetFinalStates().Count != 0 && fa.GetFinalStates().Contains(itn.M_CurrentItem))
                {
                    graphvizStringBuilder.Append("\"" + itn.M_CurrentItem.M_Label + "\" [peripheries=2];\n");
                }
                else if (itn.M_CurrentItem == fa.M_Initial)
                {
                    graphvizStringBuilder.Append("\"" + itn.M_CurrentItem.M_Label + "\" [style=filled,fillcolor=green];\n");
                }
                else
                {
                    graphvizStringBuilder.Append("\"" + itn.M_CurrentItem.M_Label + "\";\n");
                }
            }
            // Print all edges of the graph
            for (itg.Begin(); !itg.End(); itg.Next())
            {
                CGraphEdge g = itg.M_CurrentItem;

                string source, target;
                source = g.M_Source.M_Label;
                target = g.M_Target.M_Label;

                graphvizStringBuilder.AppendFormat("\"{0}\"" + graphedge_operator + "\"{1}\"",
                                                   source, target);
                string s = m_FAInfo.Info(g).M_TransitionCharSet?.ToString();
                if (s != null)
                {
                    graphvizStringBuilder.AppendFormat(" [style = bold, label = \"" + m_FAInfo.Info(g).M_TransitionCharSet?.ToString() + "\"]");
                }
                else
                {
                }

                graphvizStringBuilder.Append(";\r\n");
            }
            // Print footer if necessary
            // Print the header if the graph is printed alone independently and not
            // in the context for example of a multigraph printing
            if (!m_options.IsSet(ThompsonOptions.TO_COMBINEGRAPHS))
            {
                graphvizStringBuilder.Append("}\r\n");
            }

            return(graphvizStringBuilder);
        }
        public override StringBuilder Print()
        {
            // Allocate a stringbuiler object and allocate space for 1000 characters
            StringBuilder           graphvizStringBuilder = new StringBuilder(1000);
            CIt_GraphNodes          itn        = new CIt_GraphNodes(m_graph);
            CIt_GraphEdges          itg        = new CIt_GraphEdges(m_graph);
            CSubsetConstructionInfo subsetInfo = new CSubsetConstructionInfo(m_graph, m_subsetInfoKey);
            Dictionary <int, List <CGraphNode> > closuresMap;
            FA     fa = m_graph as FA;
            string graphedge_operator = "->";

            closuresMap = subsetInfo.GetClosureNodesMapping();

            //1. generate header
            string header = "digraph G" + m_graph.M_SerialNumber + "{\r\n";

            graphvizStringBuilder.Append(header);


            foreach (KeyValuePair <int, List <CGraphNode> > closure in closuresMap)
            {
                string subgraphHeader = "\tsubgraph cluster" + closure.Key + " {\r\n";
                string subgraphBody   = "\t\tnode [style=filled];\r\n" +
                                        "\t\tstyle=filled;\r\n" +
                                        "\t\tcolor=lightgrey;\r\n" +
                                        "\t\tlabel =\"" + subsetInfo.Info(closure.Value[0]).M_ClosureExpression +
                                        "\";\r\n\t\t";
                graphvizStringBuilder.Append(subgraphHeader + subgraphBody);
                foreach (CGraphNode node in closure.Value)
                {
                    graphvizStringBuilder.Append(node.M_Label + ";");
                }

                graphvizStringBuilder.AppendLine();
                graphvizStringBuilder.Append("\t}");
            }


            // Print all  nodes
            for (itn.Begin(); !itn.End(); itn.Next())
            {
                if (fa.GetFinalStates().Count != 0 && fa.GetFinalStates().Contains(itn.M_CurrentItem))
                {
                    graphvizStringBuilder.Append("\"" + itn.M_CurrentItem.M_Label + "\" [peripheries=2];\n");
                }
                else if (itn.M_CurrentItem == fa.M_Initial)
                {
                    graphvizStringBuilder.Append("\"" + itn.M_CurrentItem.M_Label +
                                                 "\" [style=filled,fillcolor=green];\n");
                }
                else
                {
                    graphvizStringBuilder.Append("\"" + itn.M_CurrentItem.M_Label + "\";\n");
                }
            }

            // Print all edges of the graph
            for (itg.Begin(); !itg.End(); itg.Next())
            {
                CGraphEdge g = itg.M_CurrentItem;

                string source, target;
                source = g.M_Source.M_Label;
                target = g.M_Target.M_Label;

                graphvizStringBuilder.AppendFormat("\"{0}\"" + graphedge_operator + "\"{1}\"",
                                                   source, target);
                string s = m_FAInfo.Info(g).M_TransitionCharSet?.ToString();
                if (s != null)
                {
                    graphvizStringBuilder.AppendFormat(" [style = bold, label = \"" + m_FAInfo.Info(g).M_TransitionCharSet?.ToString() + "\"]");
                }
                else
                {
                }
                graphvizStringBuilder.Append(";\r\n");
            }

            graphvizStringBuilder.Append("}\r\n");
            return(graphvizStringBuilder);
        }