diff --git a/.idea/compiler.xml b/.idea/compiler.xml
index 273d387..7efc65a 100644
--- a/.idea/compiler.xml
+++ b/.idea/compiler.xml
@@ -2,6 +2,7 @@
+
diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml
index 712ab9d..2161097 100644
--- a/.idea/jarRepositories.xml
+++ b/.idea/jarRepositories.xml
@@ -3,8 +3,13 @@
-
-
+
+
+
+
+
+
+
diff --git a/.idea/misc.xml b/.idea/misc.xml
index 2738f8e..ecfa09c 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -8,5 +8,7 @@
-
+
+
+
\ No newline at end of file
diff --git a/.idea/shelf/Uncommitted_changes_before_Update_at_08_01_2024_12_06_[Changes]/shelved.patch b/.idea/shelf/Uncommitted_changes_before_Update_at_08_01_2024_12_06_[Changes]/shelved.patch
new file mode 100644
index 0000000..9fc6e24
--- /dev/null
+++ b/.idea/shelf/Uncommitted_changes_before_Update_at_08_01_2024_12_06_[Changes]/shelved.patch
@@ -0,0 +1,22 @@
+Index: .idea/jarRepositories.xml
+IDEA additional info:
+Subsystem: com.intellij.openapi.diff.impl.patch.BaseRevisionTextPatchEP
+<+>\r\n\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n
+Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
+<+>UTF-8
+===================================================================
+diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml
+--- a/.idea/jarRepositories.xml (revision b2f6932eae27588a4b5ad8e1bb1f83f2a533182a)
++++ b/.idea/jarRepositories.xml (date 1704711982177)
+@@ -7,6 +7,11 @@
+
+
+
++
++
++
++
++
+
+
+
diff --git a/.idea/shelf/Uncommitted_changes_before_Update_at_08_01_2024_12_06__Changes_.xml b/.idea/shelf/Uncommitted_changes_before_Update_at_08_01_2024_12_06__Changes_.xml
new file mode 100644
index 0000000..4892713
--- /dev/null
+++ b/.idea/shelf/Uncommitted_changes_before_Update_at_08_01_2024_12_06__Changes_.xml
@@ -0,0 +1,4 @@
+
+
+
+
\ No newline at end of file
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
new file mode 100644
index 0000000..4fde15a
--- /dev/null
+++ b/.idea/workspace.xml
@@ -0,0 +1,165 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ {
+ "lastFilter": {
+ "state": "OPENED",
+ "assignee": {
+ "type": "org.jetbrains.plugins.gitlab.mergerequest.ui.filters.GitLabMergeRequestsFiltersValue.MergeRequestsMemberFilterValue.MergeRequestsAssigneeFilterValue",
+ "username": "rawalcher",
+ "fullname": "rawalcher"
+ }
+ }
+}
+ {
+ "selectedUrlAndAccountId": {
+ "first": "https://git-ainf.aau.at/rawalcher/theorethische-informatik-gruppe-10.git",
+ "second": "e0c4ebfe-e254-4a34-93d3-a6ee2cb18f94"
+ }
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ {
+ "associatedIndex": 2
+}
+
+
+
+
+
+ {
+ "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"
+ }
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1704700820495
+
+
+ 1704700820495
+
+
+
+
+
+
+
+
+
+
+
+
+
+ file://$PROJECT_DIR$/src/test/java/ab1/tests/ComplexTests.java
+ 171
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/main/java/ab1/impl/GRUPPE/NFAImpl.java b/src/main/java/ab1/impl/GRUPPE/NFAImpl.java
index 698c513..3d79de2 100644
--- a/src/main/java/ab1/impl/GRUPPE/NFAImpl.java
+++ b/src/main/java/ab1/impl/GRUPPE/NFAImpl.java
@@ -7,6 +7,7 @@ import ab1.Transition;
import lombok.Getter;
import java.util.*;
+import java.util.stream.Collectors;
public class NFAImpl implements NFA {
private Set states;
@@ -35,6 +36,7 @@ public class NFAImpl implements NFA {
public Set getStates() {
return this.states;
}
+
@Override
public Collection getTransitions() {
return this.transitions;
@@ -54,10 +56,24 @@ public class NFAImpl implements NFA {
public void addTransition(Transition transition) throws FinalizedStateException {
if (this.isFinalized) {
throw new FinalizedStateException();
- } else if (!this.transitions.contains(transition)) {
- // add symbol to alphabet. If it is already in the alphabet, nothing happens
- this.alphabet.add(transition.readSymbol());
- this.transitions.add(transition);
+ }
+ if (!states.contains(transition.fromState())) {
+ this.states.add(transition.fromState());
+ }
+ if (!states.contains(transition.toState())) {
+ this.states.add(transition.toState());
+ }
+ // add symbol to alphabet. If it is already in the alphabet, nothing happens
+ this.alphabet.add(transition.readSymbol());
+ this.transitions.add(transition);
+ }
+
+ public void addAllTransition(Set transitions) throws FinalizedStateException {
+ if(this.isFinalized){
+ throw new FinalizedStateException();
+ }
+ for (Transition transition : transitions) {
+ this.addTransition(transition);
}
}
@@ -65,16 +81,24 @@ public class NFAImpl implements NFA {
public void addAcceptingState(String state) throws FinalizedStateException {
if (this.isFinalized) {
throw new FinalizedStateException();
- } else if (!this.states.contains(state)) {
- this.states.add(state);
- this.acceptingStates.add(state);
+ }
+ this.states.add(state);
+ this.acceptingStates.add(state);
+ }
+
+ public void addAllAcceptingStates(Set states) throws FinalizedStateException {
+ if(this.isFinalized){
+ throw new FinalizedStateException();
+ }
+ for (String state : states) {
+ this.addAcceptingState(state);
}
}
// #TODO
@Override
public NFA union(NFA other) throws FinalizedStateException {
- if(!this.isFinalized || !other.isFinalized()){
+ if (!this.isFinalized || !other.isFinalized()) {
throw new FinalizedStateException();
}
NFAImpl unionNFA = new NFAImpl(this.initialState);
@@ -92,7 +116,7 @@ public class NFAImpl implements NFA {
// #TODO
@Override
public NFA intersection(NFA other) throws FinalizedStateException {
- if(!this.isFinalized || !other.isFinalized()){
+ if (!this.isFinalized || !other.isFinalized()) {
throw new FinalizedStateException();
}
NFAImpl intersectionNFA = new NFAImpl(this.initialState);
@@ -109,7 +133,7 @@ public class NFAImpl implements NFA {
// #TODO
@Override
public NFA concatenation(NFA other) throws FinalizedStateException {
- if(!this.isFinalized || !other.isFinalized()){
+ if (!this.isFinalized || !other.isFinalized()) {
throw new FinalizedStateException();
}
NFAImpl concatenationNFA = new NFAImpl(this.initialState);
@@ -120,7 +144,7 @@ public class NFAImpl implements NFA {
concatenationNFA.transitions.addAll(this.transitions);
concatenationNFA.transitions.addAll(other.getTransitions());
- for(String accceptingState : this.acceptingStates){
+ for (String accceptingState : this.acceptingStates) {
Transition epsilon = new Transition(accceptingState, null, other.getInitialState());
concatenationNFA.transitions.add(epsilon);
}
@@ -185,7 +209,7 @@ public class NFAImpl implements NFA {
// #TODO
@Override
public NFA complement() throws FinalizedStateException {
- if(!this.isFinalized){
+ if (!this.isFinalized) {
throw new FinalizedStateException();
}
@@ -228,7 +252,7 @@ public class NFAImpl implements NFA {
return false;
}
- public NFA convertNFAtoDFA (NFAImpl input){
+ public NFA convertNFAtoDFA(NFAImpl input) {
/*
What do we need to do?
@@ -240,6 +264,7 @@ public class NFAImpl implements NFA {
*/
+ Set dfaAcceptingStates = new HashSet<>();
// all states of the DFA
List> dfaStates = new ArrayList<>();
// all transitions of the DFA
@@ -252,31 +277,15 @@ public class NFAImpl implements NFA {
// getting the epsilon closure of the start state
startState = epsilonClosure(startState, input);
dfaStates.add(startState);
-
- // find all letters in transitions
- // obsolete, added alphabet to NFA which stores all read symbols
- /*
- Set possibleLetters = new HashSet<>();
- Set possibleTransitions = new HashSet<>();
- for(Transition transition : input.transitions){
- for(String state : states) {
- if (state.equals(transition.fromState())){
-
- if(transition.readSymbol() != null){
- possibleLetters.add(transition.readSymbol());
- possibleTransitions.add(transition);
- }
- break;
- }
- }
+ if (isAcceptingState(startState, input)){
+ dfaAcceptingStates.add(getIndexOfSet(startState, dfaStates));
}
- */
// do the above with each DFA state
Queue> queue = new LinkedList<>();
queue.add(startState);
// iterate each Letter
- while (!queue.isEmpty()){
+ while (!queue.isEmpty()) {
Set currentState = queue.poll();
// for each possible Letter
for (char letter : input.getAlphabet()) {
@@ -285,36 +294,31 @@ public class NFAImpl implements NFA {
if (!dfaStates.contains(newState)) {
queue.add(newState);
dfaStates.add(newState);
- // build new Transition
+ if (isAcceptingState(newState, input)) {
+ dfaAcceptingStates.add(getIndexOfSet(newState, dfaStates));
+ }
+
}
// build new Transition
dfaTransitions.add(new Transition(Integer.toString(dfaStates.indexOf(currentState)), letter, Integer.toString(dfaStates.indexOf(newState))));
- // we gotta change this to only a string is given
+ // we got to change this to only a string is given
//dfaTransitions.add(new Transition(currentState, letter, newState));
}
}
-/*
- for(Character letter : possibleLetters){
- Set newState = new HashSet<>();
- for(Transition trans : possibleTransitions){
- if(trans.readSymbol().equals(letter)){
- // is every transition fromState = state from states? Hoffentlich ja :')
- newState.add(trans.toState());
- }
- }
- //deal with newState + new Transitions
- if(DFA_states.contains(newState)){
- Transition newtrans = new Transition(DFA_states.get(index), letter, DFA_states.get(DFA_states.indexOf(newState)));
- }
+ NFAImpl newDFA = new NFAImpl("0");
+
+ for(int i=1;i epsilonClosure(Set states, NFA nfa) {
@@ -375,31 +379,13 @@ public class NFAImpl implements NFA {
return result;
}
- private Set> determineAcceptingStates(Set> dfaStates, NFA nfa) {
- Set> acceptingStates = new HashSet<>();
- for (Set dfaState : dfaStates) {
- for (String nfaState : dfaState) {
- if (nfa.getAcceptingStates().contains(nfaState)) {
- acceptingStates.add(dfaState);
- break;
- }
+ private boolean isAcceptingState(Set states, NFA input) {
+ for (String accState : input.getAcceptingStates()) {
+ if (states.contains(accState)) {
+ return true;
}
}
- return acceptingStates;
+ return false;
}
- public void test(){
- final NFAFactory factory = new NFAFactoryImpl();
- var instance = factory.buildNFA("START");
- instance.addTransition(
- Transition.builder()
- .fromState("START")
- .readSymbol('a')
- .toState("ACCEPT")
- .build()
- );
- instance.addAcceptingState("ACCEPT");
- instance.finalizeAutomaton();
-
- }
}
diff --git a/target/classes/ab1/impl/GRUPPE/NFAImpl.class b/target/classes/ab1/impl/GRUPPE/NFAImpl.class
index 407ea7a..1ec6e11 100644
Binary files a/target/classes/ab1/impl/GRUPPE/NFAImpl.class and b/target/classes/ab1/impl/GRUPPE/NFAImpl.class differ