internal FA Synthesize(CCharRangeSet set)
    {
        FAGraphQueryInfo FAInfo;

        m_currentFA    = new FA();
        m_ThompsonInfo = new ThompsonInfo(m_currentFA, m_ThompsonInfoKey);
        FAInfo         = new FAGraphQueryInfo(m_currentFA, FA.m_FAINFOKEY);

        //2.Create nodes initial-final
        CGraphNode init  = m_currentFA.CreateGraphNode <CGraphNode>();
        CGraphNode final = m_currentFA.CreateGraphNode <CGraphNode>();

        m_ThompsonInfo.InitNodeInfo(init, new ThompsonNodeFAInfo());
        m_ThompsonInfo.InitNodeInfo(final, new ThompsonNodeFAInfo());

        m_currentFA.M_Initial = init;
        m_currentFA.SetFinalState(final);
        m_currentFA.M_Alphabet.AddSet(set);

        //3.Draw the edge including the character
        CGraphEdge newEdge = m_currentFA.AddGraphEdge <CGraphEdge, CGraphNode>(init, final, GraphType.GT_DIRECTED);

        FAInfo.Info(newEdge).M_TransitionCharSet = set;

        return(m_currentFA);
    }
Example #2
0
        public override FA VisitRegexpbasicSet(CASTElement currentNode)
        {
            CRegexpbasicSet  setNode = currentNode as CRegexpbasicSet;
            FAGraphQueryInfo FAInfo;

            //Create FA
            m_NFA  = new FA();
            FAInfo = new FAGraphQueryInfo(m_NFA, FA.m_FAINFOKEY);
            CGraphNode init  = m_NFA.CreateGraphNode <CGraphNode>();
            CGraphNode final = m_NFA.CreateGraphNode <CGraphNode>();

            m_NFA.M_Initial = init;
            m_NFA.SetFinalState(final);
            m_NFA.M_Alphabet.AddSet(setNode.MSet);

            CGraphEdge newEdge = m_NFA.AddGraphEdge <CGraphEdge, CGraphNode>(init, final, GraphType.GT_DIRECTED);

            FAInfo.Info(newEdge).M_TransitionCharSet = setNode.MSet;
            //4.Pass FA to the predecessor

            m_NFA.PrefixGraphElementLabels(m_currentRegularExpression.M_StatementID, GraphElementType.ET_NODE);

            m_ReportingServices.ExctractThompsonStep(m_NFA, @"../Debug/BasicSet_" + setNode.MSet.ToString() + ".dot");
            m_ReportingServices.AddThompsonStepToReporting(m_NFA);

            return(m_NFA);
        }
Example #3
0
        public override FA VisitRange(CASTElement currentNode)
        {
            CRange           rangeNode = currentNode as CRange;
            FAGraphQueryInfo FAInfo;

            //1.Create FA
            m_NFA  = new FA();
            FAInfo = new FAGraphQueryInfo(m_NFA, FA.m_FAINFOKEY);
            //2.Create nodes initial-final
            CGraphNode init  = m_NFA.CreateGraphNode <CGraphNode>();
            CGraphNode final = m_NFA.CreateGraphNode <CGraphNode>();

            m_NFA.M_Initial = init;
            m_NFA.SetFinalState(final);
            m_NFA.M_Alphabet.AddRange(rangeNode.MRange);

            //3.Draw the edge including the character
            CGraphEdge newEdge = m_NFA.AddGraphEdge <CGraphEdge, CGraphNode>(init, final, GraphType.GT_DIRECTED);

            FAInfo.Info(newEdge).M_TransitionCharSet = (CCharRangeSet)rangeNode.MRange;
            newEdge.SetLabel(rangeNode.MRange.ToString());

            m_ReportingServices.ExctractThompsonStep(m_NFA, @"../Debug/Range_" + rangeNode.MRange.ToString() + ".dot");
            m_ReportingServices.AddThompsonStepToReporting(m_NFA);
            //4.Pass FA to the predecessor
            return(m_NFA);
        }
        /// <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);

            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
            graphvizStringBuilder.Append(header);


            // Print all  nodes
            for (itn.Begin(); !itn.End(); itn.Next())
            {
                graphvizStringBuilder.Append("\"" + itn.M_CurrentItem.M_Label + "\";");
            }
            // 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);
                graphvizStringBuilder.AppendFormat(" [style = bold, label = \"" + g.M_Label + "\"]");

                graphvizStringBuilder.Append(";\r\n");
            }
            // Print footer if necessary
            graphvizStringBuilder.Append("}\r\n");
            return(graphvizStringBuilder);
        }
        public override HashSet <CGraphNode> Visit(CGraphNode node)
        {
            CCharRangeSet  set;
            CIt_Successors it = new CIt_Successors(node);

            for (it.Begin(); !it.End(); it.Next())
            {
                CGraphEdge edge = m_graph.Edge(node, it.M_CurrentItem);
                set = m_graph.GetFAEdgeInfo(edge);
                if (set != null && set.IsCharInSet(m_character))
                {
                    m_outputSet.Add(it.M_CurrentItem);
                }
            }
            return(m_outputSet);
        }
