private static void ComputeForCheckPrecisionOffItterativeAlgoritm(List <int> iterativeList) { var resultList = new List <AlgorithmIterativePrecisionModel>(); foreach (var iterativeNumber in iterativeList) { var points = DataParser.ParsePointData(_csvFile.Replace("%points%", "250").Replace("%route%", "1"), 1); var pointsToAlg = new List <DataPoint>(); for (int i = 0; i < points.Count; i++) { if (i % 2 == 0) { pointsToAlg.Add(points[i]); } } var csiGaussSeidel = new CubicSplineInterpolation(pointsToAlg, AlgorithmType.IterativeGaussSeidel, iterativeNumber); var csiGaussJacobi = new CubicSplineInterpolation(pointsToAlg, AlgorithmType.IterativeJacobi, iterativeNumber); var indexes = new List <double>(); for (double i = 0; i < points.Count - 2; i++) { indexes.Add(i); } var valuesFromFile = indexes.Select(x => new { x, value = points.First(p => p.X == x).Y, AlgorithmType = AlgorithmType.None }).ToList(); var expectedValuesForSeidel = indexes.Select(x => new { x, value = csiGaussSeidel.GetObjectiveFunction(x), AlgorithmType = AlgorithmType.IterativeGaussSeidel }).ToList(); var expectedValuesForJacobi = indexes.Select(x => new { x, value = csiGaussJacobi.GetObjectiveFunction(x), AlgorithmType = AlgorithmType.IterativeJacobi }).ToList(); resultList.AddRange(expectedValuesForSeidel .Concat(valuesFromFile) .Concat(expectedValuesForJacobi) .GroupBy(x => x.x) .Select(gl => new AlgorithmIterativePrecisionModel { XKey = gl.Key, Iteration = iterativeNumber, ValueFromFile = gl.FirstOrDefault(v => v.AlgorithmType == AlgorithmType.None).value, ValueForGaussSeidel = gl.FirstOrDefault(v => v.AlgorithmType == AlgorithmType.IterativeGaussSeidel).value, ValueForJacobi = gl.FirstOrDefault(v => v.AlgorithmType == AlgorithmType.IterativeJacobi).value, }) .Where(r => r.ValueFromFile - r.ValueForGaussSeidel != 0) .ToList()); } foreach (var result in resultList) { result.IsSameValue = result.ValueForGaussSeidel == result.ValueForJacobi; } using (var writer = new StreamWriter($"result_check_preciscion_iterative_algo.csv")) using (var csv = new CsvWriter(writer)) { csv.WriteRecords(resultList); } }
static void ComputeAltitudeProfileC1(List <int> routeNumbers) { var pointsToAlgo = new List <int> { 50, 250, 500 }; foreach (var routeNumber in routeNumbers) { foreach (var pointsQuantity in pointsToAlgo) { var pointsFromRoute = DataParser.ParsePointData(_csvFile.Replace("%points%", pointsQuantity.ToString()).Replace("%route%", routeNumber.ToString()), routeNumber); var pointsGivenToAlgo = new List <DataPoint>(); for (int i = 0; i < pointsFromRoute.Count; i++) { if (i % 2 == 0) { pointsGivenToAlgo.Add(pointsFromRoute[i]); } } var csiGaussSeidel = new CubicSplineInterpolation(pointsGivenToAlgo, AlgorithmType.IterativeGaussSeidel); var csiGaussJacobi = new CubicSplineInterpolation(pointsGivenToAlgo, AlgorithmType.IterativeJacobi); var csiGaussPartialPivot = new CubicSplineInterpolation(pointsGivenToAlgo, AlgorithmType.GaussPartialPivot); var csiSparseIterativeJacobi = new CubicSplineInterpolation(pointsGivenToAlgo, AlgorithmType.SparseIterativeJacobi); var alglib = new CubicSplineInterpolation(pointsGivenToAlgo, AlgorithmType.SparseAlgLibraryType); var indexes = new List <double>(); for (double i = 0; i < pointsFromRoute.Count - 2; i++) { indexes.Add(i); } var valuesFromFile = indexes.Select(x => new { x, value = pointsFromRoute.First(p => p.X == x).Y, AlgorithmType = AlgorithmType.None }).ToList(); var expectedValuesForAlglib = indexes.Select(x => new { x, value = alglib.GetObjectiveFunction(x), AlgorithmType = AlgorithmType.SparseAlgLibraryType }).ToList(); var expectedValuesForSeidel = indexes.Select(x => new { x, value = csiGaussSeidel.GetObjectiveFunction(x), AlgorithmType = AlgorithmType.IterativeGaussSeidel }).ToList(); var expectedValuesForJacobi = indexes.Select(x => new { x, value = csiGaussJacobi.GetObjectiveFunction(x), AlgorithmType = AlgorithmType.IterativeJacobi }).ToList(); var expectedValuesForPartialPivot = indexes.Select(x => new { x, value = csiGaussPartialPivot.GetObjectiveFunction(x), AlgorithmType = AlgorithmType.GaussPartialPivot }).ToList(); var expectedValuesForSparseGaussSeidel = indexes.Select(x => new { x, value = csiSparseIterativeJacobi.GetObjectiveFunction(x), AlgorithmType = AlgorithmType.SparseIterativeJacobi }).ToList(); var groupedList = expectedValuesForSeidel .Concat(expectedValuesForAlglib) .Concat(valuesFromFile) .Concat(expectedValuesForJacobi) .Concat(expectedValuesForPartialPivot) .Concat(expectedValuesForSparseGaussSeidel) .GroupBy(x => x.x) .Select(gl => new { gl.Key, ValueFromFile = gl.FirstOrDefault(v => v.AlgorithmType == AlgorithmType.None).value, Alglib = gl.FirstOrDefault(v => v.AlgorithmType == AlgorithmType.SparseAlgLibraryType).value, PartialPivot = gl.FirstOrDefault(v => v.AlgorithmType == AlgorithmType.GaussPartialPivot).value, GaussSeider = gl.FirstOrDefault(v => v.AlgorithmType == AlgorithmType.IterativeGaussSeidel).value, Jacobi = gl.FirstOrDefault(v => v.AlgorithmType == AlgorithmType.IterativeJacobi).value, SparseJacobie = gl.FirstOrDefault(v => v.AlgorithmType == AlgorithmType.SparseIterativeJacobi).value }) .Where(r => r.ValueFromFile - r.GaussSeider != 0) .ToList(); using (var writer = new StreamWriter($"result_t{routeNumber}_{pointsQuantity}.csv")) using (var csv = new CsvWriter(writer)) { csv.WriteRecords(groupedList); } var errors = groupedList.Select(gl => new { AbsoluteErrorForAlgLib = Math.Abs(gl.Alglib - gl.ValueFromFile), RelativeErrorForAlgLib = Math.Abs((gl.Alglib - gl.ValueFromFile) / gl.ValueFromFile), AbsoluteErrorForJacobi = Math.Abs(gl.Jacobi - gl.ValueFromFile), RelativeErrorForJacobi = Math.Abs((gl.Jacobi - gl.ValueFromFile) / gl.ValueFromFile), AbsoluteErrorForSparseJacobi = Math.Abs(gl.SparseJacobie - gl.ValueFromFile), RelativeErrorForSparseJacobi = Math.Abs((gl.SparseJacobie - gl.ValueFromFile) / gl.ValueFromFile), AbsoluteErrorForPartialPivot = Math.Abs(gl.PartialPivot - gl.ValueFromFile), RelativeErrorForPartialPivot = Math.Abs((gl.PartialPivot - gl.ValueFromFile) / gl.ValueFromFile), AbsoluteErrorForGaussSeidel = Math.Abs(gl.GaussSeider - gl.ValueFromFile), RelativeErrorForGaussSeidel = Math.Abs((gl.GaussSeider - gl.ValueFromFile) / gl.ValueFromFile), }) .ToList(); using (var writer = new StreamWriter($"errors_t{routeNumber}_{pointsQuantity}.csv")) using (var csv = new CsvWriter(writer)) { csv.WriteRecords(errors); } } } }