private static void TestMaxFlow() { FlowNetwork fn = new FlowNetwork(); Vertex v1 = new Vertex(); Vertex v2 = new Vertex(); Vertex v3 = new Vertex(); Vertex v4 = new Vertex(); Vertex v5 = new Vertex(); Vertex v6 = new Vertex(); fn.AddVertex(v1); fn.AddVertex(v2); fn.AddVertex(v3); fn.AddVertex(v4); fn.AddVertex(v5); fn.AddVertex(v6); fn.SetSource(v1); fn.SetSink(v6); fn.AddEdge(new FlowEdge(v1, v2, 0f, 2f)); fn.AddEdge(new FlowEdge(v1, v3, 0f, 2f)); fn.AddEdge(new FlowEdge(v2, v4, 0f, 2f)); fn.AddEdge(new FlowEdge(v3, v4, 1f, 2f)); fn.AddEdge(new FlowEdge(v3, v5, 0f, 2f)); fn.AddEdge(new FlowEdge(v4, v6, 1f, 2f)); fn.AddEdge(new FlowEdge(v5, v6, 0f, 2f)); //float maxFlow = GraphAlgorithms.MaximumFlow(fn); //Console.WriteLine("Max flow is " + maxFlow); }
private static void TestResidualNetwork() { //Create graph from Figure 6.10 FlowNetwork fn = new FlowNetwork(); Vertex v1 = new Vertex(); Vertex v2 = new Vertex(); Vertex v3 = new Vertex(); Vertex v4 = new Vertex(); fn.AddVertex(v1); fn.AddVertex(v2); fn.AddVertex(v3); fn.AddVertex(v4); fn.SetSource(v1); fn.SetSink(v4); fn.AddEdge(new FlowEdge(v1, v3, 3, 4)); fn.AddEdge(new FlowEdge(v1, v2, 2, 2)); fn.AddEdge(new FlowEdge(v2, v3, 2, 3)); fn.AddEdge(new FlowEdge(v3, v4, 5, 5)); fn.AddEdge(new FlowEdge(v2, v4, 0, 1)); Graph g = GraphAlgorithms.CreateResidualNetwork(fn); }