concat GEHT

This commit is contained in:
Walcher 2024-01-08 23:18:52 +01:00
parent 271588221f
commit 3571f542ff
2 changed files with 94 additions and 30 deletions

76
.idea/workspace.xml generated
View file

@ -7,6 +7,7 @@
<list default="true" id="f5e08808-a5af-4c89-a1ee-21b3bcb9ae3e" name="Changes" comment="fucking hell"> <list default="true" id="f5e08808-a5af-4c89-a1ee-21b3bcb9ae3e" name="Changes" comment="fucking hell">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/ab1/impl/GRUPPE/NFAImpl.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/ab1/impl/GRUPPE/NFAImpl.java" afterDir="false" /> <change beforePath="$PROJECT_DIR$/src/main/java/ab1/impl/GRUPPE/NFAImpl.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/ab1/impl/GRUPPE/NFAImpl.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/test/java/ab1/tests/ComplexTests.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/test/java/ab1/tests/ComplexTests.java" afterDir="false" />
</list> </list>
<list id="39d4ccb3-eae9-4ed4-996a-5a13f44678fa" name="Changes by carol" comment="" /> <list id="39d4ccb3-eae9-4ed4-996a-5a13f44678fa" name="Changes by carol" comment="" />
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
@ -17,7 +18,7 @@
<component name="Git.Settings"> <component name="Git.Settings">
<option name="RECENT_BRANCH_BY_REPOSITORY"> <option name="RECENT_BRANCH_BY_REPOSITORY">
<map> <map>
<entry key="$PROJECT_DIR$" value="2-playing-around" /> <entry key="$PROJECT_DIR$" value="main" />
</map> </map>
</option> </option>
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" /> <option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
@ -49,27 +50,27 @@
<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">{ <component name="PropertiesComponent"><![CDATA[{
&quot;keyToString&quot;: { "keyToString": {
&quot;RunOnceActivity.OpenProjectViewOnStart&quot;: &quot;true&quot;, "RunOnceActivity.OpenProjectViewOnStart": "true",
&quot;RunOnceActivity.ShowReadmeOnStart&quot;: &quot;true&quot;, "RunOnceActivity.ShowReadmeOnStart": "true",
&quot;WebServerToolWindowFactoryState&quot;: &quot;false&quot;, "WebServerToolWindowFactoryState": "false",
&quot;full.screen.before.presentation.mode&quot;: &quot;false&quot;, "full.screen.before.presentation.mode": "false",
&quot;git-widget-placeholder&quot;: &quot;main&quot;, "git-widget-placeholder": "5-top-skill-issue-raphael",
&quot;ignore.virus.scanning.warn.message&quot;: &quot;true&quot;, "ignore.virus.scanning.warn.message": "true",
&quot;node.js.detected.package.eslint&quot;: &quot;true&quot;, "node.js.detected.package.eslint": "true",
&quot;node.js.detected.package.tslint&quot;: &quot;true&quot;, "node.js.detected.package.tslint": "true",
&quot;node.js.selected.package.eslint&quot;: &quot;(autodetect)&quot;, "node.js.selected.package.eslint": "(autodetect)",
&quot;node.js.selected.package.tslint&quot;: &quot;(autodetect)&quot;, "node.js.selected.package.tslint": "(autodetect)",
&quot;nodejs_package_manager_path&quot;: &quot;npm&quot;, "nodejs_package_manager_path": "npm",
&quot;project.structure.last.edited&quot;: &quot;Project&quot;, "project.structure.last.edited": "Project",
&quot;project.structure.proportion&quot;: &quot;0.0&quot;, "project.structure.proportion": "0.0",
&quot;project.structure.side.proportion&quot;: &quot;0.0&quot;, "project.structure.side.proportion": "0.0",
&quot;settings.editor.selected.configurable&quot;: &quot;preferences.pluginManager&quot;, "settings.editor.selected.configurable": "preferences.lookFeel",
&quot;vue.rearranger.settings.migration&quot;: &quot;true&quot; "vue.rearranger.settings.migration": "true"
} }
}</component> }]]></component>
<component name="RunManager" selected="JUnit.ComplexTests.complement1Test"> <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" />
<extension name="coverage"> <extension name="coverage">
@ -87,6 +88,23 @@
<option name="Make" enabled="true" /> <option name="Make" enabled="true" />
</method> </method>
</configuration> </configuration>
<configuration name="ComplexTests.plus1Test" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
<module name="ETI_Abgabe" />
<extension name="coverage">
<pattern>
<option name="PATTERN" value="ab1.tests.*" />
<option name="ENABLED" value="true" />
</pattern>
</extension>
<option name="PACKAGE_NAME" value="ab1.tests" />
<option name="MAIN_CLASS_NAME" value="ab1.tests.ComplexTests" />
<option name="METHOD_NAME" value="plus1Test" />
<option name="TEST_OBJECT" value="method" />
<dir value="$PROJECT_DIR$/src/test/java/ab1" />
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
<configuration name="ComplexTests.union1Test" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true"> <configuration name="ComplexTests.union1Test" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
<module name="ETI_Abgabe" /> <module name="ETI_Abgabe" />
<extension name="coverage"> <extension name="coverage">
@ -138,11 +156,11 @@
</configuration> </configuration>
<recent_temporary> <recent_temporary>
<list> <list>
<item itemvalue="JUnit.ComplexTests.complement1Test" />
<item itemvalue="JUnit.ab1 in ETI_Abgabe" /> <item itemvalue="JUnit.ab1 in ETI_Abgabe" />
<item itemvalue="JUnit.ComplexTests.plus1Test" />
<item itemvalue="JUnit.ComplexTests.complement1Test" />
<item itemvalue="JUnit.ComplexTests.union1Test" /> <item itemvalue="JUnit.ComplexTests.union1Test" />
<item itemvalue="JUnit.ab1.tests in ETI_Abgabe" /> <item itemvalue="JUnit.ab1.tests in ETI_Abgabe" />
<item itemvalue="JUnit.ab1.tests in ETI_Abgabe" />
</list> </list>
</recent_temporary> </recent_temporary>
</component> </component>
@ -164,7 +182,7 @@
<workItem from="1704700821945" duration="5461000" /> <workItem from="1704700821945" duration="5461000" />
<workItem from="1704712375384" duration="4940000" /> <workItem from="1704712375384" duration="4940000" />
<workItem from="1704717343016" duration="2934000" /> <workItem from="1704717343016" duration="2934000" />
<workItem from="1704750167689" duration="81000" /> <workItem from="1704750167689" duration="1793000" />
</task> </task>
<task id="LOCAL-00001" summary="changed a bit"> <task id="LOCAL-00001" summary="changed a bit">
<option name="closed" value="true" /> <option name="closed" value="true" />
@ -198,7 +216,15 @@
<option name="project" value="LOCAL" /> <option name="project" value="LOCAL" />
<updated>1704749811525</updated> <updated>1704749811525</updated>
</task> </task>
<option name="localTasksCounter" value="5" /> <task id="LOCAL-00005" summary="fucking hell">
<option name="closed" value="true" />
<created>1704750289780</created>
<option name="number" value="00005" />
<option name="presentableId" value="LOCAL-00005" />
<option name="project" value="LOCAL" />
<updated>1704750289780</updated>
</task>
<option name="localTasksCounter" value="6" />
<servers /> <servers />
</component> </component>
<component name="TypeScriptGeneratedFilesManager"> <component name="TypeScriptGeneratedFilesManager">

