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

View file

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