예제 #1
0
 public Graph()
 {
     Final                 = false;
     Valid                 = true;
     Multitrees            = new Dictionary <int, Node>();
     AdjacencyList         = new AdjacencyList(false);
     ReversedAdjacencyList = new AdjacencyList(true);
 }
예제 #2
0
        /// <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);
        }
예제 #3
0
        /// <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);
        }