AircraftSJ.cs 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. using KYFramework;
  2. using Model;
  3. using MongoDB.Bson;
  4. using MuShiApp;
  5. using SimulationCommon;
  6. using SimulationSingleServer.Utils;
  7. using Unity.Mathematics;
  8. using Define = SimulationServer.Utils.Define;
  9. using Point = SimulationCommon.Point;
  10. using Random = System.Random;
  11. namespace SimulationServer;
  12. public class AircraftSJ : AircraftEntity
  13. {
  14. public bool IsOver;
  15. private MissionEndPoint MissionEndPoint;
  16. private CurrentLocation currentLocation;
  17. private double temptime = 0;
  18. private double probability = 0;
  19. private double finalProbability = 1.0;
  20. private Random random = new Random();
  21. private bool isseefire = false;
  22. private int fireIndex = -1; // 记录发现火点的位置
  23. public EquationHelper helper;
  24. public override void Start()
  25. {
  26. //TODO 计算 AirRoute[]
  27. double[] initialPosition = { FlightPlanEditor.targetpoint[0].TargetPointLatitude, FlightPlanEditor.targetpoint[0].TargetPointLongitude };
  28. double dt = 1;
  29. double totalTime = 24.0;
  30. Text_readNC text_ReadNC = new Text_readNC();
  31. text_ReadNC.GetNCData();
  32. var nCread = text_ReadNC.windNCread;
  33. //漂移轨迹
  34. List<double[]> trajectory = SeaSJ.CalculateDriftTrajectory(nCread, initialPosition,dt, totalTime);
  35. // 生成任务终点
  36. MissionEndPoint = new MissionEndPoint
  37. {
  38. MissionEndPointLongitude = trajectory[trajectory.Count - 1][1],
  39. MissionEndPointLatitude = trajectory[trajectory.Count - 1][0],
  40. MissionEndPointHeight = 0
  41. };
  42. var temp = SeaSJ.getminEnclosingRect(trajectory);
  43. // temp 转成 List<Point>
  44. List<Point> points = new List<Point>();
  45. foreach (var item in temp)
  46. {
  47. points.Add(new Point(item[0], item[1]));
  48. }
  49. Point basePoint = new Point(FlightPlanEditor.originbase.BaseLatitude, FlightPlanEditor.originbase.BaseLongitude);
  50. double sweepWidth = 0.2;
  51. // 生成航路点
  52. List<Point> waypoints = ParallellineSearch.parallellineSearch(basePoint, points, sweepWidth);
  53. // List<Point> 转成 List<AirRoute>
  54. List<AirRoute> airRoutes = new List<AirRoute>();
  55. foreach (var item in waypoints)
  56. {
  57. airRoutes.Add(new AirRoute
  58. {
  59. AirRouteLatitude = item.lat,
  60. AirRouteLongitude = item.lon
  61. });
  62. }
  63. FlightPlanEditor.airroute = airRoutes.ToArray();
  64. FXJHGenerate.FromStartToMission(FlightPlanEditor, ref TurningPoints); //生成从起点到任务段起点的航路点
  65. FXJHGenerate.SeaSouJiu(FlightPlanEditor, ref TurningPoints);
  66. FXJHGenerate.FXJHTPDiedai(FlightPlanEditor, ref TurningPoints, Velocitys, FuelConsumptions);
  67. Task.Run(() =>
  68. {
  69. bool isseefire = false;
  70. double temptime = 0; // 自增时间,每次增加1s
  71. CurrentLocation currentLocation = new CurrentLocation();
  72. double probability = 0;
  73. double finalProbability = 1.0;
  74. Random random = new Random();
  75. int fireIndex = -1; // 记录发现火点的位置
  76. do
  77. {
  78. (currentLocation, _) =
  79. FXJHGenerate.GetCurrentLocation(TurningPoints, FlightPlanEditor, temptime); // 获取飞机当前位置
  80. double3 aricraftPoint = new double3(currentLocation.CurrentLon, currentLocation.CurrentLat,
  81. currentLocation.CurrentHei);
  82. double3 targetPoint = new double3(FlightPlanEditor.targetpoint[0].TargetPointLongitude,
  83. FlightPlanEditor.targetpoint[0].TargetPointLatitude,
  84. FlightPlanEditor.targetpoint[0].TargetPointHeight);
  85. //*******
  86. probability = helper.getProbability(aricraftPoint, targetPoint, currentLocation.CurrentCourse,
  87. Define.WIND, 1, "落水人员", "陆地"); // 计算发现概率,需要其他模型输入 // 计算发现概率,需要其他模型输入
  88. finalProbability *= (1 - probability);
  89. Console.WriteLine($"海上任务: {Name} 当前时间:{temptime},当前位置:{currentLocation.CurrentLon},{currentLocation.CurrentLat},{currentLocation.CurrentHei},概率:{probability},最终概率:{1 -finalProbability},是否看到落水人员:{isseefire}");
  90. double randomValue = random.NextDouble(); // 生成随机数比较概率
  91. if (randomValue < (1 - finalProbability))
  92. {
  93. isseefire = true;
  94. fireIndex = currentLocation.Currentsegnum; // 记录当前航路点位置
  95. IsOver = true;
  96. }
  97. else
  98. {
  99. isseefire = false;
  100. }
  101. if (temptime >= 7200) IsOver = true;
  102. temptime += 1;
  103. } while (!isseefire && IsOver == false);
  104. finalProbability = 1 - finalProbability;
  105. if (fireIndex != -1)
  106. {
  107. // 删除目标点位置开始的所有后续航路点
  108. TurningPoints.RemoveRange(fireIndex + 1, TurningPoints.Count - fireIndex - 1);
  109. MissionPoint missionPoint = new MissionPoint
  110. {
  111. MissionPointLongitude = currentLocation.CurrentLon,
  112. MissionPointLatitude = currentLocation.CurrentLat,
  113. MissionPointHeight = currentLocation.CurrentHei
  114. };
  115. FXJHGenerate.SeaSouJiu2(FlightPlanEditor, missionPoint, ref TurningPoints);
  116. //发现的目标坐标,需要其他模型输入
  117. FXJHGenerate.FromMissionToEnd(FlightPlanEditor, MissionEndPoint, ref TurningPoints);
  118. }
  119. FXJHGenerate.FXJHTPDiedai(FlightPlanEditor, ref TurningPoints, Velocitys, FuelConsumptions);
  120. Log.Info(TurningPoints.ToJson());
  121. End();
  122. });
  123. }
  124. public override void End()
  125. {
  126. for (int i = 0; i < currentLocation.Currentsegnum + 2; i++)
  127. {
  128. EffMisTime += TurningPoints[i].SegmentFlightTime;
  129. }
  130. TotalFuelConsumption = TurningPoints[0].RemainingFuel -
  131. TurningPoints[currentLocation.Currentsegnum + 1].RemainingFuel;
  132. }
  133. }
  134. [ObjectSystem]
  135. public class AircraftSJAwakeSystem : AwakeSystem<AircraftSJ, FlightPlanEditor>
  136. {
  137. public override void Awake(AircraftSJ self, FlightPlanEditor flightPlanEditor)
  138. {
  139. self.FlightPlanEditor = flightPlanEditor;
  140. self.helper = new EquationHelper(HttpInterface.baseUrl);
  141. self.Awake();
  142. }
  143. }