Added graphviz
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
.idea
|
||||
out
|
||||
FormeleMethoden.iml
|
||||
images/
|
||||
|
||||
Binary file not shown.
@@ -72,4 +72,12 @@ public class Automata <T extends Comparable> {
|
||||
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();
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
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.
|
||||
*/
|
||||
@@ -30,4 +42,27 @@ public class Graph {
|
||||
|
||||
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:");
|
||||
myAutomata.print();
|
||||
System.out.println("-------");
|
||||
Graph.generateImage(myAutomata, null);
|
||||
|
||||
DFA<String> geminimaliseerd = myAutomata.minimaliseer();
|
||||
System.out.println("Geminimaliseerd krijgen we:");
|
||||
geminimaliseerd.print();
|
||||
System.out.println("------");
|
||||
Graph.generateImage(geminimaliseerd, null);
|
||||
geminimaliseerd.ontkenning();
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
Reference in New Issue
Block a user