guess what works now, fker:)

This commit is contained in:
Ghost_Element 2024-01-10 15:27:21 +01:00
parent 2e466eea83
commit b6ab5bdf72
3 changed files with 141 additions and 68 deletions

89
.idea/workspace.xml generated
View file

@ -4,10 +4,10 @@
<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="changed nfaAddTrap, bei dem Fall, dass Transition.readSymbol() einen nullwert zurückgibt. (Thx ChatGBT)&#10;-&gt; intersectionTests funktionieren"> <list default="true" id="f5e08808-a5af-4c89-a1ee-21b3bcb9ae3e" name="Changes" comment="isFinite methode recursiv...">
<change afterPath="$PROJECT_DIR$/src/main/java/ab1/impl/GRUPPE/Tuple.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" /> <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/GRUPPE/NFAImpl.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/ab1/impl/GRUPPE/NFAImpl.java" afterDir="false" /> <change beforePath="$PROJECT_DIR$/src/main/java/ab1/impl/GRUPPE/NFAImpl.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/ab1/impl/GRUPPE/NFAImpl.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/ab1/impl/GRUPPE/Tuple.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/ab1/impl/GRUPPE/Tuple.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="" />
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
@ -60,6 +60,8 @@
<component name="PropertiesComponent"><![CDATA[{ <component name="PropertiesComponent"><![CDATA[{
"keyToString": { "keyToString": {
"JUnit.ComplexTests.executor": "Run", "JUnit.ComplexTests.executor": "Run",
"JUnit.ComplexTests.finite1Test.executor": "Run",
"JUnit.ComplexTests.finite2Test.executor": "Debug",
"JUnit.ComplexTests.intersection1Test.executor": "Run", "JUnit.ComplexTests.intersection1Test.executor": "Run",
"JUnit.ComplexTests.intersection2Test.executor": "Run", "JUnit.ComplexTests.intersection2Test.executor": "Run",
"JUnit.myTests.intersection1Test.executor": "Run", "JUnit.myTests.intersection1Test.executor": "Run",
@ -97,6 +99,38 @@
<option name="Make" enabled="true" /> <option name="Make" enabled="true" />
</method> </method>
</configuration> </configuration>
<configuration name="ComplexTests.finite1Test" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
<module name="ETI_Abgabe" />
<extension name="coverage">
<pattern>
<option name="PATTERN" value="ab1.tests.*" />
<option name="ENABLED" value="true" />
</pattern>
</extension>
<option name="PACKAGE_NAME" value="ab1.tests" />
<option name="MAIN_CLASS_NAME" value="ab1.tests.ComplexTests" />
<option name="METHOD_NAME" value="finite1Test" />
<option name="TEST_OBJECT" value="method" />
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
<configuration name="ComplexTests.finite2Test" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
<module name="ETI_Abgabe" />
<extension name="coverage">
<pattern>
<option name="PATTERN" value="ab1.tests.*" />
<option name="ENABLED" value="true" />
</pattern>
</extension>
<option name="PACKAGE_NAME" value="ab1.tests" />
<option name="MAIN_CLASS_NAME" value="ab1.tests.ComplexTests" />
<option name="METHOD_NAME" value="finite2Test" />
<option name="TEST_OBJECT" value="method" />
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
<configuration name="ComplexTests.intersection1Test" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true"> <configuration name="ComplexTests.intersection1Test" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
<module name="ETI_Abgabe" /> <module name="ETI_Abgabe" />
<extension name="coverage"> <extension name="coverage">
@ -129,30 +163,6 @@
<option name="Make" enabled="true" /> <option name="Make" enabled="true" />
</method> </method>
</configuration> </configuration>
<configuration name="ab1 in ETI_Abgabe" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
<module name="ETI_Abgabe" />
<option name="TEST_OBJECT" value="directory" />
<dir value="$PROJECT_DIR$/src/test/java/ab1" />
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
<configuration name="myTests.intersection1Test" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
<module name="ETI_Abgabe" />
<extension name="coverage">
<pattern>
<option name="PATTERN" value="ab1.tests.*" />
<option name="ENABLED" value="true" />
</pattern>
</extension>
<option name="PACKAGE_NAME" value="ab1.tests" />
<option name="MAIN_CLASS_NAME" value="ab1.tests.myTests" />
<option name="METHOD_NAME" value="intersection1Test" />
<option name="TEST_OBJECT" value="method" />
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
<configuration default="true" type="JetRunConfigurationType"> <configuration default="true" type="JetRunConfigurationType">
<method v="2"> <method v="2">
<option name="Make" enabled="true" /> <option name="Make" enabled="true" />
@ -167,10 +177,10 @@
<recent_temporary> <recent_temporary>
<list> <list>
<item itemvalue="JUnit.ComplexTests" /> <item itemvalue="JUnit.ComplexTests" />
<item itemvalue="JUnit.ComplexTests.finite2Test" />
<item itemvalue="JUnit.ComplexTests.finite1Test" />
<item itemvalue="JUnit.ComplexTests.intersection2Test" /> <item itemvalue="JUnit.ComplexTests.intersection2Test" />
<item itemvalue="JUnit.ComplexTests.intersection1Test" /> <item itemvalue="JUnit.ComplexTests.intersection1Test" />
<item itemvalue="JUnit.myTests.intersection1Test" />
<item itemvalue="JUnit.ab1 in ETI_Abgabe" />
</list> </list>
</recent_temporary> </recent_temporary>
</component> </component>
@ -258,7 +268,15 @@
<option name="project" value="LOCAL" /> <option name="project" value="LOCAL" />
<updated>1704819635241</updated> <updated>1704819635241</updated>
</task> </task>
<option name="localTasksCounter" value="9" /> <task id="LOCAL-00009" summary="isFinite methode recursiv...">
<option name="closed" value="true" />
<created>1704888180654</created>
<option name="number" value="00009" />
<option name="presentableId" value="LOCAL-00009" />
<option name="project" value="LOCAL" />
<updated>1704888180655</updated>
</task>
<option name="localTasksCounter" value="10" />
<servers /> <servers />
</component> </component>
<component name="TypeScriptGeneratedFilesManager"> <component name="TypeScriptGeneratedFilesManager">
@ -282,21 +300,27 @@
<MESSAGE value="fucking hell" /> <MESSAGE value="fucking hell" />
<MESSAGE value="concat GEHT" /> <MESSAGE value="concat GEHT" />
<MESSAGE value="changed nfaAddTrap, bei dem Fall, dass Transition.readSymbol() einen nullwert zurückgibt. (Thx ChatGBT)&#10;-&gt; intersectionTests funktionieren" /> <MESSAGE value="changed nfaAddTrap, bei dem Fall, dass Transition.readSymbol() einen nullwert zurückgibt. (Thx ChatGBT)&#10;-&gt; intersectionTests funktionieren" />
<option name="LAST_COMMIT_MESSAGE" value="changed nfaAddTrap, bei dem Fall, dass Transition.readSymbol() einen nullwert zurückgibt. (Thx ChatGBT)&#10;-&gt; intersectionTests funktionieren" /> <MESSAGE value="isFinite methode recursiv..." />
<option name="LAST_COMMIT_MESSAGE" value="isFinite methode recursiv..." />
</component> </component>
<component name="XDebuggerManager"> <component name="XDebuggerManager">
<breakpoint-manager> <breakpoint-manager>
<breakpoints> <breakpoints>
<line-breakpoint enabled="true" type="java-line"> <line-breakpoint enabled="true" type="java-line">
<url>file://$PROJECT_DIR$/src/main/java/ab1/impl/GRUPPE/NFAImpl.java</url> <url>file://$PROJECT_DIR$/src/main/java/ab1/impl/GRUPPE/NFAImpl.java</url>
<line>343</line> <line>344</line>
<option name="timeStamp" value="44" /> <option name="timeStamp" value="44" />
</line-breakpoint> </line-breakpoint>
<line-breakpoint enabled="true" type="java-line"> <line-breakpoint enabled="true" type="java-line">
<url>file://$PROJECT_DIR$/src/main/java/ab1/impl/GRUPPE/NFAImpl.java</url> <url>file://$PROJECT_DIR$/src/main/java/ab1/impl/GRUPPE/NFAImpl.java</url>
<line>355</line> <line>356</line>
<option name="timeStamp" value="53" /> <option name="timeStamp" value="53" />
</line-breakpoint> </line-breakpoint>
<line-breakpoint enabled="true" type="java-line">
<url>file://$PROJECT_DIR$/src/test/java/ab1/tests/ComplexTests.java</url>
<line>141</line>
<option name="timeStamp" value="59" />
</line-breakpoint>
</breakpoints> </breakpoints>
</breakpoint-manager> </breakpoint-manager>
<watches-manager> <watches-manager>
@ -304,6 +328,7 @@
<watch expression="((HashSet)((NFAImpl)testInstance).acceptingStates).toArray()[2]" custom="java.util.HashSet,ab1.impl.GRUPPE.NFAImpl" /> <watch expression="((HashSet)((NFAImpl)testInstance).acceptingStates).toArray()[2]" custom="java.util.HashSet,ab1.impl.GRUPPE.NFAImpl" />
<watch expression="transition.readSymbol()" /> <watch expression="transition.readSymbol()" />
<watch expression="transition.readSymbol()==letter" /> <watch expression="transition.readSymbol()==letter" />
<watch expression="transitions.get(i)" />
</configuration> </configuration>
</watches-manager> </watches-manager>
</component> </component>

View file

@ -5,6 +5,7 @@ import ab1.NFA;
import ab1.Transition; import ab1.Transition;
import java.util.*; import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
public class NFAImpl implements NFA { public class NFAImpl implements NFA {
private final Set<String> states; private final Set<String> states;
@ -385,49 +386,61 @@ public class NFAImpl implements NFA {
List<Tuple> path = new ArrayList<>(); List<Tuple> path = new ArrayList<>();
List<Transition> transitions= new ArrayList<>(this.getTransitions()); List<Transition> transitions= new ArrayList<>(this.getTransitions());
//int finished = 0; //0=unfinished, 1=finite, 2 = infinite AtomicInteger finished = new AtomicInteger(0); //0=unfinished, 1=finite, 2 = infinite
List<Character> letters = new ArrayList<>(this.alphabet); // letters is alphabet with epsilon (null) List<Character> letters = new ArrayList<>(this.alphabet); // letters is alphabet with epsilon (null)
if(!letters.contains(null)) {
letters.add(null);
}
if(this.alphabet.isEmpty()){ if(this.alphabet.isEmpty()){
return true; return true;
} }
// EndTuple hast firstElement = a if(!letters.contains(null)) {
path.add(new Tuple('a', this.initialState, true)); letters.add(null);
if(fillToEnd(path, transitions, letters)){ }
// EndTuple hast firstElement = a //doesn´t matter at all aktually
path.add(new Tuple('a', this.initialState));
if(fillToEnd(path, transitions, letters, finished)){
return false;
}
while(finished.intValue()==0){
continueOnLastTuple(path, transitions, letters, finished);
}
if (finished.intValue() == 1) {
return true; return true;
} else if (finished.intValue() == 2) {
return false;
}
System.out.println("ERROR-isFinite method isn´t running right!");
return true;
//return continueOnLastTuple(path, transitions, letters);
} }
private void continueOnLastTuple(List<Tuple> path, List<Transition> transitions, List<Character> letters, AtomicInteger finished) {
return continueOnLastTuple(path, transitions, letters);
}
private boolean continueOnLastTuple(List<Tuple> path, List<Transition> transitions, List<Character> letters) {
// path is already filled to end -> check next available state for the transition. // path is already filled to end -> check next available state for the transition.
// case we reached the limit (last state) // case we reached the limit (last state)
if(path.size()==1){ if(path.size()==1){
return false; finished.set(1);
return;
} }
String fromState = path.get(path.size()-2).getElement_2(); String fromState = path.get(path.size()-2).getElement_2();
Character readSymbol = path.get(path.size()-1).getElement_1(); Character readSymbol = path.get(path.size()-1).getElement_1();
Transition currentTransition = new Transition(fromState, readSymbol, path.get(path.size()-1).getElement_2()); Transition currentTransition = new Transition(fromState, readSymbol, path.get(path.size()-1).getElement_2());
for(int i=transitions.indexOf(currentTransition);i<transitions.size();i++){ for(int i=transitions.indexOf(currentTransition)+1;i<transitions.size();i++){
if(transitions.get(i).fromState().equals(fromState) && transitions.get(i).readSymbol().equals(readSymbol)){ if(transitions.get(i).fromState().equals(fromState) && transitions.get(i).readSymbol().equals(readSymbol)){
String newState = transitions.get(i).toState(); String newState = transitions.get(i).toState();
if (stateInPath(path, newState)) { if (stateInPath(path, newState)) {
//loop! //loop!
//loop ends in acceptingstate? //loop ends in acceptingstate?
if(stateReachesAcceptingstates(newState)) {
//true:
finished.set(2);
return;
}
} else { } else {
path.remove(path.size()-1); path.remove(path.size()-1);
path. add(new Tuple(readSymbol, newState)); path. add(new Tuple(readSymbol, newState));
if(fillToEnd(path, transitions, letters)){ if(fillToEnd(path, transitions, letters, finished)){
return true; return;
} }
return continueOnLastTuple(path, transitions, letters); return;// continueOnLastTuple(path, transitions, letters);
} }
} }
} }
@ -435,18 +448,28 @@ 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, letters, newLetter); String newState = checkForNewLetter(path, transitions, letters, newLetter);
//more than 1 transition for new letter?
if(newState!=null){ if(newState!=null){
//check given state //check given state
if(stateInPath(path, newState)){ if(stateInPath(path, newState)){
//loop! //loop!
//loop ends in acceptingstate? //loop ends in acceptingstate?
if(stateReachesAcceptingstates(newState)) {
//true:
finished.set(2);
return;
}
//else:
// save !duplicate! and return:
path.add(new Tuple(newLetter, newState));
return;
}else { }else {
//deletion already in checkForNewLetter. //deletion already in checkForNewLetter.
path.add(new Tuple(newLetter, newState)); path.add(new Tuple(newLetter, newState));
if(fillToEnd(path, transitions, letters)){ if(fillToEnd(path, transitions, letters, finished)){
return true; return;
} }
return continueOnLastTuple(path, transitions, letters); return;// continueOnLastTuple(path, transitions, letters);
} }
} }
//else go to next letter //else go to next letter
@ -455,7 +478,7 @@ public class NFAImpl implements NFA {
//remove last Tuple //remove last Tuple
path.remove(path.size()-1); path.remove(path.size()-1);
//goto next thingy //goto next thingy
return continueOnLastTuple(path, transitions, letters); //return;// continueOnLastTuple(path, transitions, letters);
} }
/** /**
@ -481,7 +504,7 @@ public class NFAImpl implements NFA {
* after method need to * after method need to
* @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
*/ */
private boolean fillToEnd(List<Tuple> path, List<Transition> transitions, List<Character> letters){ 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();
for(Character letter : letters) { for(Character letter : letters) {
for (Transition transition : transitions) { for (Transition transition : transitions) {
@ -490,9 +513,15 @@ public class NFAImpl implements NFA {
if(stateInPath(path, transition.toState())) { if(stateInPath(path, transition.toState())) {
//loop! //loop!
//loop reaches a acceptingstate? then return true, else delete some shit //loop reaches a acceptingstate? then return true, else delete some shit
if(stateReachesAcceptingstates(transition.toState())) {
//true:
finished.set(2);
return true;
}
//else do nothing and take next transition if possible
} else { } else {
path.add(new Tuple(letter, transition.toState())); path.add(new Tuple(letter, transition.toState()));
return fillToEnd(path, transitions, letters); return fillToEnd(path, transitions, letters, finished);
} }
} }
} }
@ -510,6 +539,35 @@ public class NFAImpl implements NFA {
} }
return false; return false;
} }
private boolean stateReachesAcceptingstates(String state){
if(this.acceptingStates.contains(state)){
return true;
}
Set<String> currentStates = new HashSet<>();
Set<String> newStates = new HashSet<>();
currentStates.add(state);
boolean containsNewStates;
do{
containsNewStates = false;
for(String currentstate : currentStates){
for(Transition transition : this.transitions){
if(transition.fromState().equals(currentstate)){
newStates.add(transition.toState());
}
}
}
for(String newState : newStates){
if(this.acceptingStates.contains(newState)){
return true;
}
if(!currentStates.contains(newState)){
containsNewStates=true;
currentStates.add(newState);
}
}
}while(containsNewStates);
return false;
}
// #TODO // #TODO
@Override @Override

View file

@ -21,20 +21,10 @@ public class Tuple {
private String element_2; private String element_2;
public boolean isEnd() {
return isEnd;
}
private boolean isEnd;
public Tuple(Character firstElement, String secondElement){ public Tuple(Character firstElement, String secondElement){
this.element_1=firstElement; this.element_1=firstElement;
this.element_2=secondElement; this.element_2=secondElement;
this.isEnd = false;
} }
public Tuple(Character firstElement, String secondElement, boolean isend){
this.element_1=firstElement;
this.element_2=secondElement;
this.isEnd = isend;
}
} }