complement works now

This commit is contained in:
Walcher 2024-01-08 23:39:57 +01:00
parent 6c47b25ed2
commit 0d47de5c44
3 changed files with 46 additions and 22 deletions

38
.idea/workspace.xml generated
View file

@ -46,26 +46,26 @@
<option name="hideEmptyMiddlePackages" value="true" /> <option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" /> <option name="showLibraryContents" value="true" />
</component> </component>
<component name="PropertiesComponent"><![CDATA[{ <component name="PropertiesComponent">{
"keyToString": { &quot;keyToString&quot;: {
"RunOnceActivity.OpenProjectViewOnStart": "true", &quot;RunOnceActivity.OpenProjectViewOnStart&quot;: &quot;true&quot;,
"RunOnceActivity.ShowReadmeOnStart": "true", &quot;RunOnceActivity.ShowReadmeOnStart&quot;: &quot;true&quot;,
"WebServerToolWindowFactoryState": "false", &quot;WebServerToolWindowFactoryState&quot;: &quot;false&quot;,
"full.screen.before.presentation.mode": "false", &quot;full.screen.before.presentation.mode&quot;: &quot;false&quot;,
"git-widget-placeholder": "5-top-skill-issue-raphael", &quot;git-widget-placeholder&quot;: &quot;5-top-skill-issue-raphael&quot;,
"ignore.virus.scanning.warn.message": "true", &quot;ignore.virus.scanning.warn.message&quot;: &quot;true&quot;,
"node.js.detected.package.eslint": "true", &quot;node.js.detected.package.eslint&quot;: &quot;true&quot;,
"node.js.detected.package.tslint": "true", &quot;node.js.detected.package.tslint&quot;: &quot;true&quot;,
"node.js.selected.package.eslint": "(autodetect)", &quot;node.js.selected.package.eslint&quot;: &quot;(autodetect)&quot;,
"node.js.selected.package.tslint": "(autodetect)", &quot;node.js.selected.package.tslint&quot;: &quot;(autodetect)&quot;,
"nodejs_package_manager_path": "npm", &quot;nodejs_package_manager_path&quot;: &quot;npm&quot;,
"project.structure.last.edited": "Project", &quot;project.structure.last.edited&quot;: &quot;Project&quot;,
"project.structure.proportion": "0.0", &quot;project.structure.proportion&quot;: &quot;0.0&quot;,
"project.structure.side.proportion": "0.0", &quot;project.structure.side.proportion&quot;: &quot;0.0&quot;,
"settings.editor.selected.configurable": "preferences.lookFeel", &quot;settings.editor.selected.configurable&quot;: &quot;preferences.lookFeel&quot;,
"vue.rearranger.settings.migration": "true" &quot;vue.rearranger.settings.migration&quot;: &quot;true&quot;
} }
}]]></component> }</component>
<component name="RunManager" selected="JUnit.ab1 in ETI_Abgabe"> <component name="RunManager" selected="JUnit.ab1 in ETI_Abgabe">
<configuration name="ComplexTests.complement1Test" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true"> <configuration name="ComplexTests.complement1Test" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
<module name="ETI_Abgabe" /> <module name="ETI_Abgabe" />

View file

@ -15,6 +15,7 @@ public class NFAImpl implements NFA {
private Set<Character> alphabet; private Set<Character> alphabet;
private Set<Character> completeAlphabet;
private boolean isFinalized; private boolean isFinalized;
public NFAImpl(String startState) { public NFAImpl(String startState) {
@ -24,9 +25,9 @@ public class NFAImpl implements NFA {
this.transitions = new HashSet<>(); this.transitions = new HashSet<>();
this.acceptingStates = new HashSet<>(); this.acceptingStates = new HashSet<>();
this.alphabet = new HashSet<>(); this.alphabet = new HashSet<>();
Set<Character> completeAlphabet = new HashSet<>(); this.completeAlphabet = new HashSet<>();
for (char ch = 'a'; ch <= 'z'; ch++) { for(int i='a';i<='z';i++){
completeAlphabet.add(ch); completeAlphabet.add((char)i);
} }
this.isFinalized = false; this.isFinalized = false;
@ -344,6 +345,8 @@ public class NFAImpl implements NFA {
nfa.addAllTransitions(this.transitions); nfa.addAllTransitions(this.transitions);
nfa.addAllAcceptingStates(this.acceptingStates); nfa.addAllAcceptingStates(this.acceptingStates);
nfaAddTrap(nfa);
NFAImpl fakeNFA = convertNFAtoDFA(nfa); NFAImpl fakeNFA = convertNFAtoDFA(nfa);
// state -> accepting // state -> accepting
@ -533,4 +536,25 @@ public class NFAImpl implements NFA {
return str; 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);
}
} }