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()
- {
- //TODO 计算 AirRoute[]
- 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);
- // temp 转成 List<Point>
- 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<Point> 转成 List<AirRoute>
- List<AirRoute> airRoutes = new List<AirRoute>();
- foreach (var item in waypoints)
- {
- airRoutes.Add(new AirRoute
- {
- AirRouteLatitude = item.lat,
- AirRouteLongitude = item.lon
- });
- }
- // var distance = Utils.Util.GetDistance(waypoints[0].lon,FlightPlanEditor.targetpoint[0].TargetPointLongitude, waypoints[0].lat,
- // FlightPlanEditor.targetpoint[0].TargetPointLatitude);
- // var distance1 = Utils.Util.GetDistance(waypoints[0].lon,FlightPlanEditor.originbase.BaseLongitude, waypoints[0].lat,
- // FlightPlanEditor.originbase.BaseLatitude);
-
- 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; // 自增时间,每次增加1s
- 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, "落水人员", "海上"); // 计算发现概率,需要其他模型输入 // 计算发现概率,需要其他模型输入
- }
-
-
- // probability = helper.getProbability(aricraftPoint, targetPoint, currentLocation.CurrentCourse,
- // windSpeed, waveHigh, "落水人员", "海上"); // 计算发现概率,需要其他模型输入 // 计算发现概率,需要其他模型输入
-
- // if (taskContent.SearchMode == "雷达搜索")
- // {
- // probability = DectionModel.Radar(taskContent.DetectionWavelength, taskContent.MinDetectionSignal, taskContent.RadarTransmitterPower,taskContent.TransmitAntennaGain, taskContent.ReceiveAntennaGain, taskContent.)
- // }
- //
- // if (taskContent.SearchMode == "光电搜索")
- // {
- // //搜寻目标相对搜救力量的侧向距离
- // probability = DectionModel.GuangDian(taskContent.OpticalTowerHorizontalRange,
- // taskContent.InfraredDetectorFieldAngle, taskContent.FlightHeight,,
- // FlightPlanEditor.cityweather.Visibility);
- // }
- 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;
- }
- // if (temptime >= 7200) IsOver = true;
- 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;
- // GetNCData getNCData = new GetNCData();
- // getNCData.GetData();
- //
- // double time = TotalTime; //time——搜索时间,单位:秒;数据测试用
- //
- // double latitude = FlightPlanEditor.targetpoint[0].TargetPointLatitude; //落水人员纬度;数据测试用
- // double longitude = FlightPlanEditor.targetpoint[0].TargetPointLongitude; //落水人员经度,数据测试用
- //
- // double survivalTime = SurvivalTimeModel.SurvivalTime(getNCData.tempreadNC, latitude, longitude, time); //幸存时间
- //
- //
- //
- // if (survivalTime > time)
- // {
- // Success = true;
- // }
- // else
- // {
- // Success = false;
- // }
- }
- }
- [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();
- }
- }
|