Пример #1
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
            var graph = Initializing.CreateGraph(@"../Graph/_Flow.txt");
            // var matrix = Initializing.CreateMatrix(@"../Graph/_SalesmanProblem.txt");

            FlowCalc flow = new FlowCalc(graph);

            flow.FindMaximumFlow();
        }
Пример #2
0
        public static void GetMaxFlowByFF()
        {
            var graph = Initializing.CreateGraph(@"./_Fourth.txt");

            FlowCalc flowCalc = new FlowCalc(graph);
            var      flow     = flowCalc.FindMaximumFlow();

            var maxFlow = flow.Where(e => e.Edge.Destination == graph.Nodes.Last().Id).Sum(x => x.Flow);

            System.Console.WriteLine("\n");
            ConsolePrint.HeaderPrint("Max flow");
            ConsolePrint.PrintGraph(graph);
            ConsolePrint.PrintFlow(graph.Edges, flow.ToArray());
            System.Console.WriteLine($"\t\tMAXIMUM FLOW = {maxFlow}\n\n");
        }
        public async Task <IActionResult> GetMaxFlowByFF()
        {
            var graph = Initializing.CreateGraph(@"../Graph/_Flow.txt");

            FlowCalc flowCalc = new FlowCalc(graph);
            var      flow     = flowCalc.FindMaximumFlow();

            var newGraph = (Graph)graph.Clone();

            foreach (var item in flow)
            {
                newGraph.Edges.Where(x => x.Source == item.Edge.Source && x.Destination == item.Edge.Destination && x.Weight == item.Edge.Weight).Select(x => { x.Weight = item.Flow; return(x); }).ToArray();
            }
            // (Graph graph, List<FlowModel> flow) fullResponse;

            List <Graph> fullResponse = new List <Graph>();

            // fullResponse.graph = graph;
            // fullResponse.flow = flow;

            fullResponse.Add(graph);
            fullResponse.Add(newGraph);
            return(Ok(fullResponse));
        }
Пример #4
0
        public async Task <IActionResult> GetMaxFlowByFF()
        {
            // var graph = Initializing.CreateGraph(@"../Graph/_Flow.txt");
            var matrix = new int[8, 8] {
                { 0, 20, 20, 40, 0, 0, 0, 0 },
                { 0, 0, 10, 0, 10, 0, 0, 0 },
                { 0, 0, 0, 20, 20, 0, 0, 0 },
                { 0, 0, 0, 0, 0, 20, 20, 0 },
                { 0, 0, 0, 0, 0, 0, 0, 30 },
                { 0, 0, 10, 0, 20, 0, 0, 20 },
                { 0, 0, 0, 0, 0, 10, 0, 20 },
                { 0, 0, 0, 0, 0, 0, 0, 0 },
            };

            var graph = Initializing.CreateGraph(matrix); //Can initialize from file to matrix, from file to graph, from matrix to graph and so

            FlowCalc flowCalc = new FlowCalc(graph);
            var      flow     = flowCalc.FindMaximumFlow();

            var newGraph = (Graph)graph.Clone();

            foreach (var item in flow)
            {
                newGraph.Edges.Where(x => x.Source == item.Edge.Source && x.Destination == item.Edge.Destination && x.Weight == item.Edge.Weight).Select(x => { x.Weight = item.Flow; return(x); }).ToArray();
            }
            // (Graph graph, List<FlowModel> flow) fullResponse;

            List <Graph> fullResponse = new List <Graph>();

            // fullResponse.graph = graph;
            // fullResponse.flow = flow;

            fullResponse.Add(graph);
            fullResponse.Add(newGraph);
            return(Ok(fullResponse));
        }