Beispiel #1
0
        private static void QueryMaxFlow(GraphAdj <int> graph, int from, int to)
        {
            var maximumFlow = graph.MaximumFlow(from, to);

            Console.WriteLine($"Max flow from {from} " +
                              $"to {to}:  {maximumFlow}");
        }
Beispiel #2
0
        private static GraphAdj <int> CreateGraph(int n)
        {
            GraphAdj <int> graphAdj = new GraphAdj <int>(n);

            graphAdj.AddEdge(1, 0);
            graphAdj.AddEdge(0, 2);
            graphAdj.AddEdge(0, 3);
            graphAdj.AddEdge(2, 1);
            graphAdj.AddEdge(3, 4);

            return(graphAdj);
        }
Beispiel #3
0
        private static GraphAdj <int> CreateGraph(int n)
        {
            var graph = new GraphAdj <int>(n, true);

            graph.AddEdge(0, 1, 16); graph.AddEdge(0, 2, 13);
            graph.AddEdge(1, 2, 10); graph.AddEdge(1, 3, 12);
            graph.AddEdge(2, 1, 4); graph.AddEdge(2, 4, 14);
            graph.AddEdge(3, 2, 9); graph.AddEdge(3, 5, 20);
            graph.AddEdge(4, 3, 7); graph.AddEdge(4, 5, 4);

            return(graph);
        }
Beispiel #4
0
        private static GraphAdj <int> CreateGraph(int n)
        {
            var graph = new GraphAdj <int>(n, true);

            graph.AddEdge(0, 1, 6);
            graph.AddEdge(0, 3, 7);
            graph.AddEdge(1, 3, 8);
            graph.AddEdge(1, 4, -4);
            graph.AddEdge(1, 2, 5);
            graph.AddEdge(2, 1, -2);
            graph.AddEdge(3, 2, -3);
            graph.AddEdge(3, 4, 9);
            graph.AddEdge(4, 2, 7);
            graph.AddEdge(4, 0, 2);

            return(graph);
        }
Beispiel #5
0
        private static GraphAdj <int> CreateGraph(int countNodes)
        {
            GraphAdj <int> graphAdj = new GraphAdj <int>(countNodes);

            graphAdj.AddEdge(1, 2, 100);
            graphAdj.AddEdge(1, 3, -2);
            graphAdj.AddEdge(1, 4, 100);
            graphAdj.AddEdge(2, 1, 4);
            graphAdj.AddEdge(2, 3, 3);
            graphAdj.AddEdge(2, 4, 100);
            graphAdj.AddEdge(4, 2, -1);
            graphAdj.AddEdge(4, 1, 100);
            graphAdj.AddEdge(4, 3, 100);
            graphAdj.AddEdge(3, 1, 100);
            graphAdj.AddEdge(3, 2, 100);
            graphAdj.AddEdge(3, 4, 2);

            return(graphAdj);
        }
Beispiel #6
0
        private static GraphAdj <int> CreateGraph(int n)
        {
            var graph = new GraphAdj <int>(n, true);

            graph.AddEdge(1, 8, 70); graph.AddEdge(8, 1, 70); graph.AddEdge(1, 9, 30);
            graph.AddEdge(9, 1, 30); graph.AddEdge(1, 10, 10); graph.AddEdge(10, 1, 10);
            graph.AddEdge(1, 2, 50); graph.AddEdge(2, 1, 50); graph.AddEdge(1, 3, 60);
            graph.AddEdge(3, 1, 60); graph.AddEdge(2, 10, 70); graph.AddEdge(10, 2, 70);
            graph.AddEdge(2, 3, 10); graph.AddEdge(3, 2, 10); graph.AddEdge(2, 4, 90);
            graph.AddEdge(4, 2, 90); graph.AddEdge(2, 5, 70); graph.AddEdge(5, 2, 70);
            graph.AddEdge(3, 10, 40); graph.AddEdge(10, 3, 40); graph.AddEdge(3, 5, 70);
            graph.AddEdge(5, 3, 70); graph.AddEdge(3, 4, 20); graph.AddEdge(4, 3, 20);
            graph.AddEdge(4, 5, 20); graph.AddEdge(5, 4, 20); graph.AddEdge(4, 6, 70);
            graph.AddEdge(6, 4, 70); graph.AddEdge(4, 7, 80); graph.AddEdge(7, 4, 80);
            graph.AddEdge(5, 6, 60); graph.AddEdge(6, 5, 60); graph.AddEdge(5, 7, 70);
            graph.AddEdge(7, 5, 70); graph.AddEdge(6, 7, 20); graph.AddEdge(7, 6, 20);
            graph.AddEdge(6, 8, 70); graph.AddEdge(8, 6, 70); graph.AddEdge(7, 8, 40);
            graph.AddEdge(8, 7, 40); graph.AddEdge(7, 9, 50); graph.AddEdge(9, 7, 50);
            graph.AddEdge(8, 9, 30); graph.AddEdge(9, 8, 30); graph.AddEdge(8, 10, 60);
            graph.AddEdge(10, 8, 60); graph.AddEdge(9, 10, 20); graph.AddEdge(10, 9, 20);

            return(graph);
        }