public ViewModel(Op <T> root) { var colors = CreateColorPalette(20); var set = new HashSet <Op <T> >(); var visitor = new OpVisitor <T>(op => { if (!set.Contains(op)) { set.Add(op); } }); root.Accept(visitor); var graph = new BidirectionalGraph <object, IEdge <object> >(); // new OpGraph(); var dico = new Dictionary <Op <T>, OpVertex>(); foreach (var op in set) { var colIndex = op.GetType().GetHashCode() % colors.Count; var opVertex = new OpVertex { Name = op.Representation, Color = colors[colIndex], Shape = op.Result?.Shape.ToString() != null ? "[" + op.Result.Shape + "]" : string.Empty }; dico[op] = opVertex; graph.AddVertex(opVertex); } foreach (var op in set) { foreach (var parent in op.Parents) { graph.AddEdge(new OpEdge(dico[parent], dico[op])); } } this.Graph = graph; }
public OpEdge(OpVertex source, OpVertex target) : base(source, target) { }