transit.add(new Transition(true, s1, s2, newTransSymb));
}
}
}
GraphViz gv = new GraphViz(pdfPath);
String label;
String edgeSymbol;
if (transit.size() == 0 || transit.get(0).isDirected()) {
if (completeOutput) println("Directed graph.");
gv.addln(gv.startDigraph());
edgeSymbol = GraphViz.edgeSymbolDirected;
} else {
if (completeOutput) println("Undirected graph.");
gv.addln(gv.startGraph());
edgeSymbol = GraphViz.edgeSymbolUnDirected;
}
gv.addln("rankdir=LR;");
// gv.addln("ranksep=0.12;");
// gv.addln("splines=ortho;");
// gv.addln("decorate=true;");
// Count states.
HashSet<String> set = new HashSet<String>();
set.add(initialState);
for (String s : finalStates) {
set.add(s);
}
for (String s : singleStates) {
set.add(s);
}
for (Transition t : transit) {
set.add(t.getSource());
set.add(t.getDestination());
}
LinkedList<String> list = new LinkedList<String>(set);
Collections.sort(list);
if (completeOutput) println("States (" + set.size() + "): " + list);
// Non-labelled states.
HashSet<String> nonLabelled = new HashSet<String>();
for (String s : set) {
if (optionalLabelMapping == null || !optionalLabelMapping.containsKey(s)) {
nonLabelled.add(s);
}
}
// Additional lines.
for (String s : additionalLinesForFSM) {
gv.addln(s);
}
// Initial state.
if (completeOutput) println("Initial state: " + initialState);
gv.addln("node [shape = point ]; qi");
if (finalStates.contains(initialState)) { // Initial state is final state.
gv.addln("node [shape = doublecircle];");
} else {
gv.addln("node [shape = circle];");
}
if (optionalLabelMapping == null || optionalLabelMapping.get(initialState) == null) {
label = initialState;
} else {
label = optionalLabelMapping.get(initialState);
}
gv.addln("qi " + edgeSymbol + " " + initialState + ";");
gv.addln(initialState + "[label=" + label + "];");
// Single States.
if (completeOutput) println("Single states (" + singleStates.size() + "): " + singleStates);
gv.addln("node [shape = circle];");
for (String s : singleStates) {
if (optionalLabelMapping == null || optionalLabelMapping.get(s) == null) {
label = s;
} else {
label = optionalLabelMapping.get(s);
}
gv.addln(s + "[label=" + label + "];");
}
// Final states.
if (completeOutput) println("Final states (" + finalStates.size() + "): " + finalStates);
gv.addln("node [shape = doublecircle];");
for (String s : finalStates) {
if (optionalLabelMapping == null || optionalLabelMapping.get(s) == null) {
label = s;
} else {
label = optionalLabelMapping.get(s);
}
gv.addln(s + "[label=" + label + "];");
}
gv.addln("node [shape = circle];");
// Transitions.
if (completeOutput) println("Transitions (" + transit.size() + "): " + transit);
for (Transition t : transit) {
String s1 = t.getSource();
String s2 = t.getDestination();
if (optionalLabelMapping == null || optionalLabelMapping.get(s1) == null) {
label = s1;
} else {
label = optionalLabelMapping.get(s1);
}
gv.addln(s1 + "[label=" + label + "];");
if (optionalLabelMapping == null || optionalLabelMapping.get(s2) == null) {
label = s2;
} else {
label = optionalLabelMapping.get(s2);
}
gv.addln(s2 + "[label=" + label + "];");
gv.addln(t.toString());
}
gv.addln(gv.endGraph());
if (completeOutput) println("Not explicitly labelled states (" + nonLabelled.size() + "): " + nonLabelled);
// try {
// gv.storeGraphViz(datNam, pdfPath);