Added graphviz
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
.idea
|
.idea
|
||||||
out
|
out
|
||||||
FormeleMethoden.iml
|
FormeleMethoden.iml
|
||||||
|
images/
|
||||||
|
|||||||
Binary file not shown.
@@ -72,4 +72,12 @@ public class Automata <T extends Comparable> {
|
|||||||
beginStates.clear();
|
beginStates.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
for (T state : this.states) {
|
||||||
|
sb.append(state);
|
||||||
|
}
|
||||||
|
return "Automata" + sb.toString();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -89,4 +89,31 @@ public class DFA<T extends Comparable> extends Automata<T> {
|
|||||||
return this.reverse().toDFA().reverse().toDFA();
|
return this.reverse().toDFA().reverse().toDFA();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public DFA<T> ontkenning() {
|
||||||
|
DFA<T> returnDFA = new DFA<T>(this.symbols);
|
||||||
|
|
||||||
|
SortedSet<T> newEndStates = new TreeSet<>();
|
||||||
|
|
||||||
|
for (T state : this.states) {
|
||||||
|
if (!this.eindStates.contains(state)) {
|
||||||
|
newEndStates.add(state);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (T newEndState : newEndStates) {
|
||||||
|
returnDFA.defineAsEndState(newEndState);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (T beginState : this.beginStates) {
|
||||||
|
returnDFA.defineAsStartState(beginState);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Transition<T> transistion : this.transistions) {
|
||||||
|
returnDFA.addTransition(transistion);
|
||||||
|
}
|
||||||
|
|
||||||
|
return returnDFA;
|
||||||
|
}
|
||||||
|
|
||||||
|
//TODO: add and & or operations
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,17 @@
|
|||||||
package com.imegumii;
|
package com.imegumii;
|
||||||
|
|
||||||
|
import guru.nidi.graphviz.engine.Format;
|
||||||
|
import guru.nidi.graphviz.engine.Graphviz;
|
||||||
|
import guru.nidi.graphviz.model.Label;
|
||||||
|
import guru.nidi.graphviz.model.MutableGraph;
|
||||||
|
import guru.nidi.graphviz.model.Node;
|
||||||
|
import guru.nidi.graphviz.parse.Parser;
|
||||||
|
|
||||||
|
import java.io.*;
|
||||||
|
|
||||||
|
import static guru.nidi.graphviz.model.Factory.graph;
|
||||||
|
import static guru.nidi.graphviz.model.Factory.node;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by kenny on 18-5-2017.
|
* Created by kenny on 18-5-2017.
|
||||||
*/
|
*/
|
||||||
@@ -30,4 +42,27 @@ public class Graph {
|
|||||||
|
|
||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void generateImage(Automata<String> a, String fileName) {
|
||||||
|
try {
|
||||||
|
File f = new File("images/" + a.toString() + ".dot");
|
||||||
|
PrintWriter w = new PrintWriter(f);
|
||||||
|
w.println(Graph.generateGraphString(a));
|
||||||
|
w.flush();
|
||||||
|
w.close();
|
||||||
|
MutableGraph g = Parser.read(f);
|
||||||
|
if (fileName != null) {
|
||||||
|
Graphviz.fromGraph(g).width(1080).render(Format.PNG).toFile(new File("images/" + fileName + ".png"));
|
||||||
|
} else {
|
||||||
|
Graphviz.fromGraph(g).width(1080).render(Format.PNG).toFile(new File("images/" + a.toString() + ".png"));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (f.delete()) {
|
||||||
|
System.out.println("Succesfully deleted temp file");
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -264,11 +264,14 @@ public class Main {
|
|||||||
System.out.println("Ongeminimaliseerd krijgen we:");
|
System.out.println("Ongeminimaliseerd krijgen we:");
|
||||||
myAutomata.print();
|
myAutomata.print();
|
||||||
System.out.println("-------");
|
System.out.println("-------");
|
||||||
|
Graph.generateImage(myAutomata, null);
|
||||||
|
|
||||||
DFA<String> geminimaliseerd = myAutomata.minimaliseer();
|
DFA<String> geminimaliseerd = myAutomata.minimaliseer();
|
||||||
System.out.println("Geminimaliseerd krijgen we:");
|
System.out.println("Geminimaliseerd krijgen we:");
|
||||||
geminimaliseerd.print();
|
geminimaliseerd.print();
|
||||||
System.out.println("------");
|
System.out.println("------");
|
||||||
|
Graph.generateImage(geminimaliseerd, null);
|
||||||
|
geminimaliseerd.ontkenning();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
|||||||
Reference in New Issue
Block a user