summaryrefslogtreecommitdiff
path: root/Source/Graph
diff options
context:
space:
mode:
Diffstat (limited to 'Source/Graph')
-rw-r--r--Source/Graph/Graph.cs13
1 files changed, 13 insertions, 0 deletions
diff --git a/Source/Graph/Graph.cs b/Source/Graph/Graph.cs
index e5e8444c..b5590865 100644
--- a/Source/Graph/Graph.cs
+++ b/Source/Graph/Graph.cs
@@ -843,6 +843,19 @@ namespace Graphing {
}
return dag.TopologicalSort();
}
+
+ public string ToDot(Func<Node, string> NodeLabel = null, Func<Node, string> NodeStyle = null) {
+ NodeLabel = NodeLabel ?? (n => n.ToString());
+ NodeStyle = NodeStyle ?? (n => "[shape=box]");
+ var s = new StringBuilder();
+ s.AppendLine("digraph G {");
+ foreach (var n in Nodes)
+ s.AppendLine(" \"" + NodeLabel(n) + "\" " + NodeStyle(n) + ";");
+ foreach (var e in Edges)
+ s.AppendLine(" \"" + NodeLabel(e.Item1) + "\" -> \"" + NodeLabel(e.Item2) + "\";");
+ s.AppendLine("}");
+ return s.ToString();
+ }
} // end: class Graph
public class GraphProgram {