Implemented reverse function
This commit is contained in:
@@ -65,4 +65,24 @@ public class DFA<T extends Comparable> extends Automata<T> {
|
|||||||
}
|
}
|
||||||
return new Taal(addSymbols(n - 1, taal));
|
return new Taal(addSymbols(n - 1, taal));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public DFA<T> Reverse()
|
||||||
|
{
|
||||||
|
DFA<T> reversed = new DFA<T>(this.symbols);
|
||||||
|
|
||||||
|
for(Transition<T> t : transistions)
|
||||||
|
{
|
||||||
|
reversed.addTransition(new Transition<T>(t.naarState, t.symbol, t.vanState));
|
||||||
|
}
|
||||||
|
|
||||||
|
for(T state : eindStates) {
|
||||||
|
reversed.defineAsEndState(state);
|
||||||
|
}
|
||||||
|
|
||||||
|
for(T state : beginStates) {
|
||||||
|
reversed.defineAsStartState(state);
|
||||||
|
}
|
||||||
|
|
||||||
|
return reversed;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,6 +41,7 @@ public class Main {
|
|||||||
myAutomata.defineAsEndState("q7");
|
myAutomata.defineAsEndState("q7");
|
||||||
|
|
||||||
myAutomata.printTransitions();
|
myAutomata.printTransitions();
|
||||||
|
|
||||||
final long[] startTime = {System.currentTimeMillis()};
|
final long[] startTime = {System.currentTimeMillis()};
|
||||||
myAutomata.geefTaalTotLengte(10).getSymbols().forEach((s) -> {
|
myAutomata.geefTaalTotLengte(10).getSymbols().forEach((s) -> {
|
||||||
long before = System.currentTimeMillis();
|
long before = System.currentTimeMillis();
|
||||||
@@ -110,13 +111,35 @@ public class Main {
|
|||||||
|
|
||||||
RegExp expr7 = expr5.punt(expr6);
|
RegExp expr7 = expr5.punt(expr6);
|
||||||
|
|
||||||
RegExp expr8 = expr7.ster();
|
NDFA<String> test = ThompsonConverter.Convert(expr7);
|
||||||
|
|
||||||
NDFA<String> test = ThompsonConverter.Convert(expr8);
|
|
||||||
|
|
||||||
System.out.println(Graph.generateGraphString(test));
|
System.out.println(Graph.generateGraphString(test));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void ReverseAutomata()
|
||||||
|
{
|
||||||
|
Character [] characters = {'a', 'b'};
|
||||||
|
DFA<String> myAutomata = new DFA<String>(characters);
|
||||||
|
|
||||||
|
// AAB
|
||||||
|
myAutomata.addTransition(new Transition<String>("q0", 'a', "q1"));
|
||||||
|
//myAutomata.addTransition(new Transition<String>("q0", 'b', "q1"));
|
||||||
|
|
||||||
|
//myAutomata.addTransition(new Transition<String>("q1", 'a', "q0"));
|
||||||
|
myAutomata.addTransition(new Transition<String>("q1", 'b', "q0"));
|
||||||
|
|
||||||
|
myAutomata.defineAsEndState("q1");
|
||||||
|
myAutomata.defineAsStartState("q0");
|
||||||
|
|
||||||
|
System.out.println(Graph.generateGraphString(myAutomata));
|
||||||
|
|
||||||
|
System.out.println("\nREVERSE:");
|
||||||
|
|
||||||
|
DFA<String> reverseAutomata = myAutomata.Reverse();
|
||||||
|
|
||||||
|
System.out.println(Graph.generateGraphString(reverseAutomata));
|
||||||
|
}
|
||||||
|
|
||||||
public static void Practicum4() {
|
public static void Practicum4() {
|
||||||
Character [] characters = {'a', 'b'};
|
Character [] characters = {'a', 'b'};
|
||||||
NDFA<String> myAutomata = new NDFA<String>(characters);
|
NDFA<String> myAutomata = new NDFA<String>(characters);
|
||||||
@@ -155,6 +178,8 @@ public class Main {
|
|||||||
|
|
||||||
// Practicum2();
|
// Practicum2();
|
||||||
|
|
||||||
Practicum4();
|
// Practicum4();
|
||||||
|
|
||||||
|
ReverseAutomata();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user