private static PlotResponse GetPlotResponse(PlotRequest plotRequest, double failureRate)
        {
            var systemRequest = HybridToSystemRequest(plotRequest.HybridSystemRequest, single =>
            {
                if (single.ModuleName == plotRequest.ModuleName)
                {
                    single.FailureRate = Math.Round(failureRate, 7, MidpointRounding.AwayFromZero);
                }

                return(single);
            });

            var system = (MultipleModuleSystem)systemRequest.ToSystem();
            var graph  = new SystemStateGraph(system, false);

            var plotData =
                graph.GetProbability(plotRequest.FromTime, plotRequest.ToTime, plotRequest.Step);

            return(new PlotResponse
            {
                FailureRate = Math.Round(failureRate, 7, MidpointRounding.AwayFromZero),
                ModuleName = plotRequest.ModuleName,
                PlotData = plotData
            });
        }
        public IActionResult GetPlot([FromBody] PlotRequest plotRequest)
        {
            if (plotRequest.HybridSystemRequest.Type != ModuleType.Multiple)
            {
                return(BadRequest());
            }

            var result = plotRequest
                         .FailureRates
                         .Select(failureRate => GetPlotResponse(plotRequest, failureRate)).ToList();

            var originalRequest = HybridToSystemRequest(plotRequest.HybridSystemRequest, _ => _);
            var originalSystem  = (MultipleModuleSystem)originalRequest.ToSystem();
            var originalGraph   = new SystemStateGraph(originalSystem, false);

            var originalPlotData =
                originalGraph.GetProbability(plotRequest.FromTime, plotRequest.ToTime, plotRequest.Step);

            result.Add(new PlotResponse
            {
                FailureRate = -1,
                ModuleName  = plotRequest.ModuleName,
                PlotData    = originalPlotData
            });

            return(Ok(result));
        }
        public string ToString(SystemStateGraph stateGraph)
        {
            var stringBuilder = new StringBuilder();

            foreach (var transition in stateGraph.Transitions)
            {
                if (!_stateFilteringStrategy.IncludeState(transition.SystemState))
                {
                    continue;
                }

                stringBuilder.Append(_representation(transition.SystemState));
                stringBuilder.Append(" -> ");

                const string delimiter = ", ";
                foreach (var toSystemState in transition.ToSystemStates)
                {
                    stringBuilder.Append(_representation(toSystemState.ToSystemState));
                    stringBuilder.Append(delimiter);
                }

                if (transition.ToSystemStates.Any())
                {
                    stringBuilder.Remove(stringBuilder.Length - delimiter.Length, delimiter.Length);
                }

                stringBuilder.AppendLine();
            }

            return(stringBuilder.ToString());
        }
        public IActionResult GetEquationSystem([FromBody] HybridSystemRequest hybridRequest)
        {
            if (hybridRequest.Type != ModuleType.Multiple)
            {
                return(BadRequest());
            }

            var systemRequest = HybridToSystemRequest(hybridRequest, _ => _);
            var system        = (MultipleModuleSystem)systemRequest.ToSystem();
            var graph         = new SystemStateGraph(system, false);
            var matrix        = graph.BuildWeightMatrix();

            var result = new List <List <double> >();
            var sb     = new StringBuilder();

            for (var row = 0; row < matrix.GetLength(0); row++)
            {
                sb.Append($"P{row + 1}(t)/dt = ");
                var currentEq = new List <double>();
                for (var col = 0; col < matrix.GetLength(1); col++)
                {
                    matrix[row, col] = Math.Round(matrix[row, col], 7, MidpointRounding.AwayFromZero);

                    currentEq.Add(matrix[row, col]);
                    if (matrix[row, col] != 0)
                    {
                        var value = matrix[row, col] < 0
                            ? $" - {(-1 * matrix[row, col]).ToString(CultureInfo.InvariantCulture)}"
                            : $" + {matrix[row, col].ToString(CultureInfo.InvariantCulture)}";

                        sb.Append($"{value} * P{col + 1}(t)");
                    }
                }

                result.Add(currentEq);
                sb.AppendLine();
            }

            return(Ok(new EquationSystemModel
            {
                Coefficients = result,
                SystemStates = graph.AllPossibleStates.Select(ToModel)
            }));
        }