/// <summary>
        /// Iteratively removes the dangling links from the rank map
        /// </summary>
        public void RemoveDanglingLinks()
        {
            VertexCollection danglings = new VertexCollection();
            do
            {
                danglings.Clear();

                // create filtered graph
                IVertexListGraph fg = new FilteredVertexListGraph(
                    this.VisitedGraph,
                    new InDictionaryVertexPredicate(this.ranks)
                    );

                // iterate over of the vertices in the rank map
                foreach(IVertex v in this.ranks.Keys)
                {
                    // if v does not have out-edge in the filtered graph, remove
                    if ( fg.OutDegree(v) == 0)
                        danglings.Add(v);
                }

                // remove from ranks
                foreach(IVertex v in danglings)
                    this.ranks.Remove(v);
                // iterate until no dangling was removed
            }while(danglings.Count != 0);
        }
        private bool IsOptimal(MaximumFlowAlgorithm maxFlow)
        {
            // check if mincut is saturated...
            FilteredVertexListGraph residualGraph = new FilteredVertexListGraph(
                maxFlow.VisitedGraph,
                new ReversedResidualEdgePredicate(maxFlow.ResidualCapacities, maxFlow.ReversedEdges)
                );
            BreadthFirstSearchAlgorithm bfs = new BreadthFirstSearchAlgorithm(residualGraph);

            VertexIntDictionary distances = new VertexIntDictionary();
            DistanceRecorderVisitor vis = new DistanceRecorderVisitor(distances);
            bfs.RegisterDistanceRecorderHandlers(vis);
            bfs.Compute(sink);

            return distances[source] >= maxFlow.VisitedGraph.VerticesCount;
        }
 public void RemoveDanglingLinks()
 {
     VertexCollection vertexs = new VertexCollection();
     do
     {
         vertexs.Clear();
         IVertexListGraph graph = new FilteredVertexListGraph(this.VisitedGraph, new InDictionaryVertexPredicate(this.ranks));
         foreach (IVertex vertex in this.ranks.get_Keys())
         {
             if (graph.OutDegree(vertex) == 0)
             {
                 vertexs.Add(vertex);
             }
         }
         VertexCollection.Enumerator enumerator = vertexs.GetEnumerator();
         while (enumerator.MoveNext())
         {
             IVertex vertex2 = enumerator.get_Current();
             this.ranks.Remove(vertex2);
         }
     }
     while (vertexs.Count != 0);
 }