complement1Test works

fuck yea
This commit is contained in:
Ghost_Element 2024-01-08 23:20:54 +01:00
parent 59a7df7ad1
commit b1b97fff10
3 changed files with 50 additions and 52 deletions

View file

@ -8,6 +8,7 @@ import lombok.Getter;
import java.util.*;
public class NFAImpl implements NFA {
private Set<Character> completeAlphabet; //contains the full Alphabet possible (currently all small letters, can be changed...)
private Set<String> states;
private Set<Transition> transitions;
@ -26,6 +27,10 @@ public class NFAImpl implements NFA {
this.acceptingStates = new HashSet<>();
this.alphabet = new HashSet<>();
this.isFinalized = false;
this.completeAlphabet = new HashSet<>();
for(int i='a';i<='z';i++){
completeAlphabet.add((char)i);
}
}
@ -309,6 +314,7 @@ public class NFAImpl implements NFA {
nfa.addAllTransitions(this.transitions);
nfa.addAllAcceptingStates(this.acceptingStates);
nfaAddTrap(nfa);
NFAImpl fakeNFA = convertNFAtoDFA(nfa);
// state -> accepting
@ -496,4 +502,25 @@ public class NFAImpl implements NFA {
return str;
}
private void nfaAddTrap(NFAImpl input){
String trap = changeIfNecessary("TRAP", input.getStates());
input.states.add(trap);
Set<Transition> newTransitions = new HashSet<>();
for(String state : input.getStates()){
for(char letter : completeAlphabet){
boolean hasTransition = false;
for(Transition transition : input.getTransitions()){
if(transition.fromState().equals(state)&&transition.readSymbol().equals(letter)){
hasTransition = true;
break;
}
}
if(!hasTransition){
newTransitions.add(new Transition(state, letter, trap));
}
}
}
input.addAllTransitions(newTransitions); //input.transitions.addAll(newTransitions);
}
}