Пример #1
0
        public async Task <IActionResult> GetChinesePostman()
        {
            // var graph = Initializing.CreateGraph(@"../Graph/_ChinesePostman.txt");

            var matrix = new int[8, 8] {
                { 0, 0, 0, 0, 86, 94, 51, 82 },
                { 0, 0, 81, 0, 20, 87, 0, 0 },
                { 0, 81, 0, 83, 41, 0, 0, 0 },
                { 0, 0, 83, 0, 8, 0, 0, 0 },
                { 86, 20, 41, 8, 0, 40, 0, 54 },
                { 94, 87, 0, 0, 40, 0, 89, 0 },
                { 51, 0, 0, 0, 0, 89, 0, 18 },
                { 82, 0, 0, 0, 54, 0, 18, 0 },
            };

            var graph = Initializing.CreateGraph(matrix);

            Graph newGraph = new Graph();

            if (!ChinesePostman.ChinesePostman.IsEvenDegree(graph.Nodes))
            {
                var oddNodes = OddFinder.FindOddNodes(graph.Nodes);
                newGraph = ChinesePostman.ChinesePostman.PairingOddVertices(graph, oddNodes);
            }
            var eulerianPath = ChinesePostman.ChinesePostman.FindEulerianPath(newGraph);

            newGraph.Nodes = eulerianPath.ToArray();
            List <Graph> fullResponse = new List <Graph> {
                graph, newGraph
            };

            return(Ok(fullResponse));
        }
Пример #2
0
        public async Task <IActionResult> GetKruskal()
        {
            // var graph = Initializing.CreateGraph(@"../Graph/_Kruskal.txt");

            var matrix = new int[8, 8] {
                { 0, 3, 0, 0, 0, 34, 0, 80 },
                { 3, 0, 0, 1, 0, 0, 0, 68 },
                { 0, 0, 0, 0, 23, 0, 12, 0 },
                { 0, 1, 0, 0, 53, 0, 0, 39 },
                { 0, 0, 23, 53, 0, 0, 68, 14 },
                { 34, 0, 0, 0, 0, 0, 0, 25 },
                { 0, 0, 12, 0, 68, 0, 0, 99 },
                { 80, 68, 0, 39, 14, 25, 99, 0 },
            };

            var graph = Initializing.CreateGraph(matrix);

            var          graphToReturn = KruskalAlgorithm.KruskalSolve(graph);
            List <Graph> listGraph     = new List <Graph>
            {
                graph,
                graphToReturn
            };

            return(Ok(listGraph));
        }
Пример #3
0
        public static void GetBoruvka()
        {
            var graph         = Initializing.CreateGraph(@"./_First.txt");
            var graphToReturn = BoruvkasAlgorithm.BoruvkaSolve(graph);

            System.Console.WriteLine("\n");
            ConsolePrint.HeaderPrint("Boruvka's method minimum spanning tree");
            ConsolePrint.PrintGraph(graph);
            ConsolePrint.PrintGraph(graphToReturn, "New Graph Edges");
        }
        public async Task <IActionResult> GetKruskal()
        {
            var          graph         = Initializing.CreateGraph(@"../Graph/_Kruskal.txt");
            var          graphToReturn = KruskalAlgorithm.KruskalSolve(graph);
            List <Graph> listGraph     = new List <Graph>
            {
                graph,
                graphToReturn
            };

            return(Ok(listGraph));
        }
Пример #5
0
        public static void GetSalesman()
        {
            var graph  = Initializing.CreateGraph(@"./_Third.txt");
            var matrix = Initializing.CreateMatrix(@"./_Third.txt");

            BnB_matrix brunchAndBound = new BnB_matrix();

            var edges = brunchAndBound.BranchAndBound(matrix);

            System.Console.WriteLine("\n");
            ConsolePrint.HeaderPrint("Salesman problem");
            ConsolePrint.PrintGraph(graph);
            ConsolePrint.PrintPath(edges);
        }
Пример #6
0
        public static void GetBoruvka()
        {
            var graph         = Initializing.CreateGraph(@"./boruvkas.txt");
            var matrix        = Initializing.CreateMatrix(@"./boruvkas.txt");
            var graphToReturn = Boruvkas.BoruvkasSolve(graph);

            System.Console.WriteLine("\n");
            MyPrinter.HeaderPrint("Minimum spanning tree by Boruvka's method");
            MyPrinter.PrintMatrix(matrix, "Started instance:");
            System.Console.WriteLine($"\t Edges count in started instance: {graph.EdgesCount}");
            System.Console.WriteLine($"\t Nodes count in started instance: {graph.VerticesCount}\n");
            // MyPrinter.PrintGraph(graph, "Started graph:");
            MyPrinter.PrintGraph(graphToReturn, "New minimized graph:");
        }
Пример #7
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");
        }
Пример #8
0
        public static void GetSalesman()
        {
            var graph  = Initializing.CreateGraph(@"./salesman.txt");
            var matrix = Initializing.CreateMatrix(@"./salesman.txt");

            System.Console.WriteLine("\n");
            MyPrinter.HeaderPrint("Salesman problem\n");
            MyPrinter.PrintMatrix(matrix, "Matrix instance\n");

            BranchAndBoundSolver brunchAndBound = new BranchAndBoundSolver();

            var edges = brunchAndBound.BranchAndBound(matrix);

            // MyPrinter.PrintGraph(graph, "Graph instance");
            MyPrinter.PrintPath(edges);
        }
