public virtual void AddVertex(T vertex) { if (vertex == null) { Log.Error("Vertex is null."); return; } if (VerticesData.ContainsKey(vertex)) { Log.Error("Vertex is already part of the graph: " + vertex); return; } VerticesData[vertex] = new VertexData <T, P>(vertex); recalcIsTree = true; RootVertices.Add(vertex); }
public virtual void AddEdge(Relation <T, P> relation) { if (relation == null || relation.Source == null || relation.Target == null) { Log.Error("Relation or vertex is null."); return; } if (!VerticesData.ContainsKey(relation.Source)) { Log.Error("Relation source is missing from the graph: " + relation.Source); return; } if (!VerticesData.ContainsKey(relation.Target)) { Log.Error("Relation target is missing from the graph: " + relation.Target); return; } if (!Edges.Add(relation)) { Log.Error("Relation is already part of the graph: " + relation); return; } VerticesData[relation.Source].OutEdges.Add(relation); VerticesData[relation.Target].InEdges.Add(relation); // maintain root data if (!relation.IsSelfRelation) { recalcIsTree = true; RootVertices.Remove(relation.Target); } }
public bool ContainsVertex(T vertex) { return(VerticesData.ContainsKey(vertex)); }