/// <summary> /// Runs the graph unbalancing algorithm. /// </summary> /// <exception cref="T:System.InvalidOperationException">If the graph is not balanced.</exception> public void UnBalance() { if (!Balanced) { throw new InvalidOperationException("Graph is not balanced."); } foreach (TEdge edge in _surplusEdges) { VisitedGraph.RemoveEdge(edge); Capacities.Remove(edge); _preFlow.Remove(edge); } foreach (TEdge edge in _deficientEdges) { VisitedGraph.RemoveEdge(edge); Capacities.Remove(edge); _preFlow.Remove(edge); } Capacities.Remove(BalancingSinkEdge); Capacities.Remove(BalancingSourceEdge); _preFlow.Remove(BalancingSinkEdge); _preFlow.Remove(BalancingSourceEdge); VisitedGraph.RemoveEdge(BalancingSourceEdge); VisitedGraph.RemoveEdge(BalancingSinkEdge); VisitedGraph.RemoveVertex(BalancingSource); VisitedGraph.RemoveVertex(BalancingSink); BalancingSource = default(TVertex); BalancingSink = default(TVertex); BalancingSourceEdge = default(TEdge); BalancingSinkEdge = default(TEdge); _surplusEdges.Clear(); _deficientEdges.Clear(); _surplusVertices.Clear(); _deficientVertices.Clear(); Balanced = false; }