isFinite methode recursiv...
This commit is contained in:
parent
f0207de511
commit
2e466eea83
3 changed files with 184 additions and 20 deletions
35
.idea/workspace.xml
generated
35
.idea/workspace.xml
generated
|
|
@ -4,15 +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="concat GEHT">
|
<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) -> intersectionTests funktionieren">
|
||||||
<change afterPath="$PROJECT_DIR$/src/test/java/ab1/tests/myTests.java" afterDir="false" />
|
<change afterPath="$PROJECT_DIR$/src/main/java/ab1/impl/GRUPPE/Tuple.java" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/.idea/jarRepositories.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/jarRepositories.xml" afterDir="false" />
|
|
||||||
<change beforePath="$PROJECT_DIR$/.idea/misc.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/misc.xml" 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$/target/classes/ab1/Transition$TransitionBuilder.class" beforeDir="false" afterPath="$PROJECT_DIR$/target/classes/ab1/Transition$TransitionBuilder.class" afterDir="false" />
|
|
||||||
<change beforePath="$PROJECT_DIR$/target/classes/ab1/Transition.class" beforeDir="false" afterPath="$PROJECT_DIR$/target/classes/ab1/Transition.class" afterDir="false" />
|
|
||||||
<change beforePath="$PROJECT_DIR$/target/test-classes/ab1/tests/FinalizeTests.class" beforeDir="false" afterPath="$PROJECT_DIR$/target/test-classes/ab1/tests/FinalizeTests.class" 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" />
|
||||||
|
|
@ -66,7 +61,8 @@
|
||||||
"keyToString": {
|
"keyToString": {
|
||||||
"JUnit.ComplexTests.executor": "Run",
|
"JUnit.ComplexTests.executor": "Run",
|
||||||
"JUnit.ComplexTests.intersection1Test.executor": "Run",
|
"JUnit.ComplexTests.intersection1Test.executor": "Run",
|
||||||
"JUnit.myTests.intersection1Test.executor": "Debug",
|
"JUnit.ComplexTests.intersection2Test.executor": "Run",
|
||||||
|
"JUnit.myTests.intersection1Test.executor": "Run",
|
||||||
"RunOnceActivity.OpenProjectViewOnStart": "true",
|
"RunOnceActivity.OpenProjectViewOnStart": "true",
|
||||||
"RunOnceActivity.ShowReadmeOnStart": "true",
|
"RunOnceActivity.ShowReadmeOnStart": "true",
|
||||||
"WebServerToolWindowFactoryState": "false",
|
"WebServerToolWindowFactoryState": "false",
|
||||||
|
|
@ -254,7 +250,15 @@
|
||||||
<option name="project" value="LOCAL" />
|
<option name="project" value="LOCAL" />
|
||||||
<updated>1704752420737</updated>
|
<updated>1704752420737</updated>
|
||||||
</task>
|
</task>
|
||||||
<option name="localTasksCounter" value="8" />
|
<task id="LOCAL-00008" summary="changed nfaAddTrap, bei dem Fall, dass Transition.readSymbol() einen nullwert zurückgibt. (Thx ChatGBT) -> intersectionTests funktionieren">
|
||||||
|
<option name="closed" value="true" />
|
||||||
|
<created>1704819635241</created>
|
||||||
|
<option name="number" value="00008" />
|
||||||
|
<option name="presentableId" value="LOCAL-00008" />
|
||||||
|
<option name="project" value="LOCAL" />
|
||||||
|
<updated>1704819635241</updated>
|
||||||
|
</task>
|
||||||
|
<option name="localTasksCounter" value="9" />
|
||||||
<servers />
|
<servers />
|
||||||
</component>
|
</component>
|
||||||
<component name="TypeScriptGeneratedFilesManager">
|
<component name="TypeScriptGeneratedFilesManager">
|
||||||
|
|
@ -277,16 +281,12 @@
|
||||||
<MESSAGE value="Changes by danie" />
|
<MESSAGE value="Changes by danie" />
|
||||||
<MESSAGE value="fucking hell" />
|
<MESSAGE value="fucking hell" />
|
||||||
<MESSAGE value="concat GEHT" />
|
<MESSAGE value="concat GEHT" />
|
||||||
<option name="LAST_COMMIT_MESSAGE" value="concat GEHT" />
|
<MESSAGE value="changed nfaAddTrap, bei dem Fall, dass Transition.readSymbol() einen nullwert zurückgibt. (Thx ChatGBT) -> intersectionTests funktionieren" />
|
||||||
|
<option name="LAST_COMMIT_MESSAGE" value="changed nfaAddTrap, bei dem Fall, dass Transition.readSymbol() einen nullwert zurückgibt. (Thx ChatGBT) -> intersectionTests funktionieren" />
|
||||||
</component>
|
</component>
|
||||||
<component name="XDebuggerManager">
|
<component name="XDebuggerManager">
|
||||||
<breakpoint-manager>
|
<breakpoint-manager>
|
||||||
<breakpoints>
|
<breakpoints>
|
||||||
<line-breakpoint enabled="true" type="java-line">
|
|
||||||
<url>file://$PROJECT_DIR$/src/main/java/ab1/impl/GRUPPE/NFAImpl.java</url>
|
|
||||||
<line>211</line>
|
|
||||||
<option name="timeStamp" value="43" />
|
|
||||||
</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>343</line>
|
<line>343</line>
|
||||||
|
|
@ -297,11 +297,6 @@
|
||||||
<line>355</line>
|
<line>355</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/main/java/ab1/impl/GRUPPE/NFAImpl.java</url>
|
|
||||||
<line>523</line>
|
|
||||||
<option name="timeStamp" value="55" />
|
|
||||||
</line-breakpoint>
|
|
||||||
</breakpoints>
|
</breakpoints>
|
||||||
</breakpoint-manager>
|
</breakpoint-manager>
|
||||||
<watches-manager>
|
<watches-manager>
|
||||||
|
|
|
||||||
|
|
@ -379,6 +379,135 @@ public class NFAImpl implements NFA {
|
||||||
//transitions={fromState==toState}
|
//transitions={fromState==toState}
|
||||||
//states={A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z}
|
//states={A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z}
|
||||||
//obergrenze = anzahl der states (26)
|
//obergrenze = anzahl der states (26)
|
||||||
|
|
||||||
|
//how do we get an infinite language?
|
||||||
|
//we need to have a loop, how can we check:
|
||||||
|
|
||||||
|
List<Tuple> path = new ArrayList<>();
|
||||||
|
List<Transition> transitions= new ArrayList<>(this.getTransitions());
|
||||||
|
//int finished = 0; //0=unfinished, 1=finite, 2 = infinite
|
||||||
|
List<Character> letters = new ArrayList<>(this.alphabet); // letters is alphabet with epsilon (null)
|
||||||
|
if(!letters.contains(null)) {
|
||||||
|
letters.add(null);
|
||||||
|
}
|
||||||
|
if(this.alphabet.isEmpty()){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
// EndTuple hast firstElement = a
|
||||||
|
path.add(new Tuple('a', this.initialState, true));
|
||||||
|
if(fillToEnd(path, transitions, letters)){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
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.
|
||||||
|
// case we reached the limit (last state)
|
||||||
|
if(path.size()==1){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
String fromState = path.get(path.size()-2).getElement_2();
|
||||||
|
Character readSymbol = path.get(path.size()-1).getElement_1();
|
||||||
|
Transition currentTransition = new Transition(fromState, readSymbol, path.get(path.size()-1).getElement_2());
|
||||||
|
for(int i=transitions.indexOf(currentTransition);i<transitions.size();i++){
|
||||||
|
if(transitions.get(i).fromState().equals(fromState) && transitions.get(i).readSymbol().equals(readSymbol)){
|
||||||
|
String newState = transitions.get(i).toState();
|
||||||
|
if (stateInPath(path, newState)) {
|
||||||
|
//loop!
|
||||||
|
//loop ends in acceptingstate?
|
||||||
|
} else {
|
||||||
|
path.remove(path.size()-1);
|
||||||
|
path. add(new Tuple(readSymbol, newState));
|
||||||
|
if(fillToEnd(path, transitions, letters)){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return continueOnLastTuple(path, transitions, letters);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// need newLetter
|
||||||
|
for(int i=letters.indexOf(readSymbol)+1;i<letters.size();i++){
|
||||||
|
Character newLetter = letters.get(i);
|
||||||
|
String newState = checkForNewLetter(path, transitions, letters, newLetter);
|
||||||
|
if(newState!=null){
|
||||||
|
//check given state
|
||||||
|
if(stateInPath(path, newState)){
|
||||||
|
//loop!
|
||||||
|
//loop ends in acceptingstate?
|
||||||
|
}else {
|
||||||
|
//deletion already in checkForNewLetter.
|
||||||
|
path.add(new Tuple(newLetter, newState));
|
||||||
|
if(fillToEnd(path, transitions, letters)){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return continueOnLastTuple(path, transitions, letters);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//else go to next letter
|
||||||
|
}
|
||||||
|
//no letter left
|
||||||
|
//remove last Tuple
|
||||||
|
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
|
||||||
|
* @return null if with the newletter there is no transition further
|
||||||
|
*/
|
||||||
|
private String checkForNewLetter(List<Tuple> path, List<Transition> transitions, List<Character> letters, Character letter){
|
||||||
|
String fromState = path.get(path.size()-2).getElement_2();
|
||||||
|
for(Transition transition : transitions){
|
||||||
|
if (transition.fromState().equals(fromState) && transition.readSymbol().equals(letter)) {
|
||||||
|
//found new Transition
|
||||||
|
path.remove(path.size()-1);
|
||||||
|
return transition.toState();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* call method, if the last Element of path is ok
|
||||||
|
* after method need to
|
||||||
|
* @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){
|
||||||
|
String fromState = path.get(path.size()-1).getElement_2();
|
||||||
|
for(Character letter : letters) {
|
||||||
|
for (Transition transition : transitions) {
|
||||||
|
if(transition.fromState().equals(fromState)&&transition.readSymbol().equals(letter)){
|
||||||
|
//found new Transition
|
||||||
|
if(stateInPath(path, transition.toState())) {
|
||||||
|
//loop!
|
||||||
|
//loop reaches a acceptingstate? then return true, else delete some shit
|
||||||
|
} else {
|
||||||
|
path.add(new Tuple(letter, transition.toState()));
|
||||||
|
return fillToEnd(path, transitions, letters);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//from the last State in path there is no further Transition (dead end = job done)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean stateInPath(List<Tuple> path, String state){
|
||||||
|
for(Tuple tuple : path){
|
||||||
|
if(tuple.getElement_2().equals(state)){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
40
src/main/java/ab1/impl/GRUPPE/Tuple.java
Normal file
40
src/main/java/ab1/impl/GRUPPE/Tuple.java
Normal file
|
|
@ -0,0 +1,40 @@
|
||||||
|
package ab1.impl.GRUPPE;
|
||||||
|
|
||||||
|
public class Tuple {
|
||||||
|
private Character element_1;
|
||||||
|
|
||||||
|
public Character getElement_1() {
|
||||||
|
return element_1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setElement_1(Character element_1) {
|
||||||
|
this.element_1 = element_1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getElement_2() {
|
||||||
|
return element_2;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setElement_2(String element_2) {
|
||||||
|
this.element_2 = element_2;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String element_2;
|
||||||
|
|
||||||
|
public boolean isEnd() {
|
||||||
|
return isEnd;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isEnd;
|
||||||
|
public Tuple(Character firstElement, String secondElement){
|
||||||
|
this.element_1=firstElement;
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in a new issue