Example #1
0
        public static int FindMaxFlow(AdjacencyList adList)
        {
            flowCapacityList = adList;

            InitializePreFlow();

            var t = FindExcessVertex();

            while (ExistExcess())
            {
                if (IsPushing(t))
                {
                    Push(t);
                }
                else if (IsRelabeling(t))
                {
                    Relabel(t);
                }
                else
                {
                    t = FindExcessVertex();
                }
            }

            int maxFlow = 0;

            for (int j = 0; j < flowCapacityList["S"].Count; j++)
            {
                maxFlow += flowCapacityList["S"][j].Flow;
            }

            return(maxFlow);
        }
Example #2
0
        static void Main(string[] args)
        {
            AdjacencyList adList = FileHandler.CreateAdjacencyList(@"..\..\..\network.txt");

            Console.WriteLine($"Max Flow = {PreFlow.FindMaxFlow(adList)}");

            PreFlow.Print();
        }