public string ToGraphviz(string name, Func <T, string> getNodeLabel, Func <E, string> getEdgeLabel) { int num = 0; Dictionary <T, int> nodeDic = Nodes.ToDictionary(n => n, n => num++, Comparer); string nodes = Nodes.ToString(e => " {0} [ label =\"{1}\"];".FormatWith(nodeDic[e], getNodeLabel(e)), "\r\n"); string edges = EdgesWithValue.ToString(e => " {0} -> {1} [ label =\"{2}\"];".FormatWith(nodeDic[e.From], nodeDic[e.To], getEdgeLabel(e.Value)), "\r\n"); return("digraph \"{0}\"\r\n{{\r\n{1}\r\n{2}\r\n}}".FormatWith(name, nodes, edges)); }
public DirectedEdgedGraph <T, E> WhereEdges(Func <Edge <T, E>, bool> condition, bool keepAllNodes) { if (keepAllNodes) { DirectedEdgedGraph <T, E> result = new DirectedEdgedGraph <T, E>(Comparer); foreach (var item in Nodes) { result.Add(item, RelatedTo(item).Where(to => condition(new Edge <T, E>(item, to.Key, to.Value)))); } return(result); } else { DirectedEdgedGraph <T, E> result = new DirectedEdgedGraph <T, E>(Comparer); foreach (var e in EdgesWithValue.Where(condition)) { result.Add(e.From, e.To, e.Value); } return(result); } }
public XDocument ToDGML(Func <T, XAttribute[]> getNodeAttributes, Func <E, XAttribute[]> getEdgeAttributes) { int num = 0; Dictionary <T, int> nodeDic = Nodes.ToDictionary(n => n, n => num++, Comparer); XNamespace ns = "http://schemas.microsoft.com/vs/2009/dgml"; return(new XDocument( new XElement(ns + "DirectedGraph", new XElement(ns + "Nodes", Nodes.Select(n => new XElement(ns + "Node", new XAttribute("Id", nodeDic[n]), getNodeAttributes(n)))), new XElement(ns + "Links", EdgesWithValue.Select(e => new XElement(ns + "Link", new XAttribute("Source", nodeDic[e.From]), new XAttribute("Target", nodeDic[e.To]), getEdgeAttributes(e.Value)))) ) )); }