Example #6
0
        /// <summary>
        /// Checks if there is an existing condensed map edge for the given
        /// original Graph edge
        /// </summary>
        /// <param name="originalGraphEdge"></param>
        /// <returns></returns>
        public CGraphEdge AddCondensedEdge(CGraphEdge originalGraphEdge)
        {
            CGraphEdge newedge = null;

            // Add the edge if :
            // 1. The original graph edges has not already being mapped to a condensed graph edge
            // 2. Source and Target nodes belong to different condensed node ( covers the case of
            // one or both being null )
            if (m_edgeOriginalToCondensedMappings[originalGraphEdge] == null &&
                m_nodeMappings[originalGraphEdge.M_Source] != m_nodeMappings[originalGraphEdge.M_Target])
            {
                newedge = AddGraphEdge(m_nodeMappings[originalGraphEdge.M_Source],
                                       m_nodeMappings[originalGraphEdge.M_Target], originalGraphEdge.M_EdgeType);
                m_edgeOriginalToCondensedMappings[originalGraphEdge] = newedge;
                m_edgeCondensedToOriginalMappings[newedge]           = originalGraphEdge;
            }
            return(newedge);
        }
Example #7
0
 /// <summary>
 /// Returns the information of the specified edge. If the information
 /// is not there it returns null instead of dropping an exception
 /// </summary>
 /// <param name="edge">The edge.</param>
 /// <param name="key">The key that will extract the information from the specified node's dictionary. If
 /// null is given then the current Query Info object is used as a key</param>
 /// <returns></returns>
 public override IE Info(CGraphEdge edge, bool checkOwnership = true)
 {
     if (!checkOwnership)
     {
         return((IE)edge[m_infoKey]);
     }
     else
     {
         if (edge.M_OwnerGraph == m_graph)
         {
             return((IE)edge[m_infoKey]);
         }
         else
         {
             throw new Exception("The given edge does not belong to the graph");
         }
     }
 }
Example #8
0
 public override void CreateTempInfo(CGraphEdge edge, IE info, bool checkOwnership = true)
 {
     if (!checkOwnership)
     {
         edge[edge] = info;
     }
     else
     {
         if (edge.M_OwnerGraph == m_graph)
         {
             edge[edge] = info;
         }
         else
         {
             throw new Exception("The given edge does not belong to the graph");
         }
     }
 }
Example #9
0
 public override void CreateTempInfo(CGraphNode source, CGraphNode target, IE info, bool checkOwnership = true)
 {
     if (!checkOwnership)
     {
         CGraphEdge edge = m_graph.Edge(source, target);
         edge[edge] = info;
     }
     else
     {
         if (source.M_OwnerGraph == m_graph && target.M_OwnerGraph == m_graph)
         {
             CGraphEdge edge = m_graph.Edge(source, target);
             edge[edge] = info;
         }
         else
         {
             throw new Exception("The given edge does not belong to the graph");
         }
     }
 }
        public override HashSet <CGraphNode> Visit(CGraphNode node)
        {
            m_outputSet.Add(node);

            //1.For each successor scan the nodes that have outgoing e transitions
            CIt_Successors it = new CIt_Successors(node);

            for (it.Begin(); !it.End(); it.Next())
            {
                //Find the edge between node and its successor
                CGraphEdge edge = m_graph.Edge(node, it.M_CurrentItem);

                //if the edge label is e then visit the successor and append the output set including this successor
                if (TransitionLabel(edge) == null)
                {
                    Visit(it.M_CurrentItem);
                }
            }
            //
            return(m_outputSet);
        }
        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);
        }
Example #12
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 CCharRangeSet TransitionLabel(CGraphEdge edge)
 {
     return(m_graph.GetFAEdgeInfo(edge));
 }
Example #14
0
 public CCharRangeSet GetInputDFAStateTransitionCharacterSet(CGraphEdge edge)
 {
     return(m_nodeConfiguration.Info(edge));
 }
Example #15
0
 public void SetInputDFAStateTransitionCharacterSet(CGraphEdge edge, CCharRangeSet set)
 {
     m_nodeConfiguration.CreateInfo(edge, set);
 }
        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);
        }