public double Compute(Vertex src, Vertex sink)
        {
            m_ResidualEdgeCapacities = new EdgeDoubleDictionary();

            // initializing
            foreach (Vertex u in VisitedGraph.Vertices)
            {
                foreach (Edge e in u.OutEdges)
                {
                    ResidualCapacities[e] = Capacities[e];
                }
            }

            Colors[sink] = GraphColor.Gray;
            while (Colors[sink] != GraphColor.White)
            {
                VertexBuffer          Q  = new VertexBuffer();
                ResidualEdgePredicate ep = new ResidualEdgePredicate(ResidualCapacities);

                BreadthFirstSearchAlgorithm bfs  = new BreadthFirstSearchAlgorithm(resg, Q, Colors);
                PredecessorVisitor          pred = new PredecessorVisitor(Predecessors);
                pred.RegisterHandlers(bfs);
                bfs.Compute(src);

                if (Colors[sink] != GraphColor.White)
                {
                    Augment(src, sink, pred.Predecessors);
                }
            }             // while

            double flow = 0;

            foreach (Edge e in src.OutEdges)
            {
                flow += (EdgeCapacities[e] - ResidualEdgeCapacities[e]);
            }

            return(flow);
        }
Пример #2
0
        public double Compute(Vertex src, Vertex sink)
        {
            m_ResidualEdgeCapacities = new EdgeDoubleDictionary();

            // initializing
            foreach(Vertex u in VisitedGraph.Vertices)
                foreach(Edge e in u.OutEdges)
                    ResidualCapacities[e] = Capacities[e];

            Colors[sink] = GraphColor.Gray;
            while (Colors[sink] != GraphColor.White)
            {
                VertexBuffer Q = new VertexBuffer();
                ResidualEdgePredicate ep = new ResidualEdgePredicate(ResidualCapacities);

                BreadthFirstSearchAlgorithm bfs = new BreadthFirstSearchAlgorithm(resg,Q,Colors);
                PredecessorVisitor pred = new PredecessorVisitor(Predecessors);
                pred.RegisterHandlers(bfs);
                bfs.Compute(src);

                if (Colors[sink] != GraphColor.White)
                    Augment(src, sink, pred.Predecessors);
            } // while

            double flow = 0;
            foreach(Edge e in src.OutEdges)
                flow += (EdgeCapacities[e] - ResidualEdgeCapacities[e]);

            return flow;
        }