documentation. cleanup. your turn daniel

This commit is contained in:
Ghost_Element 2024-01-10 22:32:28 +01:00
parent 00eabe56a5
commit 210cb281b7
2 changed files with 72 additions and 64 deletions

58
.idea/workspace.xml generated
View file

@ -4,7 +4,8 @@
<option name="autoReloadType" value="SELECTIVE" /> <option name="autoReloadType" value="SELECTIVE" />
</component> </component>
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="f5e08808-a5af-4c89-a1ee-21b3bcb9ae3e" name="Changes" comment="documentation. cleanup. your turn daniel"> <list default="true" id="f5e08808-a5af-4c89-a1ee-21b3bcb9ae3e" name="Changes" comment=".equals replaced with ==">
<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/gruppe10_aigensberger_dworski_walcher/NFAImpl.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/ab1/impl/gruppe10_aigensberger_dworski_walcher/NFAImpl.java" afterDir="false" /> <change beforePath="$PROJECT_DIR$/src/main/java/ab1/impl/gruppe10_aigensberger_dworski_walcher/NFAImpl.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/ab1/impl/gruppe10_aigensberger_dworski_walcher/NFAImpl.java" afterDir="false" />
</list> </list>
<list id="39d4ccb3-eae9-4ed4-996a-5a13f44678fa" name="Changes by carol" comment="" /> <list id="39d4ccb3-eae9-4ed4-996a-5a13f44678fa" name="Changes by carol" comment="" />
@ -55,33 +56,33 @@
<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"><![CDATA[{ <component name="PropertiesComponent">{
"keyToString": { &quot;keyToString&quot;: {
"JUnit.ComplexTests.executor": "Run", &quot;JUnit.ComplexTests.executor&quot;: &quot;Run&quot;,
"JUnit.ComplexTests.finite1Test.executor": "Run", &quot;JUnit.ComplexTests.finite1Test.executor&quot;: &quot;Run&quot;,
"JUnit.ComplexTests.finite2Test.executor": "Debug", &quot;JUnit.ComplexTests.finite2Test.executor&quot;: &quot;Debug&quot;,
"JUnit.ComplexTests.intersection1Test.executor": "Run", &quot;JUnit.ComplexTests.intersection1Test.executor&quot;: &quot;Run&quot;,
"JUnit.ComplexTests.intersection2Test.executor": "Run", &quot;JUnit.ComplexTests.intersection2Test.executor&quot;: &quot;Run&quot;,
"JUnit.myTests.intersection1Test.executor": "Run", &quot;JUnit.myTests.intersection1Test.executor&quot;: &quot;Run&quot;,
"RunOnceActivity.OpenProjectViewOnStart": "true", &quot;RunOnceActivity.OpenProjectViewOnStart&quot;: &quot;true&quot;,
"RunOnceActivity.ShowReadmeOnStart": "true", &quot;RunOnceActivity.ShowReadmeOnStart&quot;: &quot;true&quot;,
"SHARE_PROJECT_CONFIGURATION_FILES": "true", &quot;SHARE_PROJECT_CONFIGURATION_FILES&quot;: &quot;true&quot;,
"WebServerToolWindowFactoryState": "false", &quot;WebServerToolWindowFactoryState&quot;: &quot;false&quot;,
"full.screen.before.presentation.mode": "false", &quot;full.screen.before.presentation.mode&quot;: &quot;false&quot;,
"git-widget-placeholder": "main", &quot;git-widget-placeholder&quot;: &quot;main&quot;,
"ignore.virus.scanning.warn.message": "true", &quot;ignore.virus.scanning.warn.message&quot;: &quot;true&quot;,
"node.js.detected.package.eslint": "true", &quot;node.js.detected.package.eslint&quot;: &quot;true&quot;,
"node.js.detected.package.tslint": "true", &quot;node.js.detected.package.tslint&quot;: &quot;true&quot;,
"node.js.selected.package.eslint": "(autodetect)", &quot;node.js.selected.package.eslint&quot;: &quot;(autodetect)&quot;,
"node.js.selected.package.tslint": "(autodetect)", &quot;node.js.selected.package.tslint&quot;: &quot;(autodetect)&quot;,
"nodejs_package_manager_path": "npm", &quot;nodejs_package_manager_path&quot;: &quot;npm&quot;,
"project.structure.last.edited": "Project", &quot;project.structure.last.edited&quot;: &quot;Project&quot;,
"project.structure.proportion": "0.0", &quot;project.structure.proportion&quot;: &quot;0.0&quot;,
"project.structure.side.proportion": "0.0", &quot;project.structure.side.proportion&quot;: &quot;0.0&quot;,
"settings.editor.selected.configurable": "preferences.lookFeel", &quot;settings.editor.selected.configurable&quot;: &quot;preferences.lookFeel&quot;,
"vue.rearranger.settings.migration": "true" &quot;vue.rearranger.settings.migration&quot;: &quot;true&quot;
} }
}]]></component> }</component>
<component name="RunManager" selected="JUnit.tests in ETI_Abgabe"> <component name="RunManager" selected="JUnit.tests in ETI_Abgabe">
<configuration name="ComplexTests" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true"> <configuration name="ComplexTests" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
<module name="ETI_Abgabe" /> <module name="ETI_Abgabe" />
@ -326,7 +327,8 @@
<MESSAGE value="isFinite methode recursiv..." /> <MESSAGE value="isFinite methode recursiv..." />
<MESSAGE value="." /> <MESSAGE value="." />
<MESSAGE value="documentation. cleanup. your turn daniel" /> <MESSAGE value="documentation. cleanup. your turn daniel" />
<option name="LAST_COMMIT_MESSAGE" value="documentation. cleanup. your turn daniel" /> <MESSAGE value=".equals replaced with ==" />
<option name="LAST_COMMIT_MESSAGE" value=".equals replaced with ==" />
</component> </component>
<component name="XDebuggerManager"> <component name="XDebuggerManager">
<breakpoint-manager> <breakpoint-manager>

