Ejemplo n.º 1
0
        private void graficarAfnd()
        {
            string pathDesktop = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
            string pathFolder  = pathDesktop + "\\ER_Analisis\\" + conteoAnalisis + "\\AFND";

            try
            {
                if (!Directory.Exists(pathFolder))
                {
                    DirectoryInfo dir = Directory.CreateDirectory(pathFolder);
                }

                string       pathRep = pathFolder + "\\AFND" + conteoAnalisis + +numEr + ".dot";
                StreamWriter repAFND = new StreamWriter(pathRep);

                //Escribir el archivo dot
                repAFND.WriteLine("digraph AFND{");
                repAFND.WriteLine("rankdir=LR;");
                repAFND.WriteLine("size=\"13\";");
                //Nodo de aceptacion
                int          numEstados = afn.Count - 1;
                nodoThompson aceptacion = (nodoThompson)afn[numEstados];

                repAFND.WriteLine(aceptacion.getEstado() + "[peripheries = 2, shape=circle];");
                //Configuracion de los nodos
                repAFND.WriteLine("node[shape=circle, peripheries=1];");
                repAFND.WriteLine("node[fontcolor=black];");
                repAFND.WriteLine("edge[color=black];");
                //Insertar nodos transicion
                foreach (nodoThompson item in afn)
                {
                    foreach (nodoSiguientes next in item.getTransiciones())
                    {
                        if (next.getDir() == 1)
                        {
                            repAFND.Write(next.getEstadoNext() + " -> " + item.getEstado() + "[label=\"" + next.getValor() + "\", dir=back];\n");
                        }
                        else
                        {
                            repAFND.Write(item.getEstado() + " -> " + next.getEstadoNext() + "[label=\"" + next.getValor() + "\"];\n");
                        }
                    }
                }
                repAFND.WriteLine("}");
                repAFND.Close();

                string pathPng = pathFolder + "\\AFND" + conteoAnalisis + numEr + ".png";
                this.crearImagen(pathRep, pathPng);
            }
            catch (Exception e)
            {
            }
        }
Ejemplo n.º 2
0
        //Arreglar el dato de conjunto
        private int crearCabeceras(string conjunto, int estados, nodoCabecera actualEstado)
        {
            string guiaNuevoEstado = "";

            string[]  stringNum  = conjunto.Split(',');
            ArrayList numEstados = new ArrayList();

            ArrayList valoresEvaluados = new ArrayList();
            string    valorActual      = "";

            char epsilon = (char)603;

            nodoThompson nodoAceptacionGuia = (nodoThompson)tablaAfnd[tablaAfnd.Count - 1];

            //Console.WriteLine("Conjunto guia: " + conjunto);
            //Console.WriteLine("estados guia: " + stringNum.Length);
            //Pasar los estados a numero en arrayList
            foreach (string num in stringNum)
            {
                //Console.WriteLine("numero: " + num);
                numEstados.Add(Int32.Parse(num));

                if (Int32.Parse(num) == nodoAceptacionGuia.getEstado())
                {
                    actualEstado.setAceptacion(true);
                }
            }

            int repetirFor = 2;
            int esConj     = 0;

            while (repetirFor != 0)
            {
                repetirFor--;

                //Encontrar los estados a los que se puede ir por medio de las hojas
                foreach (int state in numEstados)
                {
                    //Extraer el estado del afnd definido por el state
                    nodoThompson auxAfnd = getEstadoAfnd(state);

                    if (auxAfnd.getTransiciones() != null)
                    {
                        //Evaluar las transiciones no iguales a epsilon
                        foreach (nodoSiguientes stateNext in auxAfnd.getTransiciones())
                        {
                            //Si el valor es igual al que estoy evaluando
                            if (valorActual.Equals(stateNext.getValor()))
                            {
                                //Concatenar el estado a la guia de estados
                                guiaNuevoEstado += "," + stateNext.getEstadoNext().ToString();
                            }
                            //Si el valor actual es nulo
                            else if (valorActual.Equals(""))
                            {
                                //Verificar que aun no se haya evaluado
                                if (valoresEvaluados.Contains(stateNext.getValor()))
                                {
                                    //Si ya esta evaluado pasar al siguiente nodo
                                }
                                else
                                {
                                    //Si no es igual a epsilon
                                    if (!epsilon.ToString().Equals(stateNext.getValor()))
                                    {
                                        //Asignar el valor evaluando
                                        valorActual     = stateNext.getValor();
                                        guiaNuevoEstado = stateNext.getEstadoNext().ToString();
                                        valoresEvaluados.Add(valorActual);
                                        esConj = stateNext.getEsConj();
                                    }
                                }
                            }
                            //Si el valor es epsilon
                            else
                            {
                                //Ignorar y continuar con los demas objetos
                            }
                        }
                    }
                }


                if (!valorActual.Equals(""))
                {
                    //Evaluar si existe el estado encontrado con el conjunto guia
                    if (!existeEstadoAfd(guiaNuevoEstado))
                    {
                        estados++;
                        //Si no existe insertarlo en la cabecera
                        tablaAfd.Add(new nodoCabecera("S" + estados.ToString(), guiaNuevoEstado, false));
                        //Insertar transiciones
                        actualEstado.addTransicion("S" + estados.ToString(), valorActual, esConj);
                    }
                    else
                    {
                        //Insertar transiciones
                        actualEstado.addTransicion(getEstadoAfdGuia(guiaNuevoEstado).getIdEstado(), valorActual, esConj);
                    }
                    repetirFor++;
                    esConj = 0;
                }

                //Limpiar los valores
                valorActual     = "";
                guiaNuevoEstado = "";
            }

            return(estados);
        }