X-Git-Url: http://git.megacz.com/?p=sbp.git;a=blobdiff_plain;f=src%2Fedu%2Fberkeley%2Fsbp%2Futil%2FGraphViz.java;h=1d85e11d4058eb035fa985ff8276d7ea4c9e9110;hp=44b47fcc8d80bf18085a6ac5924f6910e2994a97;hb=24219bdf084b45273e869cd19382d1640b396566;hpb=14b3d2ee6a2d2ef84628e541ec291961f2061a5a diff --git a/src/edu/berkeley/sbp/util/GraphViz.java b/src/edu/berkeley/sbp/util/GraphViz.java index 44b47fc..1d85e11 100644 --- a/src/edu/berkeley/sbp/util/GraphViz.java +++ b/src/edu/berkeley/sbp/util/GraphViz.java @@ -10,18 +10,18 @@ import java.lang.ref.*; public class GraphViz { - IdentityHashMap ihm = new IdentityHashMap(); - HashMap groups = new HashMap(); + IdentityHashMap ihm = new IdentityHashMap(); + HashMap groups = new HashMap(); - public class Group extends Node { + public class Group extends StateNode { private final int idx = master_idx++; public boolean cluster = false; public boolean primary = true; public Group() { } - public void add(Node n) { groups.put(n, this); } + public void add(StateNode n) { groups.put(n, this); } public String name() { return cluster?("cluster_"+idx):("subgraph_"+idx); } public boolean simple() { return false; } - public void dump(PrintWriter pw, IdentityHashMap done) { + public void dump(PrintWriter pw, IdentityHashMap done) { Group g = this; if (done.get(g)!=null) return; done.put(g,g); @@ -29,7 +29,7 @@ public class GraphViz { pw.println(" label=\""+StringUtil.escapify(label.toString(), "\\\"\r\n")+"\";\n"); pw.println(" color="+g.color+";\n"); pw.println(" shape="+g.shape+";\n"); - for(Node n : groups.keySet()) + for(StateNode n : groups.keySet()) if (groups.get(n)==g) n.dump(pw, done); pw.println(" }\n"); @@ -38,7 +38,7 @@ public class GraphViz { private static int master_idx=0; - public class Node { + public class StateNode { private final int idx = master_idx++; public String label; public String comment; @@ -46,11 +46,11 @@ public class GraphViz { public String color="black"; public String fill="white"; public String shape="ellipse"; - public ArrayList edges = new ArrayList(); + public ArrayList edges = new ArrayList(); public ArrayList labels = new ArrayList(); - public ArrayList inbound = new ArrayList(); + public ArrayList inbound = new ArrayList(); public void edge(ToGraphViz o, Object label) { - Node n = o.toGraphViz(GraphViz.this); + StateNode n = o.toGraphViz(GraphViz.this); if (n==null) return; edges.add(n); labels.add(label); @@ -69,7 +69,7 @@ public class GraphViz { public void edges(PrintWriter pw) { if (simple()) return; for(int i=0; i " + n.name() + " [color="+color+" " +(label==null?"":("label=\""+StringUtil.escapify(label.toString(), "\\\"\r\n")+"\""))+ "];\n"); @@ -80,17 +80,17 @@ public class GraphViz { boolean simple = true; if (label!=null && !label.equals("")) simple = false; if (simple) - for(Node n : edges) + for(StateNode n : edges) //if (n.numEdges()>0) { simple = false; break; } if (n.inbound.size() > 1) { simple = false; break; } return simple; } - public void dump(PrintWriter pw, IdentityHashMap done) { + public void dump(PrintWriter pw, IdentityHashMap done) { if (done.get(this)!=null) return; done.put(this, this); if (inbound.size() > 0) { boolean good = false; - for(Node n : inbound) + for(StateNode n : inbound) if (!n.simple()) { good = true; break; } if (!good) return; @@ -102,12 +102,12 @@ public class GraphViz { pw.print(" shape=record "); pw.print(" label=\""); boolean complex = false; - for(Node n : edges) + for(StateNode n : edges) if (n.edges.size()>0) complex = true; if (!complex) pw.print("{"); boolean first = true; - for(Node n : edges) { + for(StateNode n : edges) { if (!first) pw.print("|"); first = false; pw.print(""); @@ -130,10 +130,10 @@ public class GraphViz { return ihm.get(o)!=null; } - public Node createNode(ToGraphViz o) { - Node n = ihm.get(o); + public StateNode createNode(ToGraphViz o) { + StateNode n = ihm.get(o); if (n!=null) return n; - n = new Node(); + n = new StateNode(); ihm.put(o, n); return n; } @@ -147,7 +147,7 @@ public class GraphViz { } public static interface ToGraphViz { - Node toGraphViz(GraphViz gv); + StateNode toGraphViz(GraphViz gv); boolean isTransparent(); boolean isHidden(); } @@ -158,17 +158,17 @@ public class GraphViz { public void dump(OutputStream os) { dump(new PrintWriter(new OutputStreamWriter(os))); } public void dump(PrintWriter pw) { - IdentityHashMap done = new IdentityHashMap(); + IdentityHashMap done = new IdentityHashMap(); pw.println("digraph G { rankdir=LR; ordering=out; compound=true; \n"); for(Group g : groups.values()) if (g.primary) g.dump(pw, done); - for(Node n : ihm.values()) { + for(StateNode n : ihm.values()) { if (done.get(n)!=null) continue; if (n instanceof Group) continue; n.dump(pw, done); } - for(Node n : ihm.values()) n.edges(pw); + for(StateNode n : ihm.values()) n.edges(pw); pw.println("}\n"); pw.flush(); }