Merge branch 'main' into '2-playing-around'

# Conflicts:
#   .idea/workspace.xml
This commit is contained in:
rawalcher 2024-01-08 17:34:39 +00:00
commit b37348b9c3
4 changed files with 64 additions and 2 deletions

2
.idea/misc.xml generated
View file

@ -8,7 +8,7 @@
</list> </list>
</option> </option>
</component> </component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_21" default="true" project-jdk-name="openjdk-21" project-jdk-type="JavaSDK"> <component name="ProjectRootManager" version="2" languageLevel="JDK_19" default="true" project-jdk-name="openjdk-19" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" /> <output url="file://$PROJECT_DIR$/out" />
</component> </component>
</project> </project>

View file

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

15
.idea/workspace.xml generated
View file

@ -4,7 +4,13 @@
<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="changed a bit" /> <list default="true" id="f5e08808-a5af-4c89-a1ee-21b3bcb9ae3e" name="Changes" comment="">
<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/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$/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 id="2bf04d9d-9125-4ed6-9018-847e14e9822c" name="Changes by danie" comment="" /> <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" />
@ -97,6 +103,13 @@
</list> </list>
</recent_temporary> </recent_temporary>
</component> </component>
<component name="SharedIndexes">
<attachedChunks>
<set>
<option value="jdk-21.0.1-openjdk-21.0.1-f644763e9732-f98dd351" />
</set>
</attachedChunks>
</component>
<component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" /> <component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" />
<component name="TaskManager"> <component name="TaskManager">
<task active="true" id="Default" summary="Default task"> <task active="true" id="Default" summary="Default task">

View file

@ -100,6 +100,39 @@ public class NFAImpl implements NFA {
if (!this.isFinalized || !other.isFinalized()) { if (!this.isFinalized || !other.isFinalized()) {
throw new FinalizedStateException(); throw new FinalizedStateException();
} }
// 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?
Set<String> unionStates = new HashSet<>();
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); NFAImpl unionNFA = new NFAImpl(this.initialState);
unionNFA.states.addAll(this.states); unionNFA.states.addAll(this.states);
@ -393,4 +426,11 @@ public class NFAImpl implements NFA {
return Integer.toString(dfaStates.indexOf(set)); return Integer.toString(dfaStates.indexOf(set));
} }
private String changeIfNecessary(String str, Set<String> toCheck){
while(toCheck.contains(str)){
str = str+"|";
}
return str;
}
} }