View file

@ -16,6 +16,8 @@ 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) {
@ -25,6 +27,10 @@ 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<>();
this.completeAlphabet = new HashSet<>();
for (char ch = 'a'; ch <= 'z'; ch++) {
this.completeAlphabet.add(ch);
}
this.isFinalized = false; this.isFinalized = false;
} }
@ -211,28 +217,55 @@ public class NFAImpl implements NFA {
return intersectionNFA; return intersectionNFA;
} }
// #TODO
@Override @Override
public NFA concatenation(NFA other) throws FinalizedStateException { public NFA concatenation(NFA other) throws FinalizedStateException {
if (!this.isFinalized || !other.isFinalized()) { if (!this.isFinalized || !other.isFinalized()) {
throw new FinalizedStateException(); throw new FinalizedStateException();
} }
NFAImpl concatenationNFA = new NFAImpl(this.initialState); NFAImpl concatenationNFA = new NFAImpl(this.initialState);
// Add states from 'this'
concatenationNFA.states.addAll(this.states); concatenationNFA.states.addAll(this.states);
concatenationNFA.states.addAll(other.getStates());
// Add states from 'other', with renaming if necessary
Map<String, String> renamedStates = new HashMap<>();
for (String state : other.getStates()) {
String newState = changeIfNecessary(state, concatenationNFA.states);
renamedStates.put(state, newState); // Old state name -> New state name
concatenationNFA.states.add(newState);
}
// Add transitions from 'this'
concatenationNFA.transitions.addAll(this.transitions); concatenationNFA.transitions.addAll(this.transitions);
concatenationNFA.transitions.addAll(other.getTransitions());
for (String accceptingState : this.acceptingStates) { // Add transitions from 'other', updating state names
Transition epsilon = new Transition(accceptingState, null, other.getInitialState()); for (Transition transition : other.getTransitions()) {
String newFromState = renamedStates.getOrDefault(transition.fromState(), transition.fromState());
String newToState = renamedStates.getOrDefault(transition.toState(), transition.toState());
Transition newTransition = new Transition(newFromState, transition.readSymbol(), newToState);
concatenationNFA.transitions.add(newTransition);
}
// Connect accepting states of 'this' to the initial state of 'other' with epsilon transitions
String newOtherInitialState = renamedStates.getOrDefault(other.getInitialState(), other.getInitialState());
for (String acceptingState : this.acceptingStates) {
Transition epsilon = new Transition(acceptingState, null, newOtherInitialState);
concatenationNFA.transitions.add(epsilon); concatenationNFA.transitions.add(epsilon);
} }
// Set accepting states of the concatenated NFA to be the accepting states of 'other'
concatenationNFA.acceptingStates.clear();
for (String acceptingState : other.getAcceptingStates()) {
concatenationNFA.acceptingStates.add(renamedStates.getOrDefault(acceptingState, acceptingState));
}
concatenationNFA.finalizeAutomaton();
return concatenationNFA; return concatenationNFA;
} }
@Override @Override
public NFA kleeneStar() throws FinalizedStateException { public NFA kleeneStar() throws FinalizedStateException {
if (!this.isFinalized) { if (!this.isFinalized) {
@ -256,6 +289,7 @@ public class NFAImpl implements NFA {
nfa.transitions.add(loopBackTransition); nfa.transitions.add(loopBackTransition);
} }
nfa.finalizeAutomaton();
return nfa; return nfa;
} }
@ -293,6 +327,8 @@ public class NFAImpl implements NFA {
} }
*/ */
nfa.finalizeAutomaton();
return nfa; return nfa;
} }
@ -388,6 +424,8 @@ public class NFAImpl implements NFA {
currentStates = epsilonClosure(currentStates, this); currentStates = epsilonClosure(currentStates, this);
} }
return isAcceptingState(currentStates, this); return isAcceptingState(currentStates, this);
} }