fucking hell
This commit is contained in:
parent
10c49f3b70
commit
347e78fc98
4 changed files with 258 additions and 87 deletions
5
.idea/misc.xml
generated
5
.idea/misc.xml
generated
|
|
@ -8,7 +8,10 @@
|
||||||
</list>
|
</list>
|
||||||
</option>
|
</option>
|
||||||
</component>
|
</component>
|
||||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_19" default="true" project-jdk-name="openjdk-19" project-jdk-type="JavaSDK">
|
<component name="PWA">
|
||||||
|
<option name="wasEnabledAtLeastOnce" value="true" />
|
||||||
|
</component>
|
||||||
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_21" default="true" project-jdk-name="openjdk-21" project-jdk-type="JavaSDK">
|
||||||
<output url="file://$PROJECT_DIR$/out" />
|
<output url="file://$PROJECT_DIR$/out" />
|
||||||
</component>
|
</component>
|
||||||
</project>
|
</project>
|
||||||
124
.idea/workspace.xml
generated
124
.idea/workspace.xml
generated
|
|
@ -4,14 +4,16 @@
|
||||||
<option name="autoReloadType" value="SELECTIVE" />
|
<option name="autoReloadType" value="SELECTIVE" />
|
||||||
</component>
|
</component>
|
||||||
<component name="ChangeListManager">
|
<component name="ChangeListManager">
|
||||||
<list default="true" id="f5e08808-a5af-4c89-a1ee-21b3bcb9ae3e" name="Changes" comment="">
|
<list default="true" id="f5e08808-a5af-4c89-a1ee-21b3bcb9ae3e" name="Changes" comment="changed a bit">
|
||||||
<change afterPath="$PROJECT_DIR$/.idea/theorethische-informatik-gruppe-10.iml" afterDir="false" />
|
|
||||||
<change beforePath="$PROJECT_DIR$/.idea/misc.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/misc.xml" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/.idea/misc.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/misc.xml" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/.idea/shelf/Uncommitted_changes_before_Update_at_08_01_2024_12_06__Changes_.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/shelf/Uncommitted_changes_before_Update_at_08_01_2024_12_06__Changes_.xml" afterDir="false" />
|
|
||||||
<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$/target/classes/ab1/impl/GRUPPE/NFAImpl.class" beforeDir="false" afterPath="$PROJECT_DIR$/target/classes/ab1/impl/GRUPPE/NFAImpl.class" afterDir="false" />
|
||||||
|
</list>
|
||||||
|
<list id="39d4ccb3-eae9-4ed4-996a-5a13f44678fa" name="Changes by carol" comment="" />
|
||||||
|
<list id="2bf04d9d-9125-4ed6-9018-847e14e9822c" name="Changes by danie" comment="">
|
||||||
|
<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" />
|
||||||
</list>
|
</list>
|
||||||
<list id="2bf04d9d-9125-4ed6-9018-847e14e9822c" name="Changes by danie" comment="" />
|
|
||||||
<option name="SHOW_DIALOG" value="false" />
|
<option name="SHOW_DIALOG" value="false" />
|
||||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||||
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
|
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
|
||||||
|
|
@ -20,7 +22,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="main" />
|
<entry key="$PROJECT_DIR$" value="2-playing-around" />
|
||||||
</map>
|
</map>
|
||||||
</option>
|
</option>
|
||||||
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
|
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
|
||||||
|
|
@ -38,9 +40,52 @@
|
||||||
<component name="GitLabMergeRequestsSettings">{
|
<component name="GitLabMergeRequestsSettings">{
|
||||||
"selectedUrlAndAccountId": {
|
"selectedUrlAndAccountId": {
|
||||||
"first": "https://git-ainf.aau.at/rawalcher/theorethische-informatik-gruppe-10.git",
|
"first": "https://git-ainf.aau.at/rawalcher/theorethische-informatik-gruppe-10.git",
|
||||||
"second": "e0c4ebfe-e254-4a34-93d3-a6ee2cb18f94"
|
"second": "2afc8825-f511-4d8a-8cc1-901875567c84"
|
||||||
}
|
}
|
||||||
}</component>
|
}</component>
|
||||||
|
<component name="LineStatusTrackerManager">
|
||||||
|
<file path="$PROJECT_DIR$/src/main/java/ab1/impl/GRUPPE/NFAImpl.java">
|
||||||
|
<ranges>
|
||||||
|
<range start1="16" end1="17" start2="16" end2="16" changelist="f5e08808-a5af-4c89-a1ee-21b3bcb9ae3e" />
|
||||||
|
<range start1="37" end1="37" start2="36" end2="42" changelist="f5e08808-a5af-4c89-a1ee-21b3bcb9ae3e" />
|
||||||
|
<range start1="52" end1="52" start2="57" end2="61" changelist="f5e08808-a5af-4c89-a1ee-21b3bcb9ae3e" />
|
||||||
|
<range start1="64" end1="65" start2="73" end2="76" changelist="f5e08808-a5af-4c89-a1ee-21b3bcb9ae3e" />
|
||||||
|
<range start1="69" end1="70" start2="80" end2="81" changelist="f5e08808-a5af-4c89-a1ee-21b3bcb9ae3e" />
|
||||||
|
<range start1="87" end1="88" start2="98" end2="99" changelist="f5e08808-a5af-4c89-a1ee-21b3bcb9ae3e" />
|
||||||
|
<range start1="95" end1="95" start2="106" end2="112" changelist="f5e08808-a5af-4c89-a1ee-21b3bcb9ae3e" />
|
||||||
|
<range start1="96" end1="97" start2="113" end2="114" changelist="f5e08808-a5af-4c89-a1ee-21b3bcb9ae3e" />
|
||||||
|
<range start1="104" end1="106" start2="121" end2="122" changelist="f5e08808-a5af-4c89-a1ee-21b3bcb9ae3e" />
|
||||||
|
<range start1="107" end1="109" start2="123" end2="124" changelist="f5e08808-a5af-4c89-a1ee-21b3bcb9ae3e" />
|
||||||
|
<range start1="110" end1="110" start2="125" end2="126" changelist="f5e08808-a5af-4c89-a1ee-21b3bcb9ae3e" />
|
||||||
|
<range start1="111" end1="111" start2="127" end2="129" changelist="f5e08808-a5af-4c89-a1ee-21b3bcb9ae3e" />
|
||||||
|
<range start1="112" end1="112" start2="130" end2="139" changelist="f5e08808-a5af-4c89-a1ee-21b3bcb9ae3e" />
|
||||||
|
<range start1="113" end1="117" start2="140" end2="147" changelist="f5e08808-a5af-4c89-a1ee-21b3bcb9ae3e" />
|
||||||
|
<range start1="118" end1="127" start2="148" end2="158" changelist="f5e08808-a5af-4c89-a1ee-21b3bcb9ae3e" />
|
||||||
|
<range start1="128" end1="130" start2="159" end2="161" changelist="f5e08808-a5af-4c89-a1ee-21b3bcb9ae3e" />
|
||||||
|
<range start1="131" end1="131" start2="162" end2="163" changelist="2bf04d9d-9125-4ed6-9018-847e14e9822c" />
|
||||||
|
<range start1="132" end1="133" start2="164" end2="170" changelist="f5e08808-a5af-4c89-a1ee-21b3bcb9ae3e" />
|
||||||
|
<range start1="135" end1="136" start2="172" end2="179" changelist="f5e08808-a5af-4c89-a1ee-21b3bcb9ae3e" />
|
||||||
|
<range start1="137" end1="139" start2="180" end2="184" changelist="f5e08808-a5af-4c89-a1ee-21b3bcb9ae3e" />
|
||||||
|
<range start1="140" end1="142" start2="185" end2="190" changelist="f5e08808-a5af-4c89-a1ee-21b3bcb9ae3e" />
|
||||||
|
<range start1="260" end1="262" start2="308" end2="310" changelist="f5e08808-a5af-4c89-a1ee-21b3bcb9ae3e" />
|
||||||
|
<range start1="263" end1="264" start2="311" end2="312" changelist="f5e08808-a5af-4c89-a1ee-21b3bcb9ae3e" />
|
||||||
|
<range start1="265" end1="265" start2="313" end2="315" changelist="f5e08808-a5af-4c89-a1ee-21b3bcb9ae3e" />
|
||||||
|
<range start1="266" end1="268" start2="316" end2="317" changelist="f5e08808-a5af-4c89-a1ee-21b3bcb9ae3e" />
|
||||||
|
<range start1="269" end1="269" start2="318" end2="322" changelist="f5e08808-a5af-4c89-a1ee-21b3bcb9ae3e" />
|
||||||
|
<range start1="270" end1="271" start2="323" end2="331" changelist="f5e08808-a5af-4c89-a1ee-21b3bcb9ae3e" />
|
||||||
|
<range start1="272" end1="273" start2="332" end2="348" changelist="f5e08808-a5af-4c89-a1ee-21b3bcb9ae3e" />
|
||||||
|
<range start1="301" end1="301" start2="376" end2="378" changelist="f5e08808-a5af-4c89-a1ee-21b3bcb9ae3e" />
|
||||||
|
<range start1="303" end1="317" start2="380" end2="387" changelist="f5e08808-a5af-4c89-a1ee-21b3bcb9ae3e" />
|
||||||
|
<range start1="319" end1="326" start2="389" end2="390" changelist="f5e08808-a5af-4c89-a1ee-21b3bcb9ae3e" />
|
||||||
|
<range start1="328" end1="329" start2="392" end2="393" changelist="f5e08808-a5af-4c89-a1ee-21b3bcb9ae3e" />
|
||||||
|
<range start1="344" end1="345" start2="408" end2="409" changelist="f5e08808-a5af-4c89-a1ee-21b3bcb9ae3e" />
|
||||||
|
<range start1="374" end1="376" start2="438" end2="440" changelist="f5e08808-a5af-4c89-a1ee-21b3bcb9ae3e" />
|
||||||
|
<range start1="380" end1="382" start2="444" end2="444" changelist="f5e08808-a5af-4c89-a1ee-21b3bcb9ae3e" />
|
||||||
|
<range start1="424" end1="425" start2="486" end2="487" changelist="f5e08808-a5af-4c89-a1ee-21b3bcb9ae3e" />
|
||||||
|
<range start1="428" end1="431" start2="490" end2="493" changelist="f5e08808-a5af-4c89-a1ee-21b3bcb9ae3e" />
|
||||||
|
</ranges>
|
||||||
|
</file>
|
||||||
|
</component>
|
||||||
<component name="MarkdownSettingsMigration">
|
<component name="MarkdownSettingsMigration">
|
||||||
<option name="stateVersion" value="1" />
|
<option name="stateVersion" value="1" />
|
||||||
</component>
|
</component>
|
||||||
|
|
@ -57,7 +102,8 @@
|
||||||
"RunOnceActivity.OpenProjectViewOnStart": "true",
|
"RunOnceActivity.OpenProjectViewOnStart": "true",
|
||||||
"RunOnceActivity.ShowReadmeOnStart": "true",
|
"RunOnceActivity.ShowReadmeOnStart": "true",
|
||||||
"WebServerToolWindowFactoryState": "false",
|
"WebServerToolWindowFactoryState": "false",
|
||||||
"git-widget-placeholder": "2-playing-around",
|
"full.screen.before.presentation.mode": "false",
|
||||||
|
"git-widget-placeholder": "main",
|
||||||
"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",
|
||||||
|
|
@ -71,7 +117,48 @@
|
||||||
"vue.rearranger.settings.migration": "true"
|
"vue.rearranger.settings.migration": "true"
|
||||||
}
|
}
|
||||||
}]]></component>
|
}]]></component>
|
||||||
<component name="RunManager">
|
<component name="RunManager" selected="JUnit.ComplexTests.complement1Test">
|
||||||
|
<configuration name="ComplexTests.complement1Test" 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="complement1Test" />
|
||||||
|
<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">
|
||||||
|
<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="union1Test" />
|
||||||
|
<option name="TEST_OBJECT" value="method" />
|
||||||
|
<method v="2">
|
||||||
|
<option name="Make" enabled="true" />
|
||||||
|
</method>
|
||||||
|
</configuration>
|
||||||
|
<configuration name="ab1 in ETI_Abgabe" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
|
||||||
|
<module name="ETI_Abgabe" />
|
||||||
|
<option name="TEST_OBJECT" value="directory" />
|
||||||
|
<dir value="$PROJECT_DIR$/src/test/java/ab1" />
|
||||||
|
<method v="2">
|
||||||
|
<option name="Make" enabled="true" />
|
||||||
|
</method>
|
||||||
|
</configuration>
|
||||||
<configuration name="ab1.tests in ETI_Abgabe" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
|
<configuration name="ab1.tests in ETI_Abgabe" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
|
||||||
<module name="ETI_Abgabe" />
|
<module name="ETI_Abgabe" />
|
||||||
<extension name="coverage">
|
<extension name="coverage">
|
||||||
|
|
@ -99,6 +186,10 @@
|
||||||
</configuration>
|
</configuration>
|
||||||
<recent_temporary>
|
<recent_temporary>
|
||||||
<list>
|
<list>
|
||||||
|
<item itemvalue="JUnit.ComplexTests.complement1Test" />
|
||||||
|
<item itemvalue="JUnit.ab1 in ETI_Abgabe" />
|
||||||
|
<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>
|
||||||
|
|
@ -147,9 +238,24 @@
|
||||||
<line-breakpoint enabled="true" type="java-line">
|
<line-breakpoint enabled="true" type="java-line">
|
||||||
<url>file://$PROJECT_DIR$/src/test/java/ab1/tests/ComplexTests.java</url>
|
<url>file://$PROJECT_DIR$/src/test/java/ab1/tests/ComplexTests.java</url>
|
||||||
<line>171</line>
|
<line>171</line>
|
||||||
<option name="timeStamp" value="1" />
|
<option name="timeStamp" value="10" />
|
||||||
|
</line-breakpoint>
|
||||||
|
<line-breakpoint enabled="true" type="java-line">
|
||||||
|
<url>file://$PROJECT_DIR$/src/test/java/ab1/tests/ComplexTests.java</url>
|
||||||
|
<line>15</line>
|
||||||
|
<option name="timeStamp" value="12" />
|
||||||
|
</line-breakpoint>
|
||||||
|
<line-breakpoint enabled="true" type="java-line">
|
||||||
|
<url>file://$PROJECT_DIR$/src/main/java/ab1/impl/GRUPPE/NFAImpl.java</url>
|
||||||
|
<line>347</line>
|
||||||
|
<option name="timeStamp" value="21" />
|
||||||
</line-breakpoint>
|
</line-breakpoint>
|
||||||
</breakpoints>
|
</breakpoints>
|
||||||
</breakpoint-manager>
|
</breakpoint-manager>
|
||||||
|
<watches-manager>
|
||||||
|
<configuration name="JUnit">
|
||||||
|
<watch expression="((HashSet)((NFAImpl)testInstance).acceptingStates).toArray()[2]" custom="java.util.HashSet,ab1.impl.GRUPPE.NFAImpl" />
|
||||||
|
</configuration>
|
||||||
|
</watches-manager>
|
||||||
</component>
|
</component>
|
||||||
</project>
|
</project>
|
||||||
|
|
@ -14,7 +14,6 @@ public class NFAImpl implements NFA {
|
||||||
private String initialState;
|
private String initialState;
|
||||||
private Set<String> acceptingStates;
|
private Set<String> acceptingStates;
|
||||||
|
|
||||||
@Getter
|
|
||||||
private Set<Character> alphabet;
|
private Set<Character> alphabet;
|
||||||
|
|
||||||
private boolean isFinalized;
|
private boolean isFinalized;
|
||||||
|
|
@ -35,6 +34,12 @@ public class NFAImpl implements NFA {
|
||||||
return this.states;
|
return this.states;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void safeAddStates(Set<String> states, Set<String> toCheck, NFAImpl nfa) {
|
||||||
|
for (String state : states) {
|
||||||
|
nfa.states.add(changeIfNecessary(state, toCheck));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Collection<Transition> getTransitions() {
|
public Collection<Transition> getTransitions() {
|
||||||
return this.transitions;
|
return this.transitions;
|
||||||
|
|
@ -50,6 +55,10 @@ public class NFAImpl implements NFA {
|
||||||
return this.initialState;
|
return this.initialState;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Set<Character> getAlphabet() {
|
||||||
|
return this.alphabet;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addTransition(Transition transition) throws FinalizedStateException {
|
public void addTransition(Transition transition) throws FinalizedStateException {
|
||||||
if (this.isFinalized) {
|
if (this.isFinalized) {
|
||||||
|
|
@ -62,12 +71,14 @@ public class NFAImpl implements NFA {
|
||||||
this.states.add(transition.toState());
|
this.states.add(transition.toState());
|
||||||
}
|
}
|
||||||
// add symbol to alphabet. If it is already in the alphabet, nothing happens
|
// add symbol to alphabet. If it is already in the alphabet, nothing happens
|
||||||
this.alphabet.add(transition.readSymbol());
|
if (transition.readSymbol() != null) {
|
||||||
|
this.alphabet.add(transition.readSymbol());
|
||||||
|
}
|
||||||
this.transitions.add(transition);
|
this.transitions.add(transition);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addAllTransitions(Set<Transition> transitions) throws FinalizedStateException {
|
public void addAllTransitions(Set<Transition> transitions) throws FinalizedStateException {
|
||||||
if(this.isFinalized){
|
if (this.isFinalized) {
|
||||||
throw new FinalizedStateException();
|
throw new FinalizedStateException();
|
||||||
}
|
}
|
||||||
for (Transition transition : transitions) {
|
for (Transition transition : transitions) {
|
||||||
|
|
@ -85,7 +96,7 @@ public class NFAImpl implements NFA {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addAllAcceptingStates(Set<String> states) throws FinalizedStateException {
|
public void addAllAcceptingStates(Set<String> states) throws FinalizedStateException {
|
||||||
if(this.isFinalized){
|
if (this.isFinalized) {
|
||||||
throw new FinalizedStateException();
|
throw new FinalizedStateException();
|
||||||
}
|
}
|
||||||
for (String state : states) {
|
for (String state : states) {
|
||||||
|
|
@ -93,8 +104,14 @@ public class NFAImpl implements NFA {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void safeAddAcceptingStates(Set<String> states, Set<String> toCheck, NFAImpl nfa) {
|
||||||
|
for (String state : states) {
|
||||||
|
nfa.addAcceptingState(changeIfNecessary(state, toCheck));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// #TODO
|
// #TODO
|
||||||
// handle case where the state is duplicated
|
// write more testcases
|
||||||
@Override
|
@Override
|
||||||
public NFA union(NFA other) throws FinalizedStateException {
|
public NFA union(NFA other) throws FinalizedStateException {
|
||||||
if (!this.isFinalized || !other.isFinalized()) {
|
if (!this.isFinalized || !other.isFinalized()) {
|
||||||
|
|
@ -102,44 +119,74 @@ public class NFAImpl implements NFA {
|
||||||
}
|
}
|
||||||
// new initialState with epsilon to initialState of this and other.
|
// new initialState with epsilon to initialState of this and other.
|
||||||
// Problem: what if states are called the same in this and other + what do we use as initialState?
|
// Problem: what if states are called the same in this and other + what do we use as initialState?
|
||||||
Set<String> unionStates = new HashSet<>();
|
NFAImpl unionNFA = new NFAImpl(this.getInitialState());
|
||||||
unionStates.addAll(this.states);
|
|
||||||
|
|
||||||
//do the union:
|
|
||||||
String start = changeIfNecessary(changeIfNecessary("START", unionStates), other.getStates());
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
for(String state : other.getStates()){
|
|
||||||
if(!unionStates.contains(state)){
|
|
||||||
unionStates.add(state);
|
|
||||||
}else{
|
|
||||||
// a state of other has the same name as one in this.
|
|
||||||
//change name of state and every Transitions it is a part of in other
|
|
||||||
String newstate = state;
|
|
||||||
while (unionStates.contains(newstate)){
|
|
||||||
//change the state slightly and save the different version
|
|
||||||
newstate = newstate+"|";
|
|
||||||
}
|
|
||||||
for(Transition transition : other.getTransitions()){
|
|
||||||
if(transition.fromState().equals(state)){
|
|
||||||
Transition changedTransition = new Transition(newstate, transition.readSymbol(), transition.toState());
|
|
||||||
}
|
|
||||||
if(transition.toState().equals(state)){
|
|
||||||
Transition changedTransition = new Transition(transition.fromState(), transition.readSymbol(), newstate);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
unionStates.add(newstate);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
NFAImpl unionNFA = new NFAImpl(this.initialState);
|
|
||||||
|
|
||||||
unionNFA.states.addAll(this.states);
|
unionNFA.states.addAll(this.states);
|
||||||
unionNFA.states.addAll(other.getStates());
|
|
||||||
|
|
||||||
unionNFA.transitions.addAll(this.transitions);
|
unionNFA.addAllAcceptingStates(this.acceptingStates);
|
||||||
unionNFA.transitions.addAll(other.getTransitions());
|
|
||||||
|
Set<String> otherAcceptingStates = new HashSet<>(other.getAcceptingStates());
|
||||||
|
unionNFA.safeAddAcceptingStates(this.acceptingStates, otherAcceptingStates, unionNFA);
|
||||||
|
|
||||||
|
|
||||||
|
Set<Transition> newTransitions = new HashSet<>();
|
||||||
|
for (Transition transition : other.getTransitions()) {
|
||||||
|
Transition newTransition =
|
||||||
|
new Transition(transition.fromState(), transition.readSymbol(), transition.toState());
|
||||||
|
newTransitions.add(newTransition);
|
||||||
|
}
|
||||||
|
String flag = "";
|
||||||
|
newTransitions.add(new Transition(flag, null, other.getInitialState()));
|
||||||
|
|
||||||
|
for (String state : other.getStates()) {
|
||||||
|
if (!unionNFA.states.contains(state)) {
|
||||||
|
unionNFA.states.add(state);
|
||||||
|
if (other.getAcceptingStates().contains(state)) {
|
||||||
|
unionNFA.acceptingStates.add(state);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// a state of other has the same name as one in this.
|
||||||
|
// change name of state and every Transition it is a part of in other
|
||||||
|
String newState = changeIfNecessary(state, unionNFA.states);
|
||||||
|
|
||||||
|
// wieder a neues set
|
||||||
|
Set<Transition> tempTransitions = new HashSet<>();
|
||||||
|
|
||||||
|
// check each transition of other if start or to state was state
|
||||||
|
for (Transition transition : newTransitions) {
|
||||||
|
if (transition.fromState().equals(state)) {
|
||||||
|
transition = new Transition(newState, transition.readSymbol(), transition.toState());
|
||||||
|
}
|
||||||
|
if (transition.toState().equals(state)) {
|
||||||
|
transition = new Transition(transition.fromState(), transition.readSymbol(), newState);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (String accState : other.getAcceptingStates()) {
|
||||||
|
if (accState.equals(state)) {
|
||||||
|
unionNFA.acceptingStates.add(newState);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
newTransitions = tempTransitions; // Replace the original set with the updated set
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// add, alphabet
|
||||||
|
|
||||||
|
Iterator<Transition> iterator = newTransitions.iterator();
|
||||||
|
while (iterator.hasNext()){
|
||||||
|
Transition transition = iterator.next();
|
||||||
|
if(transition.fromState().isEmpty()){
|
||||||
|
iterator.remove();
|
||||||
|
|
||||||
|
newTransitions.add(new Transition(unionNFA.initialState, transition.readSymbol(), transition.toState()));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
unionNFA.addAllTransitions(newTransitions);
|
||||||
|
|
||||||
|
unionNFA.addAllTransitions(this.transitions);
|
||||||
|
|
||||||
|
unionNFA.finalizeAutomaton();
|
||||||
|
|
||||||
|
|
||||||
return unionNFA;
|
return unionNFA;
|
||||||
|
|
@ -258,19 +305,47 @@ public class NFAImpl implements NFA {
|
||||||
// create a copy of this NFA
|
// create a copy of this NFA
|
||||||
NFAImpl nfa = new NFAImpl(this.initialState);
|
NFAImpl nfa = new NFAImpl(this.initialState);
|
||||||
nfa.states.addAll(this.states);
|
nfa.states.addAll(this.states);
|
||||||
nfa.transitions.addAll(this.transitions);
|
nfa.addAllTransitions(this.transitions);
|
||||||
nfa.acceptingStates.addAll(this.acceptingStates);
|
nfa.addAllAcceptingStates(this.acceptingStates);
|
||||||
|
|
||||||
//nfa = nfa.convertNFAtoDFA(nfa);
|
NFAImpl fakeNFA = convertNFAtoDFA(nfa);
|
||||||
|
|
||||||
|
// state -> accepting
|
||||||
|
// accepting -> state
|
||||||
|
|
||||||
/*
|
Set<String> newAcceptingstate = new HashSet<>();
|
||||||
for(String state : this.states){
|
|
||||||
|
|
||||||
|
for (String state : fakeNFA.getStates()) {
|
||||||
|
if (!fakeNFA.getAcceptingStates().contains(state)) {
|
||||||
|
newAcceptingstate.add(state);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
*/
|
fakeNFA.acceptingStates.clear();
|
||||||
|
fakeNFA.addAllAcceptingStates(newAcceptingstate);
|
||||||
|
|
||||||
return null;
|
Set<Character> originalAlphabet = new HashSet<>(fakeNFA.alphabet);
|
||||||
|
|
||||||
|
fakeNFA.alphabet.clear();
|
||||||
|
|
||||||
|
Set<Character> newAlphabet = new HashSet<>();
|
||||||
|
|
||||||
|
for (char ch = 'a'; ch <= 'z'; ch++) {
|
||||||
|
if (!originalAlphabet.contains(ch)) {
|
||||||
|
newAlphabet.add(ch);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Transition transition : fakeNFA.transitions) {
|
||||||
|
for (Character letter : newAlphabet) {
|
||||||
|
fakeNFA.addTransition(new Transition(transition.fromState(), letter, transition.toState()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fakeNFA.alphabet = newAlphabet;
|
||||||
|
|
||||||
|
fakeNFA.finalizeAutomaton();
|
||||||
|
|
||||||
|
return fakeNFA;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -299,34 +374,23 @@ public class NFAImpl implements NFA {
|
||||||
throw new FinalizedStateException();
|
throw new FinalizedStateException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char[] wordArray = word.toCharArray();
|
||||||
|
|
||||||
Set<String> currentStates = new HashSet<>();
|
Set<String> currentStates = new HashSet<>();
|
||||||
currentStates.add(this.initialState);
|
currentStates.add(this.initialState);
|
||||||
currentStates = epsilonClosure(currentStates, this);
|
currentStates = (epsilonClosure(currentStates, this));
|
||||||
|
|
||||||
|
for (char letter : wordArray) {
|
||||||
for (char letter : word.toCharArray()) {
|
// schritt a
|
||||||
Set<String> nextStates = new HashSet<>();
|
currentStates = getStateAfterTransition(currentStates, letter, this);
|
||||||
|
// schritt b
|
||||||
|
currentStates = epsilonClosure(currentStates, this);
|
||||||
for (String state : currentStates) {
|
|
||||||
nextStates.addAll(getStateAfterTransition(currentStates, letter, this));
|
|
||||||
}
|
|
||||||
|
|
||||||
nextStates = epsilonClosure(nextStates, this);
|
|
||||||
|
|
||||||
currentStates = nextStates;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (String state : currentStates) {
|
return isAcceptingState(currentStates, this);
|
||||||
if (this.acceptingStates.contains(state)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public NFA convertNFAtoDFA(NFAImpl input) {
|
public NFAImpl convertNFAtoDFA(NFAImpl input) {
|
||||||
|
|
||||||
// all accepting states of the DFA
|
// all accepting states of the DFA
|
||||||
Set<String> dfaAcceptingStates = new HashSet<>();
|
Set<String> dfaAcceptingStates = new HashSet<>();
|
||||||
|
|
@ -342,7 +406,7 @@ public class NFAImpl implements NFA {
|
||||||
// getting the epsilon closure of the start state
|
// getting the epsilon closure of the start state
|
||||||
startState = epsilonClosure(startState, input);
|
startState = epsilonClosure(startState, input);
|
||||||
dfaStates.add(startState);
|
dfaStates.add(startState);
|
||||||
if (isAcceptingState(startState, input)){
|
if (isAcceptingState(startState, input)) {
|
||||||
dfaAcceptingStates.add(getIndexOfSet(startState, dfaStates));
|
dfaAcceptingStates.add(getIndexOfSet(startState, dfaStates));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -372,15 +436,13 @@ public class NFAImpl implements NFA {
|
||||||
|
|
||||||
NFAImpl newDFA = new NFAImpl("0");
|
NFAImpl newDFA = new NFAImpl("0");
|
||||||
|
|
||||||
for(int i=1;i<dfaStates.size();i++){
|
for (int i = 0; i < dfaStates.size(); i++) {
|
||||||
newDFA.states.add(""+i);
|
newDFA.states.add("" + i);
|
||||||
}
|
}
|
||||||
|
|
||||||
newDFA.addAllTransitions(dfaTransitions);
|
newDFA.addAllTransitions(dfaTransitions);
|
||||||
newDFA.addAllAcceptingStates(dfaAcceptingStates);
|
newDFA.addAllAcceptingStates(dfaAcceptingStates);
|
||||||
|
|
||||||
newDFA.finalizeAutomaton();
|
|
||||||
|
|
||||||
return newDFA;
|
return newDFA;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -422,13 +484,13 @@ public class NFAImpl implements NFA {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getIndexOfSet(Set<String> set, List<Set<String>> dfaStates){
|
private String getIndexOfSet(Set<String> set, List<Set<String>> dfaStates) {
|
||||||
return Integer.toString(dfaStates.indexOf(set));
|
return Integer.toString(dfaStates.indexOf(set));
|
||||||
}
|
}
|
||||||
|
|
||||||
private String changeIfNecessary(String str, Set<String> toCheck){
|
private String changeIfNecessary(String str, Set<String> toCheck) {
|
||||||
while(toCheck.contains(str)){
|
while (toCheck.contains(str)) {
|
||||||
str = str+"|";
|
str = str + "1";
|
||||||
}
|
}
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Binary file not shown.
Reference in a new issue