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="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",
|
||||||
"git-widget-placeholder": "main",
|
"git-widget-placeholder": "2-playing-around",
|
||||||
"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.pluginManager",
|
||||||
"vue.rearranger.settings.migration": "true"
|
"vue.rearranger.settings.migration": "true"
|
||||||
}
|
}
|
||||||
}</component>
|
}]]></component>
|
||||||
<component name="RunManager">
|
<component name="RunManager">
|
||||||
<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" />
|
||||||
|
|
@ -122,11 +122,25 @@
|
||||||
<workItem from="1704712375384" duration="4940000" />
|
<workItem from="1704712375384" duration="4940000" />
|
||||||
<workItem from="1704717343016" duration="2934000" />
|
<workItem from="1704717343016" duration="2934000" />
|
||||||
</task>
|
</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 />
|
<servers />
|
||||||
</component>
|
</component>
|
||||||
<component name="TypeScriptGeneratedFilesManager">
|
<component name="TypeScriptGeneratedFilesManager">
|
||||||
<option name="version" value="3" />
|
<option name="version" value="3" />
|
||||||
</component>
|
</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">
|
<component name="XDebuggerManager">
|
||||||
<breakpoint-manager>
|
<breakpoint-manager>
|
||||||
<breakpoints>
|
<breakpoints>
|
||||||
|
|
|
||||||
|
|
@ -2,12 +2,10 @@ package ab1.impl.GRUPPE;
|
||||||
|
|
||||||
import ab1.FinalizedStateException;
|
import ab1.FinalizedStateException;
|
||||||
import ab1.NFA;
|
import ab1.NFA;
|
||||||
import ab1.NFAFactory;
|
|
||||||
import ab1.Transition;
|
import ab1.Transition;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
public class NFAImpl implements NFA {
|
public class NFAImpl implements NFA {
|
||||||
private Set<String> states;
|
private Set<String> states;
|
||||||
|
|
@ -68,7 +66,7 @@ public class NFAImpl implements NFA {
|
||||||
this.transitions.add(transition);
|
this.transitions.add(transition);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addAllTransition(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();
|
||||||
}
|
}
|
||||||
|
|
@ -96,6 +94,7 @@ public class NFAImpl implements NFA {
|
||||||
}
|
}
|
||||||
|
|
||||||
// #TODO
|
// #TODO
|
||||||
|
// handle case where the state is duplicated
|
||||||
@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()) {
|
||||||
|
|
@ -147,6 +146,7 @@ public class NFAImpl implements NFA {
|
||||||
}
|
}
|
||||||
|
|
||||||
// #TODO
|
// #TODO
|
||||||
|
// needs to work with a DFA not NFA
|
||||||
@Override
|
@Override
|
||||||
public NFA intersection(NFA other) throws FinalizedStateException {
|
public NFA intersection(NFA other) throws FinalizedStateException {
|
||||||
if (!this.isFinalized || !other.isFinalized()) {
|
if (!this.isFinalized || !other.isFinalized()) {
|
||||||
|
|
@ -195,20 +195,19 @@ public class NFAImpl implements NFA {
|
||||||
|
|
||||||
// copy, but without accepting states
|
// copy, but without accepting states
|
||||||
nfa.states.addAll(this.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
|
// adding the initial state as accepting state because we have to accept the empty string
|
||||||
nfa.acceptingStates.add(this.initialState);
|
nfa.acceptingStates.add(this.initialState);
|
||||||
|
|
||||||
// for each accepting state
|
// for each accepting state
|
||||||
for (String acceptingState : this.acceptingStates) {
|
for (String acceptingState : this.getAcceptingStates()) {
|
||||||
Transition loopBackTransition =
|
Transition loopBackTransition =
|
||||||
// creating an epsilon transition (null) for each accepting state
|
// creating an epsilon transition (null) for each accepting state
|
||||||
new Transition(acceptingState, null, this.initialState);
|
new Transition(acceptingState, null, this.initialState);
|
||||||
if (!nfa.transitions.contains(loopBackTransition)) {
|
|
||||||
nfa.transitions.add(loopBackTransition);
|
nfa.transitions.add(loopBackTransition);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return nfa;
|
return nfa;
|
||||||
}
|
}
|
||||||
|
|
@ -219,13 +218,22 @@ public class NFAImpl implements NFA {
|
||||||
throw new FinalizedStateException();
|
throw new FinalizedStateException();
|
||||||
}
|
}
|
||||||
|
|
||||||
NFAImpl nfa = new NFAImpl(this.initialState);
|
String newInitialState = "newSTART";
|
||||||
|
NFAImpl nfa = new NFAImpl(newInitialState);
|
||||||
|
|
||||||
// simple copy
|
// simple copy
|
||||||
nfa.states.addAll(this.states);
|
nfa.states.addAll(this.states);
|
||||||
nfa.transitions.addAll(this.transitions);
|
nfa.transitions.addAll(this.transitions);
|
||||||
nfa.acceptingStates.addAll(this.acceptingStates);
|
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 each accepting state
|
||||||
for (String acceptingState : this.acceptingStates) {
|
for (String acceptingState : this.acceptingStates) {
|
||||||
Transition loopBackTransition =
|
Transition loopBackTransition =
|
||||||
|
|
@ -235,6 +243,7 @@ public class NFAImpl implements NFA {
|
||||||
nfa.transitions.add(loopBackTransition);
|
nfa.transitions.add(loopBackTransition);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
return nfa;
|
return nfa;
|
||||||
}
|
}
|
||||||
|
|
@ -246,9 +255,14 @@ public class NFAImpl implements NFA {
|
||||||
throw new FinalizedStateException();
|
throw new FinalizedStateException();
|
||||||
}
|
}
|
||||||
|
|
||||||
NFAImpl complementNFA = new NFAImpl(this.initialState);
|
// create a copy of this NFA
|
||||||
complementNFA.states.addAll(this.states);
|
NFAImpl nfa = new NFAImpl(this.initialState);
|
||||||
complementNFA.transitions.addAll(this.transitions);
|
nfa.states.addAll(this.states);
|
||||||
|
nfa.transitions.addAll(this.transitions);
|
||||||
|
nfa.acceptingStates.addAll(this.acceptingStates);
|
||||||
|
|
||||||
|
//nfa = nfa.convertNFAtoDFA(nfa);
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
for(String state : this.states){
|
for(String state : this.states){
|
||||||
|
|
@ -281,22 +295,40 @@ public class NFAImpl implements NFA {
|
||||||
// #TODO
|
// #TODO
|
||||||
@Override
|
@Override
|
||||||
public boolean acceptsWord(String word) throws FinalizedStateException {
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public NFA convertNFAtoDFA(NFAImpl input) {
|
public NFA convertNFAtoDFA(NFAImpl input) {
|
||||||
|
|
||||||
/*
|
// all accepting states of the DFA
|
||||||
What do we need to do?
|
|
||||||
|
|
||||||
Helper Methods:
|
|
||||||
- epsilonClosure
|
|
||||||
- getStateAfterTransition
|
|
||||||
- determineAcceptingStates
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
Set<String> dfaAcceptingStates = new HashSet<>();
|
Set<String> dfaAcceptingStates = new HashSet<>();
|
||||||
// all states of the DFA
|
// all states of the DFA
|
||||||
List<Set<String>> dfaStates = new ArrayList<>();
|
List<Set<String>> dfaStates = new ArrayList<>();
|
||||||
|
|
@ -332,11 +364,9 @@ public class NFAImpl implements NFA {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// build new Transition
|
// build new Transition
|
||||||
dfaTransitions.add(new Transition(getIndexOfSet(currentState, dfaStates), letter, getIndexOfSet(newState, dfaStates)));
|
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.states.add(""+i);
|
||||||
}
|
}
|
||||||
|
|
||||||
newDFA.addAllTransition(dfaTransitions);
|
newDFA.addAllTransitions(dfaTransitions);
|
||||||
newDFA.addAllAcceptingStates(dfaAcceptingStates);
|
newDFA.addAllAcceptingStates(dfaAcceptingStates);
|
||||||
|
|
||||||
newDFA.finalizeAutomaton();
|
newDFA.finalizeAutomaton();
|
||||||
|
|
@ -355,35 +385,6 @@ public class NFAImpl implements NFA {
|
||||||
}
|
}
|
||||||
|
|
||||||
private Set<String> epsilonClosure(Set<String> states, NFA 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);
|
Set<String> closure = new HashSet<>(states);
|
||||||
Stack<String> stack = new Stack<>();
|
Stack<String> stack = new Stack<>();
|
||||||
stack.addAll(states);
|
stack.addAll(states);
|
||||||
|
|
|
||||||
Binary file not shown.
Reference in a new issue