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" />
</component>
<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" />
</list>
<list id="39d4ccb3-eae9-4ed4-996a-5a13f44678fa" name="Changes by carol" comment="" />
@ -55,33 +56,33 @@
<option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" />
</component>
<component name="PropertiesComponent"><![CDATA[{
"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"
<component name="PropertiesComponent">{
&quot;keyToString&quot;: {
&quot;JUnit.ComplexTests.executor&quot;: &quot;Run&quot;,
&quot;JUnit.ComplexTests.finite1Test.executor&quot;: &quot;Run&quot;,
&quot;JUnit.ComplexTests.finite2Test.executor&quot;: &quot;Debug&quot;,
&quot;JUnit.ComplexTests.intersection1Test.executor&quot;: &quot;Run&quot;,
&quot;JUnit.ComplexTests.intersection2Test.executor&quot;: &quot;Run&quot;,
&quot;JUnit.myTests.intersection1Test.executor&quot;: &quot;Run&quot;,
&quot;RunOnceActivity.OpenProjectViewOnStart&quot;: &quot;true&quot;,
&quot;RunOnceActivity.ShowReadmeOnStart&quot;: &quot;true&quot;,
&quot;SHARE_PROJECT_CONFIGURATION_FILES&quot;: &quot;true&quot;,
&quot;WebServerToolWindowFactoryState&quot;: &quot;false&quot;,
&quot;full.screen.before.presentation.mode&quot;: &quot;false&quot;,
&quot;git-widget-placeholder&quot;: &quot;main&quot;,
&quot;ignore.virus.scanning.warn.message&quot;: &quot;true&quot;,
&quot;node.js.detected.package.eslint&quot;: &quot;true&quot;,
&quot;node.js.detected.package.tslint&quot;: &quot;true&quot;,
&quot;node.js.selected.package.eslint&quot;: &quot;(autodetect)&quot;,
&quot;node.js.selected.package.tslint&quot;: &quot;(autodetect)&quot;,
&quot;nodejs_package_manager_path&quot;: &quot;npm&quot;,
&quot;project.structure.last.edited&quot;: &quot;Project&quot;,
&quot;project.structure.proportion&quot;: &quot;0.0&quot;,
&quot;project.structure.side.proportion&quot;: &quot;0.0&quot;,
&quot;settings.editor.selected.configurable&quot;: &quot;preferences.lookFeel&quot;,
&quot;vue.rearranger.settings.migration&quot;: &quot;true&quot;
}
}]]></component>
}</component>
<component name="RunManager" selected="JUnit.tests in ETI_Abgabe">
<configuration name="ComplexTests" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
<module name="ETI_Abgabe" />
@ -326,7 +327,8 @@
<MESSAGE value="isFinite methode recursiv..." />
<MESSAGE value="." />
<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 name="XDebuggerManager">
<breakpoint-manager>

View file

@ -405,10 +405,9 @@ public class NFAImpl implements NFA {
*/
@Override
public boolean isFinite() {
List<Tuple> path = new ArrayList<>();
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);
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<Tuple> path, List<Transition> transitions, List<Character> 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<letters.size();i++){
Character newLetter = letters.get(i);
String newState = checkForNewLetter(path, transitions, newLetter);
//more than 1 transition for new letter?
if(newState!=null){
//check given state
if(stateInPath(path, newState)){
//loop!
//loop ends in acceptingstate?
//loop found
if(stateReachesAcceptingstates(newState)) {
//true:
finished.set(2);
return;
}
//else:
// save !duplicate! and return:
// else: save !duplicate! and return:
path.add(new Tuple(newLetter, newState));
return;
}else {
@ -489,22 +488,19 @@ public class NFAImpl implements NFA {
if(fillToEnd(path, transitions, letters, finished)){
return;
}
return;// continueOnLastTuple(path, transitions, letters);
return;
}
}
//else go to next letter
}
//no letter left
//remove last Tuple
//no letter left -> 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<Tuple> path, List<Transition> 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<Tuple> path, List<Transition> transitions, List<Character> 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<Tuple> 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<String> currentStates = new HashSet<>();
Set<String> 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