complement1Test works
fuck yea
This commit is contained in:
parent
59a7df7ad1
commit
b1b97fff10
3 changed files with 50 additions and 52 deletions
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Reference in a new issue