Progress
This commit is contained in:
@@ -16,7 +16,7 @@ public class Automata <T extends Comparable> {
|
|||||||
protected SortedSet<T> beginStates;
|
protected SortedSet<T> beginStates;
|
||||||
protected SortedSet<T> eindStates;
|
protected SortedSet<T> eindStates;
|
||||||
|
|
||||||
private SortedSet<Character> symbols;
|
protected SortedSet<Character> symbols;
|
||||||
|
|
||||||
public Automata(Character [] symbols) {
|
public Automata(Character [] symbols) {
|
||||||
this(new TreeSet<Character>(Arrays.asList(symbols)));
|
this(new TreeSet<Character>(Arrays.asList(symbols)));
|
||||||
|
|||||||
@@ -1,7 +1,10 @@
|
|||||||
package com.imegumii;
|
package com.imegumii;
|
||||||
|
|
||||||
|
import com.sun.source.util.Trees;
|
||||||
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.SortedSet;
|
import java.util.SortedSet;
|
||||||
|
import java.util.TreeSet;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by imegumii on 01/05/2017.
|
* Created by imegumii on 01/05/2017.
|
||||||
@@ -12,11 +15,11 @@ public class DFA<T extends Comparable> extends Automata<T> {
|
|||||||
super(symbols);
|
super(symbols);
|
||||||
}
|
}
|
||||||
|
|
||||||
public DFA(SortedSet symbols) {
|
public DFA(SortedSet<Character> symbols) {
|
||||||
super(symbols);
|
super(symbols);
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean accepteer(String s) {
|
public boolean accepteer(String s) {
|
||||||
// bij een DFA is er maar een beginstate, dus gebruiken we first.
|
// bij een DFA is er maar een beginstate, dus gebruiken we first.
|
||||||
T beginState = this.beginStates.first();
|
T beginState = this.beginStates.first();
|
||||||
T currentState = beginState;
|
T currentState = beginState;
|
||||||
@@ -40,7 +43,28 @@ public class DFA<T extends Comparable> extends Automata<T> {
|
|||||||
return this.eindStates.contains(currentState);
|
return this.eindStates.contains(currentState);
|
||||||
}
|
}
|
||||||
|
|
||||||
void geefTaalTotLengte(int n) {
|
private TreeSet<String> addSymbols(int n, TreeSet<String> tempSet) {
|
||||||
|
TreeSet<String> tempGenerated = new TreeSet<>(tempSet);
|
||||||
|
if (n == 0) {
|
||||||
|
return tempGenerated;
|
||||||
|
}
|
||||||
|
|
||||||
|
for(String s : tempSet) {
|
||||||
|
for(Character c : this.symbols) {
|
||||||
|
tempGenerated.add(s + c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
tempGenerated.addAll(addSymbols(n - 1, tempGenerated));
|
||||||
|
|
||||||
|
return tempGenerated;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Taal geefTaalTotLengte(int n) {
|
||||||
|
TreeSet<String> taal = new TreeSet<>();
|
||||||
|
for (Character c : this.symbols) {
|
||||||
|
taal.add("" + c);
|
||||||
|
}
|
||||||
|
return new Taal(addSymbols(n - 1, taal));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+23
-16
@@ -6,19 +6,10 @@ import java.util.TreeSet;
|
|||||||
|
|
||||||
public class Main {
|
public class Main {
|
||||||
|
|
||||||
public static void Practicum1Opdr1() {
|
public static void P1Opdracht1(TreeSet<String> stringsToParse) {
|
||||||
TreeSet<String> stringsToParse = new TreeSet<>();
|
|
||||||
stringsToParse.add("abbaa");
|
|
||||||
stringsToParse.add("babaa");
|
|
||||||
stringsToParse.add("abbaaabaab");
|
|
||||||
stringsToParse.add("abaab");
|
|
||||||
stringsToParse.add("aaaabba");
|
|
||||||
stringsToParse.add("baab");
|
|
||||||
stringsToParse.add("baaba");
|
|
||||||
stringsToParse.add("baabaabba");
|
|
||||||
|
|
||||||
Character [] characters = {'a', 'b'};
|
Character [] characters = {'a', 'b'};
|
||||||
DFA<String> myAutomata = new DFA<String>(characters);
|
DFA<String> myAutomata = new DFA<String>(characters);
|
||||||
|
|
||||||
// AAB
|
// AAB
|
||||||
myAutomata.addTransition(new Transition<String>("q0", 'a', "q1"));
|
myAutomata.addTransition(new Transition<String>("q0", 'a', "q1"));
|
||||||
|
|
||||||
@@ -50,16 +41,32 @@ public class Main {
|
|||||||
myAutomata.defineAsEndState("q7");
|
myAutomata.defineAsEndState("q7");
|
||||||
|
|
||||||
myAutomata.printTransitions();
|
myAutomata.printTransitions();
|
||||||
final long[] totalTime = {0};
|
final long[] startTime = {System.currentTimeMillis()};
|
||||||
stringsToParse.forEach((s) -> {
|
myAutomata.geefTaalTotLengte(10).getSymbols().forEach((s) -> {
|
||||||
long before = System.currentTimeMillis();
|
long before = System.currentTimeMillis();
|
||||||
boolean result = myAutomata.accepteer(s);
|
boolean result = myAutomata.accepteer(s);
|
||||||
long after = System.currentTimeMillis();
|
long after = System.currentTimeMillis();
|
||||||
long delta = (after-before);
|
long delta = (after-before);
|
||||||
System.out.println("string " + s + " fully parsed, result: " + result + " , it took " + delta + " ms");
|
System.out.println("string " + s + " fully parsed, result: " + result + " , it took " + delta + " ms");
|
||||||
totalTime[0] += delta;
|
startTime[0] += delta;
|
||||||
});
|
});
|
||||||
System.out.println(totalTime[0]);
|
System.out.println((System.currentTimeMillis() - startTime[0]));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void Practicum1() {
|
||||||
|
TreeSet<String> stringsToParse = new TreeSet<>();
|
||||||
|
stringsToParse.add("abbaa");
|
||||||
|
stringsToParse.add("babaa");
|
||||||
|
stringsToParse.add("abbaaabaab");
|
||||||
|
stringsToParse.add("abaab");
|
||||||
|
stringsToParse.add("aaaabba");
|
||||||
|
stringsToParse.add("baab");
|
||||||
|
stringsToParse.add("baaba");
|
||||||
|
stringsToParse.add("baabaabba");
|
||||||
|
stringsToParse.add("aaaaabb"); // this is wrong, something is wrong
|
||||||
|
|
||||||
|
|
||||||
|
P1Opdracht1(stringsToParse);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
@@ -68,7 +75,7 @@ public class Main {
|
|||||||
// t1.printTransitions();
|
// t1.printTransitions();
|
||||||
System.out.println("Zo moet het dus, nu onze beurt.");
|
System.out.println("Zo moet het dus, nu onze beurt.");
|
||||||
|
|
||||||
Practicum1Opdr1();
|
Practicum1();
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
package com.imegumii;
|
||||||
|
|
||||||
|
import java.util.SortedSet;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by imegumii on 02/05/2017.
|
||||||
|
*/
|
||||||
|
public class Taal {
|
||||||
|
private SortedSet<String> symbols;
|
||||||
|
|
||||||
|
public Taal(SortedSet<String> sortedSet) {
|
||||||
|
this.symbols = sortedSet;
|
||||||
|
}
|
||||||
|
|
||||||
|
public SortedSet<String> getSymbols() {
|
||||||
|
return symbols;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user