private void btnAutomatoPilha_Click(object sender, EventArgs e) { btnGreibach_Click(null, null); StackAutoma automato = new StackAutoma(fng.Normalized); Desenha(automato); lbDefinicao.Items.Clear(); lbDefinicao.Items.Add(string.Format("M=({{{0}}}, {{{1}}}, P, {{{2}}}, {{{3}}}, {{{4}}})", string.Join(",", automato.Alphabet.Select(a => a.Name).ToArray()), string.Join(",", automato.ObterEstados()), automato.StartState.Name, string.Join(",", automato.ObterEstadosFinais()), string.Join(",", automato.StackAlphabet.Select(a => a + "").ToArray()))); lbDefinicao.Items.Add("P={"); foreach (Transition transicao in transicoes) { lbDefinicao.Items.Add(string.Format(" P({0},{1}, {2}) = {{({3}, {4})}}", transicao.Source.Name, transicao.Symbol, transicao.ConsumingStack[0], transicao.Destiny.Name, string.Join(",", transicao.PushStack[0].Name.ToArray()))); } lbDefinicao.Items.Add("}"); }
/// <summary> /// Desenha o autômato. /// </summary> private void Desenha(StackAutoma automato) { Graph grafoAutomato = new Graph("Autômato"); transicoes = new List <Transition>(); // Adiciona elementos com base nas transições foreach (KeyValuePair <string, State> estado in automato.States) { Node no = grafoAutomato.AddNode(estado.Key); no.Attr.Shape = Shape.Circle; // Faz marcações no grafo.. if (estado.Value.Final) { no.Attr.Shape = Shape.DoubleCircle; } if (estado.Value == automato.StartState) { no.Attr.FillColor = Microsoft.Msagl.Drawing.Color.LightGray; } transicoes.AddRange(estado.Value.Transitions); } foreach (Transition transicao in transicoes) { Edge arco = grafoAutomato.AddEdge(transicao.Source.Name, transicao.Destiny.Name); arco.LabelText = string.Format("({0}, {1}, {{{2}}})", transicao.Symbol, transicao.ConsumingStack[0], string.Join(",", transicao.PushStack.ToArray().Select(c => c.Name).ToArray())); } GViewer viewer = new GViewer(); viewer.NavigationVisible = false; viewer.OutsideAreaBrush = Brushes.White; //viewer.RemoveToolbar(); viewer.Graph = grafoAutomato; viewer.Dock = System.Windows.Forms.DockStyle.Fill; pnlAutomato.Controls.Clear(); pnlAutomato.Controls.Add(viewer); }
/// <summary> /// Desenha o autômato. /// </summary> private void Desenha(StackAutoma automato) { Graph grafoAutomato = new Graph("Autômato"); transicoes = new List<Transition>(); // Adiciona elementos com base nas transições foreach (KeyValuePair<string, State> estado in automato.States) { Node no = grafoAutomato.AddNode(estado.Key); no.Attr.Shape = Shape.Circle; // Faz marcações no grafo.. if (estado.Value.Final) { no.Attr.Shape = Shape.DoubleCircle; } if (estado.Value == automato.StartState) { no.Attr.FillColor = Microsoft.Msagl.Drawing.Color.LightGray; } transicoes.AddRange(estado.Value.Transitions); } foreach (Transition transicao in transicoes) { Edge arco = grafoAutomato.AddEdge(transicao.Source.Name, transicao.Destiny.Name); arco.LabelText = string.Format("({0}, {1}, {{{2}}})", transicao.Symbol, transicao.ConsumingStack[0], string.Join(",", transicao.PushStack.ToArray().Select(c => c.Name).ToArray())); } GViewer viewer = new GViewer(); viewer.NavigationVisible = false; viewer.OutsideAreaBrush = Brushes.White; //viewer.RemoveToolbar(); viewer.Graph = grafoAutomato; viewer.Dock = System.Windows.Forms.DockStyle.Fill; pnlAutomato.Controls.Clear(); pnlAutomato.Controls.Add(viewer); }