public void Predicate_Throws() { var predicate = new ResidualEdgePredicate <int, Edge <int> >( new Dictionary <Edge <int>, double>()); // ReSharper disable ReturnValueOfPureMethodIsNotUsed // ReSharper disable once AssignNullToNotNullAttribute Assert.Throws <ArgumentNullException>(() => predicate.Test(null)); var edge12 = new Edge <int>(1, 2); Assert.Throws <KeyNotFoundException>(() => predicate.Test(edge12)); // ReSharper restore ReturnValueOfPureMethodIsNotUsed }
public void Predicate() { var predicate = new ResidualEdgePredicate <int, Edge <int> >( new Dictionary <Edge <int>, double>()); var edge12 = new Edge <int>(1, 2); var edge13 = new Edge <int>(1, 3); var edge31 = new Edge <int>(3, 1); predicate.ResidualCapacities.Add(edge12, -12); predicate.ResidualCapacities.Add(edge13, 0); predicate.ResidualCapacities.Add(edge31, 1); Assert.IsFalse(predicate.Test(edge12)); Assert.IsFalse(predicate.Test(edge13)); Assert.IsTrue(predicate.Test(edge31)); }
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); }