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; using QuYuSaoMiao; using System.Threading; namespace SimulationServer; public class AircraftLandSJ : AircraftEntity { public bool IsOver; public LandSouXunTask taskContent; public EquationHelper helper; public GetNCData getNCData; public bool isseePerson = false; public MissionEndPoint MissionEndPoint; public SearchMissionMode SearchMissionMode; public bool Success = false; //本目标搜救是否成功 public SearchMissionPayload searchMissionPayload; public double resulttime; int Days; int Hour; public bool isEndWhile; public int targetCount; public int sbCount; public double landArea; public bool isReadNC; Text_readNC text_ReadNC; public override void Reset() { base.Reset(); IsOver = false; isseePerson = false; Success = false; SearchTime = 0; TotalTime = 0; isEndWhile = false; resulttime = 0; targetCount = 0; sbCount = 0; landArea = 0; } public override void Start() { if (FlightPlanEditor.targetpoint[0].TargetType.Type == "遇险人员") { targetCount = FlightPlanEditor.targetpoint[0].TargetType.Count; sbCount = targetCount; } else sbCount = 1; landArea = SearchMissionMode.LandArea; int Year = Convert.ToInt32(taskContent.missionInformation.StartDate.Split("年")[0]); int Month = Convert.ToInt32(taskContent.missionInformation.StartDate.Split("年")[1].Split("月")[0]); int Day = Convert.ToInt32(taskContent.missionInformation.StartDate.Split("年")[1].Split("月")[1].Split("日")[0]); Hour = Convert.ToInt32(taskContent.missionInformation.StartTime.Split("时")[0]); Days = GetDaysInYear(Year, Month, Day); Velocitys = new double[5] { 220, 220, 60, 110, 0 }; // 速度 List route = new List(); if (SearchMissionMode.SearchMode == "扇形搜索") { List trajectory = new List(); foreach (var item in SearchMissionMode.Poly) { trajectory.Add(new double[] { item[1],item[0] }); } var points = SeaSJ.getminEnclosingRect(trajectory); var startPoint1 = new Point { lat = points[0][0] / 2 + points[1][0] / 2, lon = points[0][1] / 2 + points[1][1] / 2 }; var startPoint2 = new Point { lat = points[2][0] / 2 + points[3][0] / 2, lon = points[2][1] / 2 + points[3][1] / 2 }; var centerPoint = new Point { lat = startPoint1.lat / 2 + startPoint2.lat / 2, lon = startPoint1.lon / 2 + startPoint2.lon / 2 }; List temp = SectorSearch.sectorSearch(centerPoint, 30, SearchMissionMode.SearchWidth); foreach (Point point in temp) { route.Add(new double[] { point.lon, point.lat,3500 }); } } else if (SearchMissionMode.SearchMode == "等高线搜索") { route = ContourSearch.ContourSearch1(SearchMissionMode.Poly, SearchMissionMode.interval, SearchMissionMode.MinLength, SearchMissionMode.TrueH, SearchMissionMode.JG, ContourSearch.DemHelper()); } // route 转成 List List airRoutes = new List(); foreach (var item in route) { airRoutes.Add(new AirRoute { AirRouteLatitude = item[1], AirRouteLongitude = item[0], AirRouteHeight = item[2] }); } FlightPlanEditor.airroute = airRoutes.ToArray(); FlightPlanEditor.missionpoint = new MissionPoint() { MissionPointLongitude = FlightPlanEditor.airroute[0].AirRouteLongitude, MissionPointLatitude = FlightPlanEditor.airroute[0].AirRouteLatitude, MissionPointHeight = FlightPlanEditor.airroute[0].AirRouteHeight }; FXJHGenerate.FromStartToMission(FlightPlanEditor, ref TurningPoints); //生成从起点到任务段起点的航路点 // TODO 与王子涵确认这个方法 FXJHGenerate.LandSouJiu(FlightPlanEditor, ref TurningPoints); FXJHGenerate.FXJHTPDiedai(FlightPlanEditor, ref TurningPoints, Velocitys, FuelConsumptions); double time = 0; // 第一次 搜寻结束 for (int i = 0; i < TurningPoints.Count - 2; i++) { time += TurningPoints[i].SegmentFlightTime; } double3 targetPoint = new double3(FlightPlanEditor.targetpoint[0].TargetPointLongitude, FlightPlanEditor.targetpoint[0].TargetPointLatitude, FlightPlanEditor.targetpoint[0].TargetPointHeight); string cityName = helper.getCityName(targetPoint.x, targetPoint.y); //var visibility = helper.getVisibility(cityName, DateTime.Now.ToString("yyyy-MM-dd HH")); string year = taskContent.missionInformation.StartDate.Split("年")[0]; string month = taskContent.missionInformation.StartDate.Split("年")[1].Split("月")[0]; if (Convert.ToInt32(month) < 10) month = "0" + month; string day = taskContent.missionInformation.StartDate.Split("年")[1].Split("月")[1].Split("日")[0]; if (Convert.ToInt32(day) < 10) day = "0" + day; //string hour = taskContent.missionInformation.StartTime.Split("时")[0]; string date = year + "-" + month + "-" + day;// + " " + hour; //Console.Write(date); //Console.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH")); var visibility = helper.getVisibilityByDb(targetPoint.x, targetPoint.y, date); //DateTime.Now.ToString("yyyy-MM-dd HH") //getNCData = new GetNCData(); //getNCData.initlatitudes = FlightPlanEditor.targetpoint[0].TargetPointLatitude; //getNCData.initlongitudes = FlightPlanEditor.targetpoint[0].TargetPointLongitude; //getNCData.GetData(); Task.Run(() => { bool isseePerson = false; double temptime = 0; // 自增时间,每次增加1s CurrentLocation currentLocation = new CurrentLocation(); double probability = 0; double finalProbability = 1.0; Random random = new Random(); int fireIndex = -1; // 记录发现火点的位置 //IsOver = true; do { if (!isseePerson && temptime >= time) { FXJHGenerate.LandSouJiu(FlightPlanEditor, ref TurningPoints); FXJHGenerate.FXJHTPDiedai(FlightPlanEditor, ref TurningPoints, Velocitys, FuelConsumptions); time = 0; for (int i = 0; i < TurningPoints.Count - 2; i++) { time += TurningPoints[i].SegmentFlightTime; } Log.Info($"+++++++++++搜寻结束 TurningPoints Count: {TurningPoints.Count} 下次结束的时间 {time}++++++++++++++++"); } (currentLocation, _) = FXJHGenerate.GetAllCurrentLocation(TurningPoints, temptime); // 获取飞机当前位置 double3 aricraftPoint = new double3(currentLocation.CurrentLon, currentLocation.CurrentLat, currentLocation.CurrentHei); var distance = Utils.Util.GetDistance(currentLocation.CurrentLon, targetPoint.x, currentLocation.CurrentLat, targetPoint.y); Log.Info("距离:====================" + distance); if (searchMissionPayload.SearchPayload == "雷达搜索") { // Pd0 = 0.5 / Pf0 = Math.Pow(10,-6) / Pf = Math.Pow(10,-6) / R0 = 23645 / sigma0 = 5000 / sigma = Editor雷达截面面积 // R 单位m probability = helper.GetRadarPossibility(0.5, Math.Pow(10, -6), Math.Pow(10, -6), 23645, aricraftPoint, FlightPlanEditor.targetpoint[0], FlightPlanEditor.targetpoint[0].TargetType.RadarArea, 5000, visibility); } else if (searchMissionPayload.SearchPayload == "目视搜索") { probability = helper.GetMushiLandProbability(aricraftPoint, visibility, FlightPlanEditor.targetpoint[0]); } else if (searchMissionPayload.SearchPayload == "光电(红外)搜索") { // Lt = 探测目标亮度 Editor / At = 探测目标面积 Editor / τa = 1 / Lb = 3 / A0 = 1 / D0 = 0.075 / Dstar = 3 / τo = 0.8 / Ad = 0.0073728 / Δf = 0.125 / δ = 0.5 / Pf0 = Math.Pow(10, -6); probability = helper.GetInfraredDetectionProbability(FlightPlanEditor.targetpoint[0].TargetType.TargetBrightness, FlightPlanEditor.targetpoint[0].TargetType.TargetArea, 1, 3, 1, aricraftPoint, FlightPlanEditor.targetpoint[0], 0.075, 3, 0.8, 0073728, 0.125, 0.5, Math.Pow(10, -6)); } //probability = // helper.GetMushiLandProbability(aricraftPoint, visibility, FlightPlanEditor.targetpoint[0]); //finalProbability *= (1 - probability); if (probability > 0.8) { probability -= 0.5f; probability *= random.NextDouble(); double random1 = random.NextInt64(8000, 9200); // 生成随机数比较概率 调整概率使任务成功率降低 至 5%(0.05) 第一个参数越低概率越低 // 1000 random1 /= 10000; probability += (0.5 * random1); } double randomValue = random.NextInt64(9006, 10000); // 生成随机数比较概率 调整概率使任务成功率降低 至 5%(0.05) 第一个参数越高概率越低 randomValue /= 10000; Log.Info( $"陆上任务:{taskContent.missionInformation.MissionName} 机型: {AircraftId} 当前时间:{temptime},当前位置:{currentLocation.CurrentLon},{currentLocation.CurrentLat},{currentLocation.CurrentHei},概率:{probability},是否看到遇险人员:{isseePerson}"); if (randomValue < probability) // 1 - finalProbability { isseePerson = true; this.isseePerson = true; fireIndex = currentLocation.Currentsegnum; // 记录当前航路点位置 //IsOver = true; isEndWhile = true; //Success = true; //resulttime = get_result_time_rope(30, FlightPlanEditor.targetpoint[0].TargetType.Count, windSpeed, visibility, 0.75, 1.38).time; //调运时间 //Console.WriteLine("resulttime:" + resulttime); } else { isseePerson = false; } temptime += 10; if (temptime >= taskContent.missionInformation.TaskEndConditions.TaskTime) { //IsOver = true; isEndWhile = true; isseePerson = false; fireIndex = currentLocation.Currentsegnum; } } while (!isseePerson && isEndWhile == 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); } if (isseePerson) { double seeTime = 0; if (FlightPlanEditor.targetpoint[0].TargetType.Type == "遇险人员") { if (!isReadNC) { text_ReadNC = new Text_readNC(); text_ReadNC.initlatitudes = FlightPlanEditor.targetpoint[0].TargetPointLatitude; text_ReadNC.initlongitudes = FlightPlanEditor.targetpoint[0].TargetPointLongitude; //text_ReadNC = new Text_readNC(); bool isSuccess = false; while (!isSuccess) { isSuccess = text_ReadNC.GetNCData(); } isReadNC = true; } var nCread = text_ReadNC.windNCread; var wind = SeaSJ.GetWindVelocityFromAPI(nCread, currentLocation.CurrentLat, currentLocation.CurrentLon, temptime, text_ReadNC.times, text_ReadNC.latitudes, text_ReadNC.longitudes, text_ReadNC.times1, text_ReadNC.latitudes1, text_ReadNC.longitudes1, Days, Hour); double windSpeed = Math.Sqrt(wind[0] * wind[0] + wind[1] * wind[1]); for (int i = 0; i < TurningPoints.Count - 1; i++) { seeTime += TurningPoints[i].SegmentFlightTime; } double latitude = FlightPlanEditor.targetpoint[0].TargetPointLatitude; //落水人员纬度;数据测试用 double longitude = FlightPlanEditor.targetpoint[0].TargetPointLongitude; //落水人员经度,数据测试用 double survivalTime = FlightPlanEditor.targetpoint[0].TargetType.LiveTime;//幸存时间 // SHJParameter.person_number = Eidtor里读取 SHJParameter.windspeed Nc/Editor目标气象信息读取时间先取任务初始时间 resulttime = get_result_time_rope(30, FlightPlanEditor.targetpoint[0].TargetType.Count, windSpeed, visibility, 0.75, 1.38).time; //调运时间 Console.WriteLine("resulttime:" + resulttime); //Console.WriteLine("survivalTime:" + survivalTime); if (survivalTime * 3600 > seeTime) { Success = true; } //Log.Info("TotalTime:" + TotalTime); //Log.Info("幸存时间:" + survivalTime); } } //Console.WriteLine( // $"海上任务1:{taskContent.missionInformation.MissionName} 机型: {AircraftId} 当前时间:{temptime},当前位置:{currentLocation.CurrentLon},{currentLocation.CurrentLat},{currentLocation.CurrentHei},概率:{probability},最终概率:{1 - finalProbability},是否看到落水人员:{isseePerson}"); Log.Info( $"陆上任务:{taskContent.missionInformation.MissionName} 机型: {AircraftId} 当前时间:{temptime},当前位置:{currentLocation.CurrentLon},{currentLocation.CurrentLat},{currentLocation.CurrentHei},概率:{probability},是否看到遇险人员:{isseePerson}"); FXJHGenerate.FXJHTPDiedai(FlightPlanEditor, ref TurningPoints, Velocitys, FuelConsumptions); End(); }); } public static handling_result get_result_time_rope(double H, int person_number, double windspeed, double vis, double upspeed, double downspeed) { handling_result result = new handling_result(); if (windspeed < 8 && vis > 3) { result.time = (person_number * H) / downspeed + (person_number * H) / upspeed; result.success = true; } else { result.success = false; } return result; } public static int GetDaysInYear(int year, int month, int day) { int[] daysInMonths = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; if (IsLeapYear(year)) { daysInMonths[1] = 29; } int days = day; for (int i = 0; i < month - 1; i++) { days += daysInMonths[i]; } return days; } public static bool IsLeapYear(int year) { return (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0); } 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; IsOver = true; } } [ObjectSystem] public class AircraftLandSJAwakeSystem : AwakeSystem { public override void Awake(AircraftLandSJ self, FlightPlanEditor flightPlanEditor) { self.FlightPlanEditor = flightPlanEditor; self.helper = new EquationHelper(HttpInterface.baseUrl); self.Awake(); } }