public static DirectedGraphDescriptor <TNodeValue, TEdgeLabel> ToDescriptor <TNodeValue, TEdgeLabel>(this DirectedGraph <TNodeValue, TEdgeLabel> source) { if (source == null) { throw new ArgumentNullException("source"); } var descriptor = new DirectedGraphDescriptor <TNodeValue, TEdgeLabel>(); ToDescriptor(source, descriptor); return(descriptor); }
public static void AddDescriptor <TNodeValue, TEdgeLabel>(this DirectedGraph <TNodeValue, TEdgeLabel> source, DirectedGraphDescriptor <TNodeValue, TEdgeLabel> descriptor) { if (source == null) { throw new ArgumentNullException("source"); } if (descriptor == null) { throw new ArgumentNullException("descriptor"); } var nodes = descriptor.Nodes.Select(value => source.Add(value)).ToArray(); foreach (var edge in descriptor.Edges) { source.AddEdge(nodes[edge.From], nodes[edge.To], edge.Label); } }
public static void ToDescriptor <TNodeValue, TEdgeLabel>(this DirectedGraph <TNodeValue, TEdgeLabel> source, DirectedGraphDescriptor <TNodeValue, TEdgeLabel> descriptor) { if (source == null) { throw new ArgumentNullException("source"); } if (descriptor == null) { throw new ArgumentNullException("descriptor"); } var nodes = source.ToArray(); foreach (var node in nodes) { descriptor.Nodes.Add(node.Value); } var from = 0; foreach (var node in nodes) { foreach (var successor in node.Successors) { var to = Array.IndexOf(nodes, successor.Target); descriptor.Edges.Add(new EdgeDescriptor <TEdgeLabel>(from, to, successor.Label)); } from++; } }
public static DirectedGraph <TNodeValue, TEdgeLabel> ToDirectedGraph <TNodeValue, TEdgeLabel>(this DirectedGraphDescriptor <TNodeValue, TEdgeLabel> source) { if (source == null) { throw new ArgumentNullException(nameof(source)); } var graph = new DirectedGraph <TNodeValue, TEdgeLabel>(); graph.AddDescriptor(source); return(graph); }