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">
<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/test/java/ab1/tests/ComplexTests.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/test/java/ab1/tests/ComplexTests.java" afterDir="false" />
</list>
<list id="39d4ccb3-eae9-4ed4-996a-5a13f44678fa" name="Changes by carol" comment="" />
<option name="SHOW_DIALOG" value="false" />
@ -17,7 +18,7 @@
<component name="Git.Settings">
<option name="RECENT_BRANCH_BY_REPOSITORY">
<map>
<entry key="$PROJECT_DIR$" value="2-playing-around" />
<entry key="$PROJECT_DIR$" value="main" />
</map>
</option>
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
@ -49,27 +50,27 @@
<option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" />
</component>
<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;main&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.pluginManager&quot;,
&quot;vue.rearranger.settings.migration&quot;: &quot;true&quot;
<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>
<component name="RunManager" selected="JUnit.ComplexTests.complement1Test">
}]]></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" />
<extension name="coverage">
@ -87,6 +88,23 @@
<option name="Make" enabled="true" />
</method>
</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">
<module name="ETI_Abgabe" />
<extension name="coverage">
@ -138,11 +156,11 @@
</configuration>
<recent_temporary>
<list>
<item itemvalue="JUnit.ComplexTests.complement1Test" />
<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.ab1.tests in ETI_Abgabe" />
<item itemvalue="JUnit.ab1.tests in ETI_Abgabe" />
</list>
</recent_temporary>
</component>
@ -164,7 +182,7 @@
<workItem from="1704700821945" duration="5461000" />
<workItem from="1704712375384" duration="4940000" />
<workItem from="1704717343016" duration="2934000" />
<workItem from="1704750167689" duration="81000" />
<workItem from="1704750167689" duration="1793000" />
</task>
<task id="LOCAL-00001" summary="changed a bit">
<option name="closed" value="true" />
@ -198,7 +216,15 @@
<option name="project" value="LOCAL" />
<updated>1704749811525</updated>
</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 />
</component>
<component name="TypeScriptGeneratedFilesManager">

View file

@ -16,6 +16,8 @@ public class NFAImpl implements NFA {
private Set<Character> alphabet;
private Set<Character> completeAlphabet;
private boolean isFinalized;
public NFAImpl(String startState) {
@ -25,6 +27,10 @@ public class NFAImpl implements NFA {
this.transitions = new HashSet<>();
this.acceptingStates = new HashSet<>();
this.alphabet = new HashSet<>();
this.completeAlphabet = new HashSet<>();
for (char ch = 'a'; ch <= 'z'; ch++) {
this.completeAlphabet.add(ch);
}
this.isFinalized = false;
}
@ -211,28 +217,55 @@ public class NFAImpl implements NFA {
return intersectionNFA;
}
// #TODO
@Override
public NFA concatenation(NFA other) throws FinalizedStateException {
if (!this.isFinalized || !other.isFinalized()) {
throw new FinalizedStateException();
}
NFAImpl concatenationNFA = new NFAImpl(this.initialState);
// Add states from 'this'
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(other.getTransitions());
for (String accceptingState : this.acceptingStates) {
Transition epsilon = new Transition(accceptingState, null, other.getInitialState());
// Add transitions from 'other', updating state names
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);
}
// 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;
}
@Override
public NFA kleeneStar() throws FinalizedStateException {
if (!this.isFinalized) {
@ -256,6 +289,7 @@ public class NFAImpl implements NFA {
nfa.transitions.add(loopBackTransition);
}
nfa.finalizeAutomaton();
return nfa;
}
@ -293,6 +327,8 @@ public class NFAImpl implements NFA {
}
*/
nfa.finalizeAutomaton();
return nfa;
}
@ -388,6 +424,8 @@ public class NFAImpl implements NFA {
currentStates = epsilonClosure(currentStates, this);
}
return isAcceptingState(currentStates, this);
}