View file

@ -405,10 +405,9 @@ public class NFAImpl implements NFA {
*/ */
@Override @Override
public boolean isFinite() { public boolean isFinite() {
List<Tuple> path = new ArrayList<>(); List<Tuple> path = new ArrayList<>();
List<Transition> transitions= new ArrayList<>(this.getTransitions()); List<Transition> transitions= new ArrayList<>(this.getTransitions());
AtomicInteger finished = new AtomicInteger(0); AtomicInteger finished = new AtomicInteger(0); // saves result over function calls
List<Character> letters = new ArrayList<>(this.alphabet); List<Character> letters = new ArrayList<>(this.alphabet);
if(this.alphabet.isEmpty()){ if(this.alphabet.isEmpty()){
return true; return true;
@ -416,8 +415,7 @@ public class NFAImpl implements NFA {
if(!letters.contains(null)) { if(!letters.contains(null)) {
letters.add(null); letters.add(null);
} }
path.add(new Tuple('a', this.initialState)); //'a' is just a dummy value
path.add(new Tuple('a', this.initialState));
if(fillToEnd(path, transitions, letters, finished)){ if(fillToEnd(path, transitions, letters, finished)){
return false; return false;
} }
@ -433,9 +431,17 @@ public class NFAImpl implements NFA {
return true; 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<Tuple> path, List<Transition> transitions, List<Character> letters, AtomicInteger finished) { private void continueOnLastTuple(List<Tuple> path, List<Transition> transitions, List<Character> letters, AtomicInteger finished) {
// path is already filled to end -> check next available state for the transition. // trivial case
// case we reached the limit (last state)
if(path.size()==1){ if(path.size()==1){
finished.set(1); finished.set(1);
return; return;
@ -447,10 +453,8 @@ public class NFAImpl implements NFA {
if(transitions.get(i).fromState().equals(fromState) && transitions.get(i).readSymbol()==(readSymbol)){ if(transitions.get(i).fromState().equals(fromState) && transitions.get(i).readSymbol()==(readSymbol)){
String newState = transitions.get(i).toState(); String newState = transitions.get(i).toState();
if (stateInPath(path, newState)) { if (stateInPath(path, newState)) {
//loop! //loop found
//loop ends in acceptingstate?
if(stateReachesAcceptingstates(newState)) { if(stateReachesAcceptingstates(newState)) {
//true:
finished.set(2); finished.set(2);
return; return;
} }
@ -460,7 +464,7 @@ public class NFAImpl implements NFA {
if(fillToEnd(path, transitions, letters, finished)){ if(fillToEnd(path, transitions, letters, finished)){
return; return;
} }
return;// continueOnLastTuple(path, transitions, letters); return;
} }
} }
} }
@ -468,19 +472,14 @@ public class NFAImpl implements NFA {
for(int i=letters.indexOf(readSymbol)+1;i<letters.size();i++){ for(int i=letters.indexOf(readSymbol)+1;i<letters.size();i++){
Character newLetter = letters.get(i); Character newLetter = letters.get(i);
String newState = checkForNewLetter(path, transitions, newLetter); String newState = checkForNewLetter(path, transitions, newLetter);
//more than 1 transition for new letter?
if(newState!=null){ if(newState!=null){
//check given state
if(stateInPath(path, newState)){ if(stateInPath(path, newState)){
//loop! //loop found
//loop ends in acceptingstate?
if(stateReachesAcceptingstates(newState)) { if(stateReachesAcceptingstates(newState)) {
//true:
finished.set(2); finished.set(2);
return; return;
} }
//else: // else: save !duplicate! and return:
// save !duplicate! and return:
path.add(new Tuple(newLetter, newState)); path.add(new Tuple(newLetter, newState));
return; return;
}else { }else {
@ -489,22 +488,19 @@ public class NFAImpl implements NFA {
if(fillToEnd(path, transitions, letters, finished)){ if(fillToEnd(path, transitions, letters, finished)){
return; return;
} }
return;// continueOnLastTuple(path, transitions, letters); return;
} }
} }
//else go to next letter
} }
//no letter left //no letter left -> remove last Tuple and return
//remove last Tuple
path.remove(path.size()-1); path.remove(path.size()-1);
//goto next thingy
//return;// continueOnLastTuple(path, transitions, letters);
} }
/** /**
* !Does not check the new state added * Checks for the second last state in path, weather it has a Transition with the given letter or not
* @return -state if a tostate for the newletter is found and deletes the old Tuple * !Does not check the state, which is returned!
* -null if with the newletter there is no transition further * @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<Tuple> path, List<Transition> transitions, Character letter){ private String checkForNewLetter(List<Tuple> path, List<Transition> transitions, Character letter){
String fromState = path.get(path.size()-2).getElement_2(); 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 * Fills in the first possible path for the last element and checks
* after method need to * 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 * @return true if a valid loop has been found while filling it up
* false if everything worked fine
*/ */
private boolean fillToEnd(List<Tuple> path, List<Transition> transitions, List<Character> letters, AtomicInteger finished){ private boolean fillToEnd(List<Tuple> path, List<Transition> transitions, List<Character> letters, AtomicInteger finished){
String fromState = path.get(path.size()-1).getElement_2(); 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)){ if(transition.fromState().equals(fromState)&&transition.readSymbol()==(letter)){
//found new Transition //found new Transition
if(stateInPath(path, transition.toState())) { if(stateInPath(path, transition.toState())) {
//loop! //loop found
//loop reaches a acceptingstate? then return true, else delete some shit
if(stateReachesAcceptingstates(transition.toState())) { if(stateReachesAcceptingstates(transition.toState())) {
//true:
finished.set(2); finished.set(2);
return true; return true;
} }
//else do nothing and take next transition if possible //else go to next Transition
} else { } else {
path.add(new Tuple(letter, transition.toState())); path.add(new Tuple(letter, transition.toState()));
//recursion until the state has no valid Transition
return fillToEnd(path, transitions, letters, finished); 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; 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<Tuple> path, String state){ private boolean stateInPath(List<Tuple> path, String state){
for(Tuple tuple : path){ for(Tuple tuple : path){
if(tuple.getElement_2().equals(state)){ if(tuple.getElement_2().equals(state)){
@ -560,6 +561,12 @@ public class NFAImpl implements NFA {
return false; 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){ private boolean stateReachesAcceptingstates(String state){
if(this.acceptingStates.contains(state)){ if(this.acceptingStates.contains(state)){
return true; return true;
@ -567,7 +574,7 @@ public class NFAImpl implements NFA {
Set<String> currentStates = new HashSet<>(); Set<String> currentStates = new HashSet<>();
Set<String> newStates = new HashSet<>(); Set<String> newStates = new HashSet<>();
currentStates.add(state); currentStates.add(state);
boolean containsNewStates; boolean containsNewStates; //weather all reachable states have been found
do{ do{
containsNewStates = false; containsNewStates = false;
for(String currentstate : currentStates){ for(String currentstate : currentStates){
@ -616,7 +623,6 @@ public class NFAImpl implements NFA {
return isAcceptingState(currentStates, this); return isAcceptingState(currentStates, this);
} }
/** /**
* Converts the given NFA to a DFA. If the NFA is not finalized, a FinalizedStateException is thrown. * Converts the given NFA to a DFA. If the NFA is not finalized, a FinalizedStateException is thrown.
* @param input The NFA to convert * @param input The NFA to convert