changed a bit
This commit is contained in:
parent
e6ef99bb8b
commit
29e5431bc7
3 changed files with 84 additions and 111 deletions
82
.idea/workspace.xml
generated
82
.idea/workspace.xml
generated
|
|
@ -4,15 +4,13 @@
|
|||
<option name="autoReloadType" value="SELECTIVE" />
|
||||
</component>
|
||||
<component name="ChangeListManager">
|
||||
<list default="true" id="f5e08808-a5af-4c89-a1ee-21b3bcb9ae3e" name="Changes" comment="">
|
||||
<change beforePath="$PROJECT_DIR$/.idea/compiler.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/compiler.xml" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/.idea/jarRepositories.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/jarRepositories.xml" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/.idea/misc.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/misc.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 default="true" id="f5e08808-a5af-4c89-a1ee-21b3bcb9ae3e" name="Changes" comment="progress of 7/1">
|
||||
<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" />
|
||||
<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="2bf04d9d-9125-4ed6-9018-847e14e9822c" name="Changes by danie" comment="" />
|
||||
<option name="SHOW_DIALOG" value="false" />
|
||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
|
||||
|
|
@ -42,36 +40,6 @@
|
|||
"second": "e0c4ebfe-e254-4a34-93d3-a6ee2cb18f94"
|
||||
}
|
||||
}</component>
|
||||
<component name="LineStatusTrackerManager">
|
||||
<file path="$PROJECT_DIR$/src/main/java/ab1/impl/GRUPPE/NFAImpl.java">
|
||||
<ranges>
|
||||
<range start1="9" end1="9" start2="9" end2="10" changelist="f5e08808-a5af-4c89-a1ee-21b3bcb9ae3e" />
|
||||
<range start1="37" end1="37" start2="38" end2="39" changelist="f5e08808-a5af-4c89-a1ee-21b3bcb9ae3e" />
|
||||
<range start1="56" end1="61" start2="58" end2="68" changelist="f5e08808-a5af-4c89-a1ee-21b3bcb9ae3e" />
|
||||
<range start1="62" end1="62" start2="69" end2="78" changelist="f5e08808-a5af-4c89-a1ee-21b3bcb9ae3e" />
|
||||
<range start1="67" end1="71" start2="83" end2="86" changelist="f5e08808-a5af-4c89-a1ee-21b3bcb9ae3e" />
|
||||
<range start1="72" end1="72" start2="87" end2="96" changelist="f5e08808-a5af-4c89-a1ee-21b3bcb9ae3e" />
|
||||
<range start1="76" end1="77" start2="100" end2="101" changelist="f5e08808-a5af-4c89-a1ee-21b3bcb9ae3e" />
|
||||
<range start1="94" end1="95" start2="118" end2="119" changelist="f5e08808-a5af-4c89-a1ee-21b3bcb9ae3e" />
|
||||
<range start1="111" end1="112" start2="135" end2="136" changelist="f5e08808-a5af-4c89-a1ee-21b3bcb9ae3e" />
|
||||
<range start1="122" end1="123" start2="146" end2="147" changelist="f5e08808-a5af-4c89-a1ee-21b3bcb9ae3e" />
|
||||
<range start1="187" end1="188" start2="211" end2="212" changelist="f5e08808-a5af-4c89-a1ee-21b3bcb9ae3e" />
|
||||
<range start1="230" end1="231" start2="254" end2="255" changelist="f5e08808-a5af-4c89-a1ee-21b3bcb9ae3e" />
|
||||
<range start1="242" end1="242" start2="266" end2="267" changelist="f5e08808-a5af-4c89-a1ee-21b3bcb9ae3e" />
|
||||
<range start1="254" end1="273" start2="279" end2="282" changelist="f5e08808-a5af-4c89-a1ee-21b3bcb9ae3e" />
|
||||
<range start1="278" end1="279" start2="287" end2="288" changelist="f5e08808-a5af-4c89-a1ee-21b3bcb9ae3e" />
|
||||
<range start1="287" end1="288" start2="296" end2="300" changelist="f5e08808-a5af-4c89-a1ee-21b3bcb9ae3e" />
|
||||
<range start1="290" end1="291" start2="302" end2="303" changelist="2bf04d9d-9125-4ed6-9018-847e14e9822c" />
|
||||
<range start1="292" end1="293" start2="304" end2="305" changelist="f5e08808-a5af-4c89-a1ee-21b3bcb9ae3e" />
|
||||
<range start1="297" end1="310" start2="309" end2="313" changelist="f5e08808-a5af-4c89-a1ee-21b3bcb9ae3e" />
|
||||
<range start1="312" end1="313" start2="315" end2="317" changelist="f5e08808-a5af-4c89-a1ee-21b3bcb9ae3e" />
|
||||
<range start1="314" end1="317" start2="318" end2="321" changelist="f5e08808-a5af-4c89-a1ee-21b3bcb9ae3e" />
|
||||
<range start1="377" end1="388" start2="381" end2="388" changelist="f5e08808-a5af-4c89-a1ee-21b3bcb9ae3e" />
|
||||
<range start1="389" end1="389" start2="389" end2="393" changelist="2bf04d9d-9125-4ed6-9018-847e14e9822c" />
|
||||
<range start1="390" end1="404" start2="394" end2="394" changelist="f5e08808-a5af-4c89-a1ee-21b3bcb9ae3e" />
|
||||
</ranges>
|
||||
</file>
|
||||
</component>
|
||||
<component name="MarkdownSettingsMigration">
|
||||
<option name="stateVersion" value="1" />
|
||||
</component>
|
||||
|
|
@ -83,25 +51,25 @@
|
|||
<option name="hideEmptyMiddlePackages" value="true" />
|
||||
<option name="showLibraryContents" value="true" />
|
||||
</component>
|
||||
<component name="PropertiesComponent">{
|
||||
"keyToString": {
|
||||
"RunOnceActivity.OpenProjectViewOnStart": "true",
|
||||
"RunOnceActivity.ShowReadmeOnStart": "true",
|
||||
"WebServerToolWindowFactoryState": "false",
|
||||
"git-widget-placeholder": "main",
|
||||
"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.pluginManager",
|
||||
"vue.rearranger.settings.migration": "true"
|
||||
<component name="PropertiesComponent"><![CDATA[{
|
||||
"keyToString": {
|
||||
"RunOnceActivity.OpenProjectViewOnStart": "true",
|
||||
"RunOnceActivity.ShowReadmeOnStart": "true",
|
||||
"WebServerToolWindowFactoryState": "false",
|
||||
"git-widget-placeholder": "2-playing-around",
|
||||
"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.pluginManager",
|
||||
"vue.rearranger.settings.migration": "true"
|
||||
}
|
||||
}</component>
|
||||
}]]></component>
|
||||
<component name="RunManager">
|
||||
<configuration name="ab1.tests in ETI_Abgabe" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
|
||||
<module name="ETI_Abgabe" />
|
||||
|
|
@ -151,6 +119,10 @@
|
|||
<component name="TypeScriptGeneratedFilesManager">
|
||||
<option name="version" value="3" />
|
||||
</component>
|
||||
<component name="VcsManagerConfiguration">
|
||||
<MESSAGE value="progress of 7/1" />
|
||||
<option name="LAST_COMMIT_MESSAGE" value="progress of 7/1" />
|
||||
</component>
|
||||
<component name="XDebuggerManager">
|
||||
<breakpoint-manager>
|
||||
<breakpoints>
|
||||
|
|
|
|||
|
|
@ -2,12 +2,10 @@ package ab1.impl.GRUPPE;
|
|||
|
||||
import ab1.FinalizedStateException;
|
||||
import ab1.NFA;
|
||||
import ab1.NFAFactory;
|
||||
import ab1.Transition;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class NFAImpl implements NFA {
|
||||
private Set<String> states;
|
||||
|
|
@ -68,7 +66,7 @@ public class NFAImpl implements NFA {
|
|||
this.transitions.add(transition);
|
||||
}
|
||||
|
||||
public void addAllTransition(Set<Transition> transitions) throws FinalizedStateException {
|
||||
public void addAllTransitions(Set<Transition> transitions) throws FinalizedStateException {
|
||||
if(this.isFinalized){
|
||||
throw new FinalizedStateException();
|
||||
}
|
||||
|
|
@ -96,6 +94,7 @@ public class NFAImpl implements NFA {
|
|||
}
|
||||
|
||||
// #TODO
|
||||
// handle case where the state is duplicated
|
||||
@Override
|
||||
public NFA union(NFA other) throws FinalizedStateException {
|
||||
if (!this.isFinalized || !other.isFinalized()) {
|
||||
|
|
@ -114,6 +113,7 @@ public class NFAImpl implements NFA {
|
|||
}
|
||||
|
||||
// #TODO
|
||||
// needs to work with a DFA not NFA
|
||||
@Override
|
||||
public NFA intersection(NFA other) throws FinalizedStateException {
|
||||
if (!this.isFinalized || !other.isFinalized()) {
|
||||
|
|
@ -162,21 +162,20 @@ public class NFAImpl implements NFA {
|
|||
|
||||
// copy, but without accepting states
|
||||
nfa.states.addAll(this.states);
|
||||
nfa.transitions.addAll(this.transitions);
|
||||
nfa.addAllTransitions(this.transitions);
|
||||
|
||||
// adding the initial state as accepting state because we have to accept the empty string
|
||||
nfa.acceptingStates.add(this.initialState);
|
||||
|
||||
// for each accepting state
|
||||
for (String acceptingState : this.acceptingStates) {
|
||||
for (String acceptingState : this.getAcceptingStates()) {
|
||||
Transition loopBackTransition =
|
||||
// creating an epsilon transition (null) for each accepting state
|
||||
new Transition(acceptingState, null, this.initialState);
|
||||
if (!nfa.transitions.contains(loopBackTransition)) {
|
||||
nfa.transitions.add(loopBackTransition);
|
||||
}
|
||||
nfa.transitions.add(loopBackTransition);
|
||||
}
|
||||
|
||||
|
||||
return nfa;
|
||||
}
|
||||
|
||||
|
|
@ -186,13 +185,22 @@ public class NFAImpl implements NFA {
|
|||
throw new FinalizedStateException();
|
||||
}
|
||||
|
||||
NFAImpl nfa = new NFAImpl(this.initialState);
|
||||
String newInitialState = "newSTART";
|
||||
NFAImpl nfa = new NFAImpl(newInitialState);
|
||||
|
||||
// simple copy
|
||||
nfa.states.addAll(this.states);
|
||||
nfa.transitions.addAll(this.transitions);
|
||||
nfa.acceptingStates.addAll(this.acceptingStates);
|
||||
|
||||
nfa.transitions.add(new Transition(newInitialState, null, this.initialState));
|
||||
|
||||
|
||||
for (String acceptingState : this.acceptingStates) {
|
||||
nfa.transitions.add(new Transition(acceptingState, null, newInitialState));
|
||||
}
|
||||
|
||||
/*
|
||||
// for each accepting state
|
||||
for (String acceptingState : this.acceptingStates) {
|
||||
Transition loopBackTransition =
|
||||
|
|
@ -202,6 +210,7 @@ public class NFAImpl implements NFA {
|
|||
nfa.transitions.add(loopBackTransition);
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
return nfa;
|
||||
}
|
||||
|
|
@ -213,9 +222,14 @@ public class NFAImpl implements NFA {
|
|||
throw new FinalizedStateException();
|
||||
}
|
||||
|
||||
NFAImpl complementNFA = new NFAImpl(this.initialState);
|
||||
complementNFA.states.addAll(this.states);
|
||||
complementNFA.transitions.addAll(this.transitions);
|
||||
// create a copy of this NFA
|
||||
NFAImpl nfa = new NFAImpl(this.initialState);
|
||||
nfa.states.addAll(this.states);
|
||||
nfa.transitions.addAll(this.transitions);
|
||||
nfa.acceptingStates.addAll(this.acceptingStates);
|
||||
|
||||
//nfa = nfa.convertNFAtoDFA(nfa);
|
||||
|
||||
|
||||
/*
|
||||
for(String state : this.states){
|
||||
|
|
@ -248,22 +262,40 @@ public class NFAImpl implements NFA {
|
|||
// #TODO
|
||||
@Override
|
||||
public boolean acceptsWord(String word) throws FinalizedStateException {
|
||||
//check if word is accepted
|
||||
if (!this.isFinalized) {
|
||||
throw new FinalizedStateException();
|
||||
}
|
||||
|
||||
Set<String> currentStates = new HashSet<>();
|
||||
currentStates.add(this.initialState);
|
||||
currentStates = epsilonClosure(currentStates, this);
|
||||
|
||||
|
||||
for (char letter : word.toCharArray()) {
|
||||
Set<String> nextStates = new HashSet<>();
|
||||
|
||||
|
||||
for (String state : currentStates) {
|
||||
nextStates.addAll(getStateAfterTransition(currentStates, letter, this));
|
||||
}
|
||||
|
||||
nextStates = epsilonClosure(nextStates, this);
|
||||
|
||||
currentStates = nextStates;
|
||||
}
|
||||
|
||||
for (String state : currentStates) {
|
||||
if (this.acceptingStates.contains(state)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public NFA convertNFAtoDFA(NFAImpl input) {
|
||||
|
||||
/*
|
||||
What do we need to do?
|
||||
|
||||
Helper Methods:
|
||||
- epsilonClosure
|
||||
- getStateAfterTransition
|
||||
- determineAcceptingStates
|
||||
|
||||
*/
|
||||
|
||||
// all accepting states of the DFA
|
||||
Set<String> dfaAcceptingStates = new HashSet<>();
|
||||
// all states of the DFA
|
||||
List<Set<String>> dfaStates = new ArrayList<>();
|
||||
|
|
@ -299,11 +331,9 @@ public class NFAImpl implements NFA {
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
// build new Transition
|
||||
dfaTransitions.add(new Transition(getIndexOfSet(currentState, dfaStates), letter, getIndexOfSet(newState, dfaStates)));
|
||||
|
||||
// we got to change this to only a string is given
|
||||
//dfaTransitions.add(new Transition(currentState, letter, newState));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -313,7 +343,7 @@ public class NFAImpl implements NFA {
|
|||
newDFA.states.add(""+i);
|
||||
}
|
||||
|
||||
newDFA.addAllTransition(dfaTransitions);
|
||||
newDFA.addAllTransitions(dfaTransitions);
|
||||
newDFA.addAllAcceptingStates(dfaAcceptingStates);
|
||||
|
||||
newDFA.finalizeAutomaton();
|
||||
|
|
@ -322,35 +352,6 @@ public class NFAImpl implements NFA {
|
|||
}
|
||||
|
||||
private Set<String> epsilonClosure(Set<String> states, NFA nfa) {
|
||||
/*
|
||||
Original:
|
||||
|
||||
boolean isAccepting = false;
|
||||
|
||||
int index = 0;
|
||||
|
||||
List<Set<String>> DFA_states = new ArrayList<>();
|
||||
Set<Transition> DFA_transitions = new HashSet<>();
|
||||
|
||||
// start state alle verbindungen mit epsilon als set
|
||||
for(String state : states) {
|
||||
for (Transition transition : input.transitions) {
|
||||
if (state.equals(transition.fromState()) && transition.readSymbol() == null) {
|
||||
if(!isAccepting) {
|
||||
for (String acceptingState : acceptingStates)
|
||||
if (transition.toState().equals(acceptingState)) {
|
||||
isAccepting = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
states.add(transition.toState());
|
||||
// funktioniert immer noch, wenn w epsilon Übergänge hintereinander?
|
||||
}
|
||||
}
|
||||
}
|
||||
DFA_states.add(new HashSet<>(states));
|
||||
*/
|
||||
|
||||
Set<String> closure = new HashSet<>(states);
|
||||
Stack<String> stack = new Stack<>();
|
||||
stack.addAll(states);
|
||||
|
|
|
|||
Binary file not shown.
Reference in a new issue