Example #1
0
        public async Task <Responce> PostAsync([FromBody] InputData input)
        {
            return(await Task.Run(() =>
            {
                try
                {
                    // Проверка аргумента на null
                    _ = input ?? throw new ArgumentNullException(nameof(input));

                    // Решение задачи
                    IBalanceSolver solver = new AccordBalanceSolver();
                    var output = new OutputData
                    {
                        X = solver.Solve(input.X0, input.A, input.B, input.Measurability,
                                         input.Tolerance, input.Lower, input.Upper),
                        DisbalanceOriginal = solver.DisbalanceOriginal,
                        Disbalance = solver.Disbalance
                    };

                    return new Responce
                    {
                        Type = "result",
                        Data = output
                    };
                }
                catch (Exception e)
                {
                    return new Responce
                    {
                        Type = "error",
                        Data = e.Message
                    };
                }
            }));
        }
        public async Task <Responce> PostGraphAsync([FromBody] InputGraph input)
        {
            var converted = await GraphToMatrixAsync(input);

            return(await Task.Run(() =>
            {
                try
                {
                    // Проверка аргумента на null
                    _ = input ?? throw new ArgumentNullException(nameof(input));

                    // Решение задачи
                    IBalanceSolver solver = new AccordBalanceSolver();

                    var output = new OutputData
                    {
                        X = solver.Solve(converted.X0, converted.A, converted.B, converted.Measurability,
                                         converted.Tolerance,
                                         converted.UseTechnologic
                                ? converted.LowerTechnologic
                                : converted.LowerMetrologic,
                                         converted.UseTechnologic
                                ? converted.UpperTechnologic
                                : converted.UpperMetrologic),
                        DisbalanceOriginal = solver.DisbalanceOriginal,
                        Disbalance = solver.Disbalance,
                        Time = solver.TimeAll.TotalSeconds,
                        TimeMatrix = solver.Time.TotalSeconds
                    };

                    return new Responce
                    {
                        Type = "result",
                        Data = output
                    };
                }
                catch (Exception e)
                {
                    return new Responce
                    {
                        Type = "error",
                        Data = e.Message
                    };
                }
            }));
        }