public void SimpleGraph(MaximumFlowAlgorithm maxFlow) { double flow = maxFlow.Compute(source, sink); Assert.AreEqual(23, flow, double.Epsilon); Assert.IsTrue(IsFlow(maxFlow)); Assert.IsTrue(IsOptimal(maxFlow)); }
public void Compute(IVertex source, IVertex sink) { // step 1 constructor balancing graph this.balancer = new GraphBalancerAlgorithm( this.VisitedGraph, source, sink, this.capacities ); balancer.Balance(); this.capacities[balancer.BalancingSourceEdge] = 0; this.capacities[balancer.BalancingSinkEdge] = 0; // step 2 find max flow reverser.AddReversedEdges(); maxFlowF1.Compute(source, sink); // step 3 this.capacities[balancer.BalancingSourceEdge] = double.MaxValue; foreach (IEdge edge in balancer.SurplusEdges) { IVertex v = edge.Target; // find edges foreach (IEdge vs in this.VisitedGraph.OutEdges(v)) { if (vs.Target == balancer.BalancingSource) { this.capacities[vs] = 0; } } } // step 4: // reverser.RemoveReversedEdges(); // balancer.UnBalance(); }