public Graph() { Final = false; Valid = true; Multitrees = new Dictionary <int, Node>(); AdjacencyList = new AdjacencyList(false); ReversedAdjacencyList = new AdjacencyList(true); }
/// <summary> /// Sets the graph to immutable and creates the reversed adjacency list /// </summary> public void SetImmutable() { if (!Valid) { throw new InvalidOperationException("Graph is declared invalid"); } foreach (var tree in Multitrees) { tree.Value.SetImmutable(); } Final = true; Algorithms.ComputeDimensionFactors(AdjacencyList); ReversedAdjacencyList = Algorithms.ReverseAdjacencyList(AdjacencyList); }
/// <summary> /// Appends an edge to the graph. If the nodes, the edge is referencing, are not yet /// part of the graph, they will also be appended /// </summary> public void AddEdge(Edge newEdge) { if (!Valid) { throw new InvalidOperationException("Graph is declared invalid"); } if (Final) { throw new InvalidOperationException("Graph can not be modified after set to immutable"); } Edge edgeToAdd = Algorithms.ResolvePossibleReplacements(newEdge); if (!Validators.IsValidEdge(edgeToAdd, this)) { throw new InvalidOperationException("Edge reference is not part of the graph"); } AdjacencyList.AddEdge(edgeToAdd); }