Update:: Create 2 iteration

This commit is contained in:
moxitech 2024-09-03 17:32:14 +07:00
parent 2b0a3a87c7
commit 4b6c7983a1

View File

@ -1,4 +1,5 @@
using System.ComponentModel.DataAnnotations;
using System.Globalization;
using System.Numerics;
using System.Runtime.InteropServices;
using System.Security.Cryptography;
@ -11,6 +12,9 @@ using RealCoordinatesCalculation.Models;
// Подгрузка M1, M2
// Подгрузка PA.TA.HA.TC.PC
// ДИАПАЗОНЫ ВЫЧИСЛЕНИЙ
const double NG_PREDEL_LOW = 1.494452;
const double NG_PREDEL_HIGHT = 1.506247;
@ -26,64 +30,124 @@ const double DGM = 60.00;
const int COUNT_EXPERIMENTS = 6;
//DELETE AFTER PARSER IS GOING TO UP
var XYZ = new Vector3D(5944.787, -1758.92, 3885.021);
var M1 = new Vector3D(3472.706, 2543.101, 952.0311);
var M2 = new Vector3D(-1847.56, 2517.044, -2771.21);
const double PA = 743.056;
const double TA = 27.106;
const double HA = 46.676;
const double PC = 743.12;
const double TC = 26.6;
var L0_J1_12=449.322;
var L0_J1_23=449.939;
var L0_J1_13=899.261;
var L0_J2_12=450.150;
var L0_J2_23=449.513;
var L0_J2_13=899.663;
var L0_J3_12=449.531;
var L0_J3_23=449.856;
var L0_J3_13=899.387;
Console.WriteLine("[*] Start process of calculation");
Console.WriteLine("[1] Layer 1 :: Correcting coordinate is ended");
Console.WriteLine("[2] Layer 2 :: Calculate Distance is resolved");
Console.WriteLine("[3] Layer 3 :: Calculate DELTA is ended");
// Console.WriteLine("[2] Layer 2 :: Calculate Distance is resolved");
// Console.WriteLine("[3] Layer 3 :: Calculate DELTA is ended");
// Display the command line arguments using the args variable.
System.Console.ReadLine();
StartCalc();
// Запуск процесса вычислений
void StartCalc() {
var STEP_NG = (NG_PREDEL_HIGHT - NG_PREDEL_LOW) / 30;
var STEP_BETA = (NG_PREDEL_HIGHT - NG_PREDEL_LOW) / 30;
var filepath = "/home/moxitech/Загрузки/ЦСМ/CALCULATION_INPUT.csv";
List<Measurement> measurements = CsvParser.Parse(filepath);
List<Measurement> ClearedMeasurements = new List<Measurement>();
List<MeasurementMX> M1M2Measurements = new List<MeasurementMX>();
List<DeltaStore> Store = new List<DeltaStore>();
var CorrectedCoords = new List<Vector3D>();
for (int i = 0; i < COUNT_EXPERIMENTS; i++) {
var res = RunDivergenceCorrectForCoordinate(NG_PREDEL_LOW + (STEP_NG * i), (int)(BETA_PREDEL_LOW + (STEP_BETA * i)), PA, TA, HA, PC, TC, M1, M2, XYZ);
System.Console.WriteLine($"[LOG] ITERATION {i} in {COUNT_EXPERIMENTS} :: POINT {"J1.1"} :: " + res);
foreach (var measurement in measurements)
{
// Console.WriteLine(measurement);
if (measurement.Point == "M1" || measurement.Point == "M2") {
M1M2Measurements.Add(new MeasurementMX{
Point = measurement.Point,
Iteration = measurement.Iteration,
X = measurement.X,
Y = measurement.Y,
Z = measurement.Y
});
continue;
}
else {
ClearedMeasurements.Add(measurement);
}
}
Dictionary<string, List<Measurement>> CalculatedResultsL1 = new Dictionary<string, List<Measurement>>();
for (int i = 1; i < COUNT_EXPERIMENTS + 1; i++) {
foreach (var m in ClearedMeasurements)
{
var m1 = M1M2Measurements.Where(x => x.Point == "M1" && x.Iteration == m.Iteration).Last();
var m2 = M1M2Measurements.Where(x => x.Point == "M2" && x.Iteration == m.Iteration).Last();
var res = RunDivergenceCorrectForCoordinate(NG_PREDEL_LOW + (STEP_NG * i), (int)(BETA_PREDEL_LOW + (STEP_BETA * i)), m.PressurePa, m.TemperatureTa, m.HumidityHa, m.PressurePc, m.TemperatureTc,
new Vector3D(m1.X, m1.Y, m1.Z),
new Vector3D(m2.X, m2.Y, m2.Z),
new Vector3D(m.X, m.Y, m.Z)
);
m.FixedX = (double)res.X;
m.FixedY = (double)res.Y;
m.FixedZ = (double)res.Z;
}
Console.WriteLine($"[1] Partial results step {i} :: ");
foreach (var m in ClearedMeasurements)
{
Console.WriteLine($" [ {m.Iteration} |{m.Point}] ({m.X}, {m.Y}, {m.Z}) | Calculated ({m.FixedX}, {m.FixedY}, {m.FixedZ})");
}
CalculatedResultsL1.Add(i.ToString(), ClearedMeasurements);
}
Console.WriteLine("[1] Layer 1 :: Correcting coordinate with Math model is ended, Iterations: " + CalculatedResultsL1.Keys.Count + " Values in iterations: " + CalculatedResultsL1["1"].Count * CalculatedResultsL1.Keys.Count);
Console.Write("∆ | NG | BETA \n");
for (int i = 1; i < COUNT_EXPERIMENTS + 1; i++) {
// Console.WriteLine(CalculatedResultsL1[i.ToString()].Count);
// === Считаем искомые расстояния
var J1_12 = CalculateDistance(GetMeasurementByPoint(CalculatedResultsL1[i.ToString()],"J1.1", 1), GetMeasurementByPoint(CalculatedResultsL1[i.ToString()] ,"J1.2", 1));
// System.Console.WriteLine("J1_12: " + J1_12);
var J1_23 = CalculateDistance(GetMeasurementByPoint(CalculatedResultsL1[i.ToString()] ,"J1.2", 1), GetMeasurementByPoint(CalculatedResultsL1[i.ToString()] ,"J1.3", 1));
//System.Console.WriteLine("J1_23: " + J1_23);
var J1_13 = CalculateDistance(GetMeasurementByPoint(CalculatedResultsL1[i.ToString()] ,"J1.1", 1), GetMeasurementByPoint(CalculatedResultsL1[i.ToString()] ,"J1.3", 1));
// System.Console.WriteLine("J1_13: " + J1_13);
// === Уточняем координаты точек
var J1_1 = RunDivergenceCorrectForCoordinate(NG_PREDEL_LOW, (int)BETA_PREDEL_LOW, PA, TA, HA, PC, TC, M1, M2, XYZ);
var J1_2 = RunDivergenceCorrectForCoordinate(NG_PREDEL_LOW, (int)BETA_PREDEL_LOW, PA, TA, HA, PC, TC, M1, M2, XYZ);
var J1_3 = RunDivergenceCorrectForCoordinate(NG_PREDEL_LOW, (int)BETA_PREDEL_LOW, PA, TA, HA, PC, TC, M1, M2, XYZ);
var J2_1 = RunDivergenceCorrectForCoordinate(NG_PREDEL_LOW, (int)BETA_PREDEL_LOW, PA, TA, HA, PC, TC, M1, M2, XYZ);
var J2_2 = RunDivergenceCorrectForCoordinate(NG_PREDEL_LOW, (int)BETA_PREDEL_LOW, PA, TA, HA, PC, TC, M1, M2, XYZ);
var J2_3 = RunDivergenceCorrectForCoordinate(NG_PREDEL_LOW, (int)BETA_PREDEL_LOW, PA, TA, HA, PC, TC, M1, M2, XYZ);
var J3_1 = RunDivergenceCorrectForCoordinate(NG_PREDEL_LOW, (int)BETA_PREDEL_LOW, PA, TA, HA, PC, TC, M1, M2, XYZ);
var J3_2 = RunDivergenceCorrectForCoordinate(NG_PREDEL_LOW, (int)BETA_PREDEL_LOW, PA, TA, HA, PC, TC, M1, M2, XYZ);
var J3_3 = RunDivergenceCorrectForCoordinate(NG_PREDEL_LOW, (int)BETA_PREDEL_LOW, PA, TA, HA, PC, TC, M1, M2, XYZ);
var J2_12 = CalculateDistance(GetMeasurementByPoint(CalculatedResultsL1[i.ToString()] ,"J2.1", 1), GetMeasurementByPoint(CalculatedResultsL1[i.ToString()] ,"J2.2", 1));
// System.Console.WriteLine("J2_12: " + J2_12);
var J2_23 = CalculateDistance(GetMeasurementByPoint(CalculatedResultsL1[i.ToString()] ,"J2.2", 1), GetMeasurementByPoint(CalculatedResultsL1[i.ToString()] ,"J2.3", 1));
// System.Console.WriteLine("J2_12: " + J2_23);
var J2_13 = CalculateDistance(GetMeasurementByPoint(CalculatedResultsL1[i.ToString()] ,"J2.1", 1), GetMeasurementByPoint(CalculatedResultsL1[i.ToString()] ,"J2.3", 1));
// System.Console.WriteLine("J2_12: " + J2_13);
// === Считаем искомые расстояния
var J1_12 = CalculateDistance(J1_1, J1_2);
var J1_23 = CalculateDistance(J1_2, J1_3);
var J1_13 = CalculateDistance(J1_1, J1_3);
var J3_12 = CalculateDistance(GetMeasurementByPoint(CalculatedResultsL1[i.ToString()] ,"J3.1", 1), GetMeasurementByPoint(CalculatedResultsL1[i.ToString()] ,"J3.2", 1));
// System.Console.WriteLine("J3_12: " + J3_12);
var J3_23 = CalculateDistance(GetMeasurementByPoint(CalculatedResultsL1[i.ToString()] ,"J3.2", 1), GetMeasurementByPoint(CalculatedResultsL1[i.ToString()] ,"J3.3", 1));
// System.Console.WriteLine("J3_12: " + J3_23);
var J3_13 = CalculateDistance(GetMeasurementByPoint(CalculatedResultsL1[i.ToString()] ,"J3.1", 1), GetMeasurementByPoint(CalculatedResultsL1[i.ToString()] ,"J3.3", 1));
// System.Console.WriteLine("J3_12: " + J3_13);
double delta =
Math.Pow(J1_12 - L0_J1_12, 2) +
Math.Pow(J1_23 - L0_J1_23, 2) +
Math.Pow(J1_13 - L0_J1_13, 2) +
Math.Pow(J2_12 - L0_J2_12, 2) +
Math.Pow(J2_23 - L0_J2_23, 2) +
Math.Pow(J2_13 - L0_J2_13, 2) +
Math.Pow(J3_12 - L0_J3_12, 2) +
Math.Pow(J3_23 - L0_J3_23, 2) +
Math.Pow(J3_13 - L0_J3_13, 2);
var J2_12 = CalculateDistance(J2_1, J2_2);
var J2_23 = CalculateDistance(J2_2, J2_3);
var J2_13 = CalculateDistance(J2_1, J2_3);
var J3_12 = CalculateDistance(J3_1, J3_2);
var J3_23 = CalculateDistance(J3_2, J3_3);
var J3_13 = CalculateDistance(J3_1, J3_3);
// === Оцениваем отклонения найденных значений от истинного
System.Console.WriteLine(delta + " | " + (NG_PREDEL_LOW + (STEP_NG * i)) + " | " + (BETA_PREDEL_LOW + (STEP_BETA * i)));
Store.Add(new DeltaStore{
DELTA = delta, BETA = NG_PREDEL_LOW + (STEP_NG * i), NG = BETA_PREDEL_LOW + (STEP_BETA * i)
});
}
Console.WriteLine("[2] Layer 2 is completed, start calculate gradient");
// var ng_min =
}
@ -113,7 +177,85 @@ Vector3D RunDivergenceCorrectForCoordinate(double NG, int BETA, double PA, doubl
return CALCULATED;
}
// Вычисление длинны вектора
double CalculateDistance(Vector3D JI_1, Vector3D JI_2) {
return (double)Vector3D.Length(JI_1, JI_2);
}
Vector3D GetMeasurementByPoint(List<Measurement> measurements, string point, int iteration)
{
var Partial = measurements.FirstOrDefault(m => m.Point == point && m.Iteration == iteration);
if (Partial == null) {
throw new Exception("Ошибка поиска " + point + " на итерации " + iteration);
}
return new Vector3D(Partial.FixedX, Partial.FixedY, Partial.FixedZ);
}
public class CsvParser
{
public static List<Measurement> Parse(string filePath)
{
var measurements = new List<Measurement>();
var lines = File.ReadAllLines(filePath);
for (int i = 1; i < lines.Length; i++) // Пропускаем заголовок
{
var values = lines[i].Split(';');
var measurement = new Measurement
{
Iteration = int.Parse(values[0]),
Point = values[1],
X = double.Parse(values[2].Replace(',', '.'), CultureInfo.InvariantCulture),
Y = double.Parse(values[3].Replace(',', '.'), CultureInfo.InvariantCulture),
Z = double.Parse(values[4].Replace(',', '.'), CultureInfo.InvariantCulture),
PressurePa = double.Parse(values[5].Replace(',', '.'), CultureInfo.InvariantCulture),
TemperatureTa = double.Parse(values[6].Replace(',', '.'), CultureInfo.InvariantCulture),
HumidityHa = double.Parse(values[7].Replace(',', '.'), CultureInfo.InvariantCulture),
PressurePc = double.Parse(values[8].Replace(',', '.'), CultureInfo.InvariantCulture),
TemperatureTc = double.Parse(values[9].Replace(',', '.'), CultureInfo.InvariantCulture),
HumidityHc = double.Parse(values[10].Replace(',', '.'), CultureInfo.InvariantCulture)
};
measurements.Add(measurement);
}
return measurements;
}
}
class DeltaStore {
public double BETA {get;set;}
public double NG {get;set;}
public double DELTA {get;set;}
}
public class MeasurementMX {
public int Iteration { get; set; }
public string Point { get; set; }
public double X { get; set; }
public double Y { get; set; }
public double Z { get; set; }
}
public class Measurement
{
public int Iteration { get; set; }
public string Point { get; set; }
public double X { get; set; }
public double Y { get; set; }
public double Z { get; set; }
public double PressurePa { get; set; }
public double TemperatureTa { get; set; }
public double HumidityHa { get; set; }
public double PressurePc { get; set; }
public double TemperatureTc { get; set; }
public double HumidityHc { get; set; }
public double FixedX { get; set; }
public double FixedY { get; set; }
public double FixedZ { get; set; }
public override string ToString()
{
return $"Iteration: {Iteration}, Point: {Point}, X: {X}, Y: {Y}, Z: {Z}, PressurePa: {PressurePa}, TemperatureTa: {TemperatureTa}, HumidityHa: {HumidityHa}, PressurePc: {PressurePc}, TemperatureTc: {TemperatureTc}, HumidityHc: {HumidityHc}";
}
}