Пример #9
0
        public static void GetMaxFlowByFF()
        {
            var graph  = Initializing.CreateGraph(@"./flow.txt");
            var matrix = Initializing.CreateMatrix(@"./flow.txt");

            FlowFinder FlowFinder = new FlowFinder(graph);
            var        flow       = FlowFinder.FindMaximumFlow();

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

            System.Console.WriteLine("\n");
            MyPrinter.HeaderPrint("Max flow");
            MyPrinter.PrintMatrix(matrix, "Matrix instance");
            // MyPrinter.PrintGraph(graph, "Edges instance");
            MyPrinter.PrintFlow(graph.Edges, flow.ToArray());
            System.Console.WriteLine($"\n\t\tmax flow = {maxFlow}\n\n");
        }
        public async Task <IActionResult> GetChinesePostman()
        {
            var graph = Initializing.CreateGraph(@"../Graph/_ChinesePostman.txt");

            Graph newGraph = new Graph();

            if (!ChinesePostman.ChinesePostman.IsEvenDegree(graph.Nodes))
            {
                var oddNodes = OddFinder.FindOddNodes(graph.Nodes);
                newGraph = ChinesePostman.ChinesePostman.PairingOddVertices(graph, oddNodes);
            }
            var eulerianPath = ChinesePostman.ChinesePostman.FindEulerianPath(newGraph);

            newGraph.Nodes = eulerianPath.ToArray();
            List <Graph> fullResponse = new List <Graph> {
                graph, newGraph
            };

            return(Ok(fullResponse));
        }
Пример #11
0
        public static void GetChinesePostman()
        {
            var graph = Initializing.CreateGraph(@"./_Second.txt");

            Graph newGraph = new Graph();

            if (!ChinesePostman.IsEvenDegree(graph.Nodes))
            {
                var oddNodes = OddFinder.FindOddNodes(graph.Nodes);
                newGraph = ChinesePostman.PairingOddVertices(graph, oddNodes);
            }
            var eulerianPath = ChinesePostman.FindEulerianPath(newGraph);

            System.Console.WriteLine("\n");
            ConsolePrint.HeaderPrint("Chinese postman problem");
            ConsolePrint.PrintGraph(graph);
            ConsolePrint.ShowAdditionalEdges(graph, newGraph);
            // ConsolePrint.PrintNodes(graph.Nodes, newGraph.Nodes);
            ConsolePrint.PrintPath(eulerianPath.ToArray());
        }
Пример #12
0
        public async Task <IActionResult> GetSalesman()
        {
            var graph  = Initializing.CreateGraph(@"../Graph/_SalesmanProblem.txt");
            var matrix = Initializing.CreateMatrix(@"../Graph/_SalesmanProblem.txt");

            BnB_matrix brunchAndBound = new BnB_matrix();

            var edges         = brunchAndBound.BranchAndBound(matrix);
            var graphToReturn = (Graph)graph.Clone();

            graphToReturn.EdgesCount = edges.Length;

            graphToReturn.Edges = edges;

            List <Graph> listGraph = new List <Graph>
            {
                graph,
                graphToReturn
            };

            return(Ok(listGraph));
        }
Пример #13
0
        public static void GetPostman()
        {
            var graph = Initializing.CreateGraph(@"./postman.txt");

            var matrix = Initializing.CreateMatrix(@"./postman.txt");

            Graph newGraph = new Graph();

            if (!Postman.IsEvenDegree(graph.Nodes))
            {
                var oddNodes = OddFinder.FindOddNodes(graph.Nodes);
                newGraph = Postman.PairingOddVertices(graph, oddNodes);
            }
            var eulerianPath = Postman.FindEulerianPath(newGraph);

            System.Console.WriteLine("\n");
            MyPrinter.HeaderPrint("Chinese postman problem");
            MyPrinter.PrintMatrix(matrix, "Matrix instance\n");
            // MyPrinter.PrintGraph(graph, "Graph instance: Edges");
            MyPrinter.ShowAdditionalEdges(graph, newGraph);
            MyPrinter.PrintNodes(graph.Nodes, newGraph.Nodes);
            MyPrinter.PrintPath(eulerianPath.ToArray());
        }
        public async Task <IActionResult> GetSalesman()
        {
            var graph  = Initializing.CreateGraph(@"../Graph/_SalesmanProblem.txt");
            var matrix = Initializing.CreateMatrix(@"../Graph/_SalesmanProblem.txt");

            BnB_matrix brunchAndBound = new BnB_matrix();

            var edges         = brunchAndBound.BranchAndBound(matrix);
            var graphToReturn = (Graph)graph.Clone();

            // foreach (var item in edges)
            // {
            //     if (graphToReturn.Edges.Any(x => x.Source == item.Source && x.Destination == item.Destination))
            //     {
            //        continue;
            //     }
            //     else if (graphToReturn.Edges.Any(x => x.Destination == item.Source && x.Source == item.Destination))
            //     {
            //        int temp = 0;
            //        temp = item.Source;
            //        item.Source = item.Destination;
            //        item.Destination = temp;
            //     }
            // }
            graphToReturn.EdgesCount = edges.Length;

            graphToReturn.Edges = edges;

            List <Graph> listGraph = new List <Graph>
            {
                graph,
                graphToReturn
            };

            return(Ok(listGraph));
        }
        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));
        }
Пример #16
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));
        }