Implementado metodo para reconocer si la maquina reconoce la cadena (cinta)

This commit is contained in:
carlos 2017-06-28 16:53:44 +00:00
parent 75083921a0
commit 2a1975c2c3
2 changed files with 39 additions and 1 deletions

View File

@ -54,6 +54,9 @@ public class MT extends Application {
for(int i=0; i<machine.machine.estados.size();i++){ for(int i=0; i<machine.machine.estados.size();i++){
System.out.println(machine.machine.estados.get(i)); System.out.println(machine.machine.estados.get(i));
} }
if(machine.comprobarCadena(new StringBuilder("000111###"),5)){
System.out.println("Reconoce");
}else System.out.println("No reconoce");
} }
} }
}; };

View File

@ -10,7 +10,42 @@ import org.w3c.dom.Document;
public class Machine { public class Machine {
Automata machine; Automata machine;
public Machine(Document document) { public Machine(Document document) {
machine = new Automata(document); machine = new Automata(document);
} }
boolean comprobarCadena(StringBuilder cinta,int estadofinal) {
Estado qi = machine.estados.get(0);
int cabezal = 0;
do{
int i;
for(i=0;i<qi.link.size();i++){
if(qi.link.get(i).si == cinta.charAt(cabezal)){
cinta.setCharAt(cabezal,qi.link.get(i).sj);
switch (qi.link.get(i).movimiento){
case 'L':{
cabezal--;
if(cabezal == (-1)){
cinta.insert(0,"#");
cabezal++;
} }
break;
}
case 'R':{
cabezal++;
if(cabezal == cinta.length()) cinta.insert(cabezal,"#");
break;
}
default:{/*Se mantiene*/}
}
qi = qi.link.get(i).qj;
i = -1;
}
}
if(qi.q == estadofinal) return true;
return false;
}while(true);
}
}