Professional Documents
Culture Documents
Modelo;
import java.util.*;
public Automata()
{
super();
Alfabeto = new TreeSet<String>();
estadoFinal = new TreeSet<Integer>();
EstadoActual = EstadoInicial;
String[] letras = palabra.split("");
for(String l:letras)
{
if(!l.equals(""))
{
EstadoActual = funcion(EstadoActual,l);
if(EstadoActual==-1)
return false;
}
}
if(estadoFinal.contains(EstadoActual))
return true;
return false;
}
private int funcion(int estadoActual, String e)
{
Vector<String> a = new Vector<String>();
a.addAll(Alfabeto);
if(TablaTransiciones[estadoActual][a.indexOf(e)].isEmpty())
{
return -1;
}
else
{
return TablaTransiciones[estadoActual]
[a.indexOf(e)].first();
}
@Override
public String toString() {
String cadena="";
}
cadena+="\n";
return cadena;
}
}
package Lenguaje.Formal.AFND2AFD.Logica;
import Lenguaje.Formal.AFND2AFD.Modelo.Automata;
import java.util.Stack;
import java.util.TreeSet;
import java.util.Vector;
import javax.swing.JOptionPane;
nombre = automata.getNombre();
numestados = automata.getnumEstados();
alfabeto = automata.getAlfabeto();
estadoInicial = automata.getEstadoInicial();
estadoFinal = automata.getestadoFinal();
tabtrans = automata.getTablaTransiciones();
if(alfabeto.contains("E"))
{
JOptionPane.showMessageDialog(null,"Quitando tranciciones
vacias");
quitarTansicionesVacias();
JOptionPane.showMessageDialog(null,"tranciciones vacias
quitadas");
}
else
{
JOptionPane.showMessageDialog(null,"no tiene tranciciones
vacias");
}
if(noEsDeterminista())
{
JOptionPane.showMessageDialog(null,"Quitando indeterminismo");
quitarIndeterminismo();
JOptionPane.showMessageDialog(null,"Indeterminismo quitado");
}
else
{
JOptionPane.showMessageDialog(null,"Ya es determinista");
while(!verificarMinimo())
minimizar();
JOptionPane.showMessageDialog(null,"Es minimo");
for(String s:alfabeto)
{
for(int cont = 0;cont<numestados;cont++)
{
ts = obtenerTransicion(cont, s);
if(ts.size()!=0 && !nuevosEstados.contains(ts))
{
nuevosEstados.add(ts);
}
}
}
Vector<TreeSet> temporal = (Vector<TreeSet>)
nuevosEstados.clone();
for(TreeSet<Integer> t: temporal)
{
ts2 = new TreeSet<Integer>();
for(String s: alfabeto)
{
for(Integer i: t)
{
ts2.addAll(obtenerTransicion(i, s));
}
if(ts2.size()!=0 && !nuevosEstados.contains(ts2))
{
nuevosEstados.add(ts2);
}
}
}
TreeSet<Integer> tranO,tran;
for(String s: alfabeto)
{
for(TreeSet<Integer> t: nuevosEstados)
{
tranO = new TreeSet<Integer>();
tran = new TreeSet<Integer>();
for(Integer i: t)
{
tranO.addAll(obtenerTransicion(i, s));
}
///-nuevo
if(nuevosEstados.indexOf(tranO)!=-1)
tran.add(nuevosEstados.indexOf(tranO));
for(TreeSet<Integer> t: nuevosEstados)
{
for(Integer i: estadoFinal)
{
if(t.contains(i))
{
finales.add(nuevosEstados.indexOf(t));
}
}
}
numestados = nuevosEstados.size();
estadoFinal = finales;
tabtrans = tablaaux;
System.out.println(tablaaux);
}
TreeSet<String> alfabetoTemp =
(TreeSet<String>)alfabeto.clone();
alfabetoTemp.remove("E");
TreeSet<Integer>[][] tablatransicionesTemp = new
TreeSet[numestados][alfabetoTemp.size()];
for(int a=0;a<alfabetoTemp.size();a++)
{
for(int q=0;q<numestados;q++)
{
tablatransicionesTemp[q][a] = new
TreeSet<Integer>();
}
for(String s: alfabeto)
{
if(!s.equals("E"))
{
for(int cont=0;cont<numestados;cont++)
{
//System.out.print(cont + " "+s+" -");
clau2.addAll(cerrarVacias(i.intValue()));
Vector<String> a = new
Vector<String>();
a.addAll(alfabetoTemp);
tablatransicionesTemp[cont]
[a.indexOf(s)].addAll(clau2);
}
}
}
}
TreeSet<Integer> f = cerrarVacias(estadoInicial);
boolean cq0F=false;
for(Integer i: estadoFinal)
{
if(f.contains(i))
{
cq0F = true;
}
}
if(cq0F)
{
estadoFinal.add(estadoInicial);
}
alfabeto = alfabetoTemp;
tabtrans = tablatransicionesTemp;
System.out.println();
}
pila.push(obtenerTransicion(q, "E"));
cierre.add(q);
while(!pila.isEmpty())
{
ts = pila.pop();
for(Integer i: ts)
{
if(!cierre.contains(i.intValue()))
{
pila.push(obtenerTransicion(i.intValue(),
"E"));
}
}
cierre.addAll(ts);
}
return cierre;
}
{
boolean f = true;
}
tamanio =0;
for(String s:alfabeto)
{
r = obtenerTransicion(cont, s);
t = obtenerTransicion(cont2, s);
if(x<y)
{
if(estados[y][x]==1)
{
estados[cont][cont2] = 1;
}
}
else
{
if(estados[x][y]==1)
{
estados[cont][cont2] = 1;
}
}
if(y!=x)
{
estados[cont][cont2] = 1;
}
}
}
if(tamanio!=alfabeto.size())
{
estados[cont][cont2] = 1;
}
}
}
for(int cont=1;cont<numestados;cont++)
{
for(int cont2=0;cont2<cont;cont2++)
{
if(estados[cont][cont2]==0)
f = false;
}
}
return f;
}
tamanio =0;
for(String s:alfabeto)
{
r = obtenerTransicion(cont, s);
t = obtenerTransicion(cont2, s);
if(y<x)
{
if(estados[x][y]==1)
{
estados[cont][cont2] = 1;
}
}
else
{
if(estados[y][x]==1)
{
estados[cont][cont2] = 1;
}
}
if(x!=y)
{
estados[cont][cont2] = 1;
}
}
}
if(tamanio!=alfabeto.size())
{
estados[cont][cont2] = 1;
}
}
}
Vector<TreeSet> vector = new Vector<TreeSet>();
TreeSet<Integer> ts;
boolean f;
for(int cont=1;cont<numestados;cont++)
{
for(int cont2=0;cont2<cont;cont2++)
{
if(estados[cont][cont2] == 0)
{
ts = new TreeSet<Integer>();
f = true;
ts.add(cont);
ts.add(cont2);
f= true;
TreeSet<Integer> tran;
int t0;
TreeSet<Integer> t1;
for(String s: alfabeto)
{
for(TreeSet<Integer> tsi:vector)
{
tran = new TreeSet<Integer>();
for(Integer i:tsi)
{
tran.addAll(obtenerTransicion(i, s));
}
t0 = vector.indexOf(tsi);
t1 = new TreeSet<Integer>();
for(TreeSet<Integer> tsi2:vector)
{
if(tran.size()>0&&tsi2.containsAll(tran))
{
t1.add(vector.indexOf(tsi2));
}
}
}
}
for(TreeSet<Integer> i: vector)
{
if(i.contains(estadoInicial))
{
q00 = vector.indexOf(i);
}
for(Integer ii:estadoFinal)
{
if(i.contains(ii))
{
finales.add(vector.indexOf(i));
}
}
}
estadoInicial=q00;
numestados = vector.size();
estadoFinal = finales;
tabtrans = tablaTemp;
System.out.println();
}
}
package Lenguaje.Formal.AFND2AFD.Ventanas;
import Lenguaje.Formal.AFND2AFD.Logica.Transformador;
import Lenguaje.Formal.AFND2AFD.Modelo.Automata;
import Lenguje.Formal.AFND2AFD.Util.PanelFondo;
import com.mycsistemas.swingec.button.RoundtButton;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.SpringLayout;
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author Maricela Maldonado
*/
public class Ventanita extends JFrame implements ActionListener{
private RoundtButton ingresar= new RoundtButton();
private RoundtButton ingresaLetrar= new RoundtButton();
private RoundtButton ingresaNEstados= new RoundtButton();
private RoundtButton ingresaEstadoI= new RoundtButton();
private RoundtButton ingresaEstadoF= new RoundtButton();
private RoundtButton ingresaTabla= new RoundtButton();
private RoundtButton limpiar= new RoundtButton();
public Ventanita() {
initComponents();
setTitle("Convertidor");
Dimension screenSize =
Toolkit.getDefaultToolkit().getScreenSize();
setBounds((screenSize.width-535)/2, (screenSize.height-420)/2,
535, 420);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setVisible(true);
}
public void initComponents(){
// back.setImageIcon(new
ImageIcon(getClass().getResource("//Lenguaje//Formal//AFND2AFD//Imagenes/
/23.jpg")));
area.setEditable(false);
back.setLayout(sp);
sp.putConstraint(SpringLayout.NORTH, ingresaNEstados, 0,
SpringLayout.NORTH, eti3);
sp.putConstraint(SpringLayout.EAST, ingresaNEstados, -15,
SpringLayout.EAST, back);
sp.putConstraint(SpringLayout.NORTH, txtEstadosN, 0,
SpringLayout.NORTH, eti3);
sp.putConstraint(SpringLayout.WEST, txtEstadosN, 15,
SpringLayout.EAST, eti3);
sp.putConstraint(SpringLayout.EAST, txtEstadosN, -15,
SpringLayout.WEST, ingresaNEstados);
sp.putConstraint(SpringLayout.NORTH, ingresaLetrar, 0,
SpringLayout.NORTH, eti);
sp.putConstraint(SpringLayout.EAST, ingresaLetrar, -15,
SpringLayout.EAST, back);
sp.putConstraint(SpringLayout.NORTH, txtIngreso, 0,
SpringLayout.NORTH, eti);
sp.putConstraint(SpringLayout.WEST, txtIngreso, 15,
SpringLayout.EAST, eti);
sp.putConstraint(SpringLayout.EAST, txtIngreso, -15,
SpringLayout.WEST, ingresaLetrar);
sp.putConstraint(SpringLayout.NORTH, ingresaEstadoI, 0,
SpringLayout.NORTH, eti4);
sp.putConstraint(SpringLayout.EAST, ingresaEstadoI, -15,
SpringLayout.EAST, back);
sp.putConstraint(SpringLayout.NORTH, txtEstadosI, 0,
SpringLayout.NORTH, eti4);
sp.putConstraint(SpringLayout.WEST, txtEstadosI, 15,
SpringLayout.EAST, eti4);
sp.putConstraint(SpringLayout.EAST, txtEstadosI, -15,
SpringLayout.WEST, ingresaEstadoI);
sp.putConstraint(SpringLayout.NORTH, ingresaEstadoF, 0,
SpringLayout.NORTH, eti5);
sp.putConstraint(SpringLayout.EAST, ingresaEstadoF, -15,
SpringLayout.EAST, back);
sp.putConstraint(SpringLayout.NORTH, txtEstadosF, 0,
SpringLayout.NORTH, eti5);
sp.putConstraint(SpringLayout.WEST, txtEstadosF, 15,
SpringLayout.EAST, eti5);
sp.putConstraint(SpringLayout.EAST, txtEstadosF, -15,
SpringLayout.WEST, ingresaEstadoF);
sp.putConstraint(SpringLayout.NORTH, ingresaTabla, 0,
SpringLayout.NORTH, eti6);
sp.putConstraint(SpringLayout.EAST, ingresaTabla, -15,
SpringLayout.EAST, back);
sp.putConstraint(SpringLayout.NORTH, txtTabla, 0,
SpringLayout.NORTH, ingresaTabla);
sp.putConstraint(SpringLayout.WEST, txtTabla, -30,
SpringLayout.EAST, txtTabla);
sp.putConstraint(SpringLayout.EAST, txtTabla, -15,
SpringLayout.WEST, ingresaTabla);
sp.putConstraint(SpringLayout.NORTH, txtTabla2, 0,
SpringLayout.NORTH, txtTabla);
sp.putConstraint(SpringLayout.WEST, txtTabla2, -30,
SpringLayout.EAST, txtTabla2);
sp.putConstraint(SpringLayout.EAST, txtTabla2, -15,
SpringLayout.WEST, txtTabla);
sp.putConstraint(SpringLayout.NORTH, txtTabla3, 0,
SpringLayout.NORTH, txtTabla2);
sp.putConstraint(SpringLayout.WEST, txtTabla3, -30,
SpringLayout.EAST, txtTabla3);
sp.putConstraint(SpringLayout.EAST, txtTabla3, -15,
SpringLayout.WEST, txtTabla2);
ingresar.setText("Ejecutar Conversion");
ingresaLetrar.setText("Ingresar");
ingresaNEstados.setText("Ingresar");
ingresaEstadoI.setText("Ingresar");
ingresaEstadoF.setText("Ingresar");
ingresaTabla.setText("Ingresar");
limpiar.setText("Limpiar Campos");
ingresar.addActionListener(this);
ingresaLetrar.addActionListener(this);
ingresaNEstados.addActionListener(this);
ingresaEstadoI.addActionListener(this);
ingresaEstadoF.addActionListener(this);
ingresaTabla.addActionListener(this);
limpiar.addActionListener(this);
back.add(eti);
back.add(txtIngreso);
back.add(ingresaLetrar);
back.add(eti3);
back.add(txtEstadosN);
back.add(ingresaNEstados);
back.add(eti4);
back.add(txtEstadosI);
back.add(ingresaEstadoI);
back.add(eti5);
back.add(txtEstadosF);
back.add(ingresaEstadoF);
back.add(eti6);
back.add(txtTabla);
back.add(txtTabla2);
back.add(txtTabla3);
back.add(eti7);
back.add(eti8);
back.add(eti9);
back.add(ingresaTabla);
back.add(eti2);
back.add(ingresar);
back.add(limpiar);
back.add(scroll);
getContentPane().add(back);
}else if(e.getSource().equals(limpiar)){
txtIngreso.setText("");
area.setText("");
}else if(e.getSource().equals(ingresaNEstados)){
try {
int numeros = Integer.parseInt(txtEstadosN.getText());
area.append("Numero de estados: "+numeros+"\n");
auto.setnumEstados(numeros);
txtEstadosN.setEditable(false);
} catch (NumberFormatException numberFormatException) {
JOptionPane.showMessageDialog(this, "Ingrese un numero
valido","Error",JOptionPane.ERROR_MESSAGE);
}
}else if(e.getSource().equals(ingresaEstadoI)){
try {
int numeros =
Integer.parseInt(txtEstadosI.getText());
area.append("\nEstado Inicial : "+numeros);
auto.setEstadoInicial(numeros);
txtEstadosI.setEditable(false);
} catch (NumberFormatException numberFormatException) {
JOptionPane.showMessageDialog(this, "Ingrese un numero
valido","Error",JOptionPane.ERROR_MESSAGE);
}
}else if(e.getSource().equals(ingresaEstadoF)){
try {
int numeros = Integer.parseInt(txtEstadosF.getText());
area.append("\nEstado Final: "+numeros);
auto.addEstadoFinal(numeros);
txtEstadosF.setText("");
} catch (NumberFormatException numberFormatException) {
JOptionPane.showMessageDialog(this, "Ingrese un numero
valido","Error",JOptionPane.ERROR_MESSAGE);
}
}
else if(e.getSource().equals(ingresaTabla)){
try {
int numeros = Integer.parseInt(txtTabla3.getText());
int numeros2 = Integer.parseInt(txtTabla.getText());
auto.addTransicion(numeros, txtTabla2.getText(),
numeros2);
area.append("\nTransisicion:
"+numeros+"\t\t"+txtTabla2.getText()+"\t"+numeros2);
txtTabla.setText("");
txtTabla2.setText("");
txtTabla3.setText("");
} catch (NumberFormatException numberFormatException) {
JOptionPane.showMessageDialog(this, "Ingrese un numero
valido","Error",JOptionPane.ERROR_MESSAGE);
}
}else if(e.getSource().equals(ingresar)){
Transformador trans=new Transformador();
area.append("\nAutomata Finito no Determinista\n"+auto);
area.append("\nAutomata Finito
Determinista\n"+trans.minimizar(auto));
}
}