diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index f9a5ccb..7e2fa0e 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -4,7 +4,8 @@
-
+
+
@@ -55,33 +56,33 @@
- {
+ "keyToString": {
+ "JUnit.ComplexTests.executor": "Run",
+ "JUnit.ComplexTests.finite1Test.executor": "Run",
+ "JUnit.ComplexTests.finite2Test.executor": "Debug",
+ "JUnit.ComplexTests.intersection1Test.executor": "Run",
+ "JUnit.ComplexTests.intersection2Test.executor": "Run",
+ "JUnit.myTests.intersection1Test.executor": "Run",
+ "RunOnceActivity.OpenProjectViewOnStart": "true",
+ "RunOnceActivity.ShowReadmeOnStart": "true",
+ "SHARE_PROJECT_CONFIGURATION_FILES": "true",
+ "WebServerToolWindowFactoryState": "false",
+ "full.screen.before.presentation.mode": "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.lookFeel",
+ "vue.rearranger.settings.migration": "true"
}
-}]]>
+}
@@ -326,7 +327,8 @@
-
+
+
diff --git a/src/main/java/ab1/impl/gruppe10_aigensberger_dworski_walcher/NFAImpl.java b/src/main/java/ab1/impl/gruppe10_aigensberger_dworski_walcher/NFAImpl.java
index 97e1078..b1c18ac 100644
--- a/src/main/java/ab1/impl/gruppe10_aigensberger_dworski_walcher/NFAImpl.java
+++ b/src/main/java/ab1/impl/gruppe10_aigensberger_dworski_walcher/NFAImpl.java
@@ -405,10 +405,9 @@ public class NFAImpl implements NFA {
*/
@Override
public boolean isFinite() {
-
List path = new ArrayList<>();
List transitions= new ArrayList<>(this.getTransitions());
- AtomicInteger finished = new AtomicInteger(0);
+ AtomicInteger finished = new AtomicInteger(0); // saves result over function calls
List letters = new ArrayList<>(this.alphabet);
if(this.alphabet.isEmpty()){
return true;
@@ -416,8 +415,7 @@ public class NFAImpl implements NFA {
if(!letters.contains(null)) {
letters.add(null);
}
-
- path.add(new Tuple('a', this.initialState));
+ path.add(new Tuple('a', this.initialState)); //'a' is just a dummy value
if(fillToEnd(path, transitions, letters, finished)){
return false;
}
@@ -433,9 +431,17 @@ public class NFAImpl implements NFA {
return true;
}
+ /**
+ * Call method, if the last element of path has been checked, to continue
+ * (Is build like a recursive method but changed to iterative for no big memory savings)
+ * returns immediately if the last element is the first (end of recursion)
+ * Changes the last element to next available by:
+ * 1. checking weather with the same letter there is another Transition to a new toState
+ * 2. checking weather for any new letter there is a valid new Transition to a new state
+ * 3. deleting the current last element of path, so the second last element gets the status checked and continue from there
+ */
private void continueOnLastTuple(List path, List transitions, List letters, AtomicInteger finished) {
- // path is already filled to end -> check next available state for the transition.
- // case we reached the limit (last state)
+ // trivial case
if(path.size()==1){
finished.set(1);
return;
@@ -447,10 +453,8 @@ public class NFAImpl implements NFA {
if(transitions.get(i).fromState().equals(fromState) && transitions.get(i).readSymbol()==(readSymbol)){
String newState = transitions.get(i).toState();
if (stateInPath(path, newState)) {
- //loop!
- //loop ends in acceptingstate?
+ //loop found
if(stateReachesAcceptingstates(newState)) {
- //true:
finished.set(2);
return;
}
@@ -460,7 +464,7 @@ public class NFAImpl implements NFA {
if(fillToEnd(path, transitions, letters, finished)){
return;
}
- return;// continueOnLastTuple(path, transitions, letters);
+ return;
}
}
}
@@ -468,19 +472,14 @@ public class NFAImpl implements NFA {
for(int i=letters.indexOf(readSymbol)+1;i remove last Tuple and return
path.remove(path.size()-1);
- //goto next thingy
- //return;// continueOnLastTuple(path, transitions, letters);
}
/**
- * !Does not check the new state added
- * @return -state if a tostate for the newletter is found and deletes the old Tuple
- * -null if with the newletter there is no transition further
+ * Checks for the second last state in path, weather it has a Transition with the given letter or not
+ * !Does not check the state, which is returned!
+ * @return state if a toState for the letter is found. And deletes the old last Tuple
+ * null if for the letter there is no further Transition
*/
private String checkForNewLetter(List path, List transitions, Character letter){
String fromState = path.get(path.size()-2).getElement_2();
@@ -520,9 +516,11 @@ public class NFAImpl implements NFA {
/**
- * call method, if the last Element of path is ok
- * after method need to
+ * Fills in the first possible path for the last element and checks
+ * every state until the end (last element also gets checked).
+ * (recursive method)
* @return true if a valid loop has been found while filling it up
+ * false if everything worked fine
*/
private boolean fillToEnd(List path, List transitions, List letters, AtomicInteger finished){
String fromState = path.get(path.size()-1).getElement_2();
@@ -531,26 +529,29 @@ public class NFAImpl implements NFA {
if(transition.fromState().equals(fromState)&&transition.readSymbol()==(letter)){
//found new Transition
if(stateInPath(path, transition.toState())) {
- //loop!
- //loop reaches a acceptingstate? then return true, else delete some shit
+ //loop found
if(stateReachesAcceptingstates(transition.toState())) {
- //true:
finished.set(2);
return true;
}
- //else do nothing and take next transition if possible
+ //else go to next Transition
} else {
path.add(new Tuple(letter, transition.toState()));
+ //recursion until the state has no valid Transition
return fillToEnd(path, transitions, letters, finished);
}
}
}
}
- //from the last State in path there is no further Transition (dead end = job done)
+ //dead end = job done
return false;
-
}
+ /**
+ * Checks weather the given state is already in the path (-> loop)
+ * @return false if the given state is not in the path
+ * true if the given state is in the path -> a loop occurred
+ */
private boolean stateInPath(List path, String state){
for(Tuple tuple : path){
if(tuple.getElement_2().equals(state)){
@@ -560,6 +561,12 @@ public class NFAImpl implements NFA {
return false;
}
+ /**
+ * Checks weather the given state is able to reach an accepting state of the nfa
+ * (checks weather the loop found actually has an impact)
+ * @return true if the state reaches an accepting state of the nfa
+ * false if it does not
+ */
private boolean stateReachesAcceptingstates(String state){
if(this.acceptingStates.contains(state)){
return true;
@@ -567,7 +574,7 @@ public class NFAImpl implements NFA {
Set currentStates = new HashSet<>();
Set newStates = new HashSet<>();
currentStates.add(state);
- boolean containsNewStates;
+ boolean containsNewStates; //weather all reachable states have been found
do{
containsNewStates = false;
for(String currentstate : currentStates){
@@ -616,7 +623,6 @@ public class NFAImpl implements NFA {
return isAcceptingState(currentStates, this);
}
-
/**
* Converts the given NFA to a DFA. If the NFA is not finalized, a FinalizedStateException is thrown.
* @param input The NFA to convert