concat GEHT
This commit is contained in:
parent
271588221f
commit
3571f542ff
2 changed files with 94 additions and 30 deletions
76
.idea/workspace.xml
generated
76
.idea/workspace.xml
generated
|
|
@ -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[{
|
||||||
"keyToString": {
|
"keyToString": {
|
||||||
"RunOnceActivity.OpenProjectViewOnStart": "true",
|
"RunOnceActivity.OpenProjectViewOnStart": "true",
|
||||||
"RunOnceActivity.ShowReadmeOnStart": "true",
|
"RunOnceActivity.ShowReadmeOnStart": "true",
|
||||||
"WebServerToolWindowFactoryState": "false",
|
"WebServerToolWindowFactoryState": "false",
|
||||||
"full.screen.before.presentation.mode": "false",
|
"full.screen.before.presentation.mode": "false",
|
||||||
"git-widget-placeholder": "main",
|
"git-widget-placeholder": "5-top-skill-issue-raphael",
|
||||||
"ignore.virus.scanning.warn.message": "true",
|
"ignore.virus.scanning.warn.message": "true",
|
||||||
"node.js.detected.package.eslint": "true",
|
"node.js.detected.package.eslint": "true",
|
||||||
"node.js.detected.package.tslint": "true",
|
"node.js.detected.package.tslint": "true",
|
||||||
"node.js.selected.package.eslint": "(autodetect)",
|
"node.js.selected.package.eslint": "(autodetect)",
|
||||||
"node.js.selected.package.tslint": "(autodetect)",
|
"node.js.selected.package.tslint": "(autodetect)",
|
||||||
"nodejs_package_manager_path": "npm",
|
"nodejs_package_manager_path": "npm",
|
||||||
"project.structure.last.edited": "Project",
|
"project.structure.last.edited": "Project",
|
||||||
"project.structure.proportion": "0.0",
|
"project.structure.proportion": "0.0",
|
||||||
"project.structure.side.proportion": "0.0",
|
"project.structure.side.proportion": "0.0",
|
||||||
"settings.editor.selected.configurable": "preferences.pluginManager",
|
"settings.editor.selected.configurable": "preferences.lookFeel",
|
||||||
"vue.rearranger.settings.migration": "true"
|
"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">
|
||||||
|
|
|
||||||
|
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Reference in a new issue