123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276 |
- using KYFramework;
- using Model;
- using MongoDB.Bson;
- using MuShiApp;
- using SimulationCommon;
- using SimulationSingleServer.Utils;
- using Unity.Mathematics;
- using Point = SimulationCommon.Point;
- using Random = System.Random;
- namespace SimulationServer;
- public class AircraftSJ : AircraftEntity
- {
- public bool IsOver;
- private MissionEndPoint MissionEndPoint;
- private CurrentLocation currentLocation;
- private double temptime = 0;
- private double probability = 0;
- private double finalProbability = 1.0;
- private bool isseefire = false;
- private int fireIndex = -1;
- public EquationHelper helper;
- public SeaSouJiuTask taskContent;
- public bool Success = true;
- public override void Start()
- {
-
- double[] initialPosition =
- {
- FlightPlanEditor.targetpoint[0].TargetPointLatitude, FlightPlanEditor.targetpoint[0].TargetPointLongitude
- };
- double dt = 1;
- double totalTime = 24.0;
- Text_readNC text_ReadNC = new Text_readNC();
- text_ReadNC.GetNCData();
- text_ReadNC.GetWaveHighData();
- var nCread = text_ReadNC.windNCread;
-
- List<double[]> trajectory = SeaSJ.CalculateDriftTrajectory(nCread, initialPosition, dt, totalTime);
- Log.Info(trajectory.ToJson());
-
- MissionEndPoint = new MissionEndPoint
- {
- MissionEndPointLongitude = trajectory[^1][1],
- MissionEndPointLatitude = trajectory[^1][0],
- MissionEndPointHeight = 0
- };
- var temp = SeaSJ.getminEnclosingRect(trajectory);
-
- List<Point> points = new List<Point>();
- foreach (var item in temp)
- {
- points.Add(new Point(item[0], item[1]));
- }
- Point basePoint = new Point(FlightPlanEditor.originbase.BaseLatitude,
- FlightPlanEditor.originbase.BaseLongitude);
- List<Point> waypoints = new List<Point>();
-
- if (taskContent.SearchMode == "平行线搜索")
- {
- waypoints = ParallellineSearch.parallellineSearch(basePoint, points, taskContent.SearchWidth);
- }
- if (taskContent.SearchMode == "扇形搜索")
- {
- waypoints = SectorSearch.PerformSearch(taskContent.SearchWidth);
- }
- if (taskContent.SearchMode == "扩展矩形搜索")
- {
- waypoints = TZFX.GenerateWaypoints(points[0], points[1], points[2], points[3], 20, taskContent.SearchWidth);
- }
- Log.Info("===========================");
- Log.Info( FlightPlanEditor.targetpoint[0].ToJson());
- Log.Info("===========================");
- Log.Info(points.ToJson());
- Log.Info("===========================");
- Log.Info(waypoints.ToJson());
-
- List<AirRoute> airRoutes = new List<AirRoute>();
- foreach (var item in waypoints)
- {
- airRoutes.Add(new AirRoute
- {
- AirRouteLatitude = item.lat,
- AirRouteLongitude = item.lon
- });
- }
-
-
-
-
-
- FlightPlanEditor.airroute = airRoutes.ToArray();
- MissionPoint missionPoint = new MissionPoint();
- missionPoint.MissionPointLatitude = waypoints[0].lat;
- missionPoint.MissionPointLongitude = waypoints[0].lon;
-
- FlightPlanEditor.missionpoint = missionPoint;
- FXJHGenerate.FromStartToMission(FlightPlanEditor, ref TurningPoints);
- FXJHGenerate.SeaSouJiu(FlightPlanEditor, ref TurningPoints);
- FXJHGenerate.FXJHTPDiedai(FlightPlanEditor, ref TurningPoints, Velocitys, FuelConsumptions);
- Task.Run(() =>
- {
- bool isseefire = false;
- double temptime = 0;
- CurrentLocation currentLocation = new CurrentLocation();
- double probability = 0;
- double finalProbability = 1.0;
- Random random = new Random();
- int fireIndex = -1;
- do
- {
- (currentLocation, _) =
- FXJHGenerate.GetCurrentLocation(TurningPoints, FlightPlanEditor, temptime);
- double3 aricraftPoint = new double3(currentLocation.CurrentLon, currentLocation.CurrentLat,
- currentLocation.CurrentHei);
- double3 targetPoint = new double3(FlightPlanEditor.targetpoint[0].TargetPointLongitude,
- FlightPlanEditor.targetpoint[0].TargetPointLatitude,
- FlightPlanEditor.targetpoint[0].TargetPointHeight);
- var wind = SeaSJ.GetWindVelocityFromAPI(nCread, currentLocation.CurrentLat, currentLocation.CurrentLon,
- temptime);
- var windSpeed = Math.Sqrt(wind[0] * wind[0] + wind[1] * wind[1]);
-
- var waveHigh = SeaSJ.GetWaveHeightFromAPI(nCread, currentLocation.CurrentLon,
- currentLocation.CurrentLat, temptime);
- var distance = Utils.Util.GetDistance(currentLocation.CurrentLon,targetPoint.x, currentLocation.CurrentLat,
- targetPoint.y);
- Log.Info("距离:====================" + distance);
- if (distance < 20)
- {
- probability = helper.getProbability(aricraftPoint, targetPoint, currentLocation.CurrentCourse,
- windSpeed, waveHigh, "落水人员", "海上");
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- finalProbability *= (1 - probability);
- Console.WriteLine(
- $"海上任务:{taskContent.missionInformation.MissionName} 机型: {AircraftId} 当前时间:{temptime},当前位置:{currentLocation.CurrentLon},{currentLocation.CurrentLat},{currentLocation.CurrentHei},概率:{probability},最终概率:{1 - finalProbability},是否看到落水人员:{isseefire}");
- double randomValue = random.NextDouble();
- if (randomValue < (1 - finalProbability))
- {
- isseefire = true;
- fireIndex = currentLocation.Currentsegnum;
- IsOver = true;
- }
- else
- {
- isseefire = false;
- }
-
- temptime += 1;
- } while (!isseefire && IsOver == false);
- finalProbability = 1 - finalProbability;
- if (fireIndex != -1)
- {
-
- TurningPoints.RemoveRange(fireIndex + 1, TurningPoints.Count - fireIndex - 1);
- MissionPoint missionPoint = new MissionPoint
- {
- MissionPointLongitude = currentLocation.CurrentLon,
- MissionPointLatitude = currentLocation.CurrentLat,
- MissionPointHeight = currentLocation.CurrentHei
- };
- FXJHGenerate.SeaSouJiu2(FlightPlanEditor, missionPoint, ref TurningPoints);
-
- FXJHGenerate.FromMissionToEnd(FlightPlanEditor, MissionEndPoint, ref TurningPoints);
- }
- FXJHGenerate.FXJHTPDiedai(FlightPlanEditor, ref TurningPoints, Velocitys, FuelConsumptions);
- End();
- });
- }
- public override void End()
- {
- for (int i = 0; i < TurningPoints.Count - 2; i++)
- {
- EffMisTime += TurningPoints[i].SegmentFlightTime;
- }
- for (int i = 0; i < TurningPoints.Count - 3; i++)
- {
- SearchTime += TurningPoints[i].SegmentFlightTime;
- }
- for (int i = 0; i < TurningPoints.Count; i++)
- {
- TotalTime += TurningPoints[i].SegmentFlightTime;
- }
- TotalFuelConsumption = TurningPoints[0].RemainingFuel -
- TurningPoints[TurningPoints.Count - 1].RemainingFuel;
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- }
- }
- [ObjectSystem]
- public class AircraftSJAwakeSystem : AwakeSystem<AircraftSJ, FlightPlanEditor>
- {
- public override void Awake(AircraftSJ self, FlightPlanEditor flightPlanEditor)
- {
- self.FlightPlanEditor = flightPlanEditor;
- self.helper = new EquationHelper(HttpInterface.baseUrl);
- self.Awake();
- }
- }
|