Merge branch '2-playing-around' into 'main'
Resolve "playing around" Closes #2 See merge request rawalcher/theorethische-informatik-gruppe-10!2
This commit is contained in:
commit
10c49f3b70
3 changed files with 89 additions and 74 deletions
50
.idea/workspace.xml
generated
50
.idea/workspace.xml
generated
|
|
@ -52,25 +52,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" />
|
||||
|
|
@ -122,11 +122,25 @@
|
|||
<workItem from="1704712375384" duration="4940000" />
|
||||
<workItem from="1704717343016" duration="2934000" />
|
||||
</task>
|
||||
<task id="LOCAL-00001" summary="changed a bit">
|
||||
<option name="closed" value="true" />
|
||||
<created>1704734947115</created>
|
||||
<option name="number" value="00001" />
|
||||
<option name="presentableId" value="LOCAL-00001" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1704734947115</updated>
|
||||
</task>
|
||||
<option name="localTasksCounter" value="2" />
|
||||
<servers />
|
||||
</component>
|
||||
<component name="TypeScriptGeneratedFilesManager">
|
||||
<option name="version" value="3" />
|
||||
</component>
|
||||
<component name="VcsManagerConfiguration">
|
||||
<MESSAGE value="progress of 7/1" />
|
||||
<MESSAGE value="changed a bit" />
|
||||
<option name="LAST_COMMIT_MESSAGE" value="changed a bit" />
|
||||
</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()) {
|
||||
|
|
@ -147,6 +146,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()) {
|
||||
|
|
@ -195,20 +195,19 @@ 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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return nfa;
|
||||
}
|
||||
|
|
@ -219,13 +218,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 =
|
||||
|
|
@ -235,6 +243,7 @@ public class NFAImpl implements NFA {
|
|||
nfa.transitions.add(loopBackTransition);
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
return nfa;
|
||||
}
|
||||
|
|
@ -246,9 +255,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){
|
||||
|
|
@ -281,22 +295,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<>();
|
||||
|
|
@ -332,11 +364,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));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -346,7 +376,7 @@ public class NFAImpl implements NFA {
|
|||
newDFA.states.add(""+i);
|
||||
}
|
||||
|
||||
newDFA.addAllTransition(dfaTransitions);
|
||||
newDFA.addAllTransitions(dfaTransitions);
|
||||
newDFA.addAllAcceptingStates(dfaAcceptingStates);
|
||||
|
||||
newDFA.finalizeAutomaton();
|
||||
|
|
@ -355,35 +385,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