123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532 |
- using KYFramework;
- using Model;
- using MongoDB.Bson;
- using MuShiApp;
- using Org.BouncyCastle.Asn1.Pkcs;
- using SimulationCommon;
- using SimulationSingleServer.Utils;
- using System.Threading;
- 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;
- public bool isseePerson = false;
- private int fireIndex = -1;
- public EquationHelper helper;
- public SeaSouJiuTask taskContent;
- public bool Success = false;
- public GetNCData getNCData;
- public double resulttime;
- public SearchMissionPayload searchMissionPayload;
-
-
-
- public SearchMissionMode SearchMode;
- int Days;
- int Hour;
- public int targetCount;
- public bool isEndWhile;
- public int sbCount;
- public double seaArea;
- public bool isReadNC;
- Text_readNC text_ReadNC;
- public override void Reset()
- {
- base.Reset();
- IsOver = false;
- isseePerson = false;
- Success = false;
- SearchTime = 0;
- TotalTime = 0;
- resulttime = 0;
- isEndWhile = false;
- targetCount = 0;
- sbCount = 0;
- seaArea = 0;
- }
- public override void Start()
- {
- if (FlightPlanEditor.targetpoint[0].TargetType.Type == "落水人员")
- {
- targetCount = FlightPlanEditor.targetpoint[0].TargetType.Count;
- sbCount = targetCount;
- }
- else
- sbCount = 1;
- 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 };
-
- double[] initialPosition =
- {
- FlightPlanEditor.targetpoint[0].TargetPointLatitude, FlightPlanEditor.targetpoint[0].TargetPointLongitude
- };
- double dt = 1;
- double totalTime = 24.0;
- if (!isReadNC)
- {
-
-
- text_ReadNC = new Text_readNC();
- text_ReadNC.initlatitudes = FlightPlanEditor.targetpoint[0].TargetPointLatitude;
- text_ReadNC.initlongitudes = FlightPlanEditor.targetpoint[0].TargetPointLongitude;
-
- bool isSuccess = false;
- while(!isSuccess)
- {
- isSuccess = text_ReadNC.GetNCData();
- }
- bool isSuccess2 = false;
- while (!isSuccess2)
- {
- isSuccess2 = text_ReadNC.GetWaveHighData();
- }
-
-
- getNCData = new GetNCData();
- getNCData.initlatitudes = FlightPlanEditor.targetpoint[0].TargetPointLatitude;
- getNCData.initlongitudes = FlightPlanEditor.targetpoint[0].TargetPointLongitude;
- bool isSuccess3 = false;
- while(!isSuccess3)
- {
- isSuccess3 = getNCData.GetData();
- }
- isReadNC = true;
- }
- var nCread = text_ReadNC.windNCread;
-
- List<double[]> trajectory = SeaSJ.CalculateDriftTrajectory(nCread, initialPosition, dt, totalTime, text_ReadNC.times, text_ReadNC.latitudes, text_ReadNC.longitudes, text_ReadNC.times1, text_ReadNC.latitudes1, text_ReadNC.longitudes1, text_ReadNC.times2, text_ReadNC.latitudes2, text_ReadNC.longitudes2, text_ReadNC.times3, text_ReadNC.latitudes3, text_ReadNC.longitudes3, Days, Hour, text_ReadNC.initlatitudes, text_ReadNC.initlongitudes);
-
-
-
-
-
- MissionEndPoint = new MissionEndPoint
- {
- MissionEndPointLongitude = trajectory[^1][1],
- MissionEndPointLatitude = trajectory[^1][0],
- MissionEndPointHeight = 0
- };
- var temp = SeaSJ.getminEnclosingRect(trajectory);
- seaArea = Rectangular_Area_Search_Function.min_area;
-
- 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 (SearchMode.SearchMode == "平行线搜索")
- {
- waypoints = ParallellineSearch.parallellineSearch(basePoint, points, SearchMode.SearchWidth);
- }
- if (SearchMode.SearchMode == "扇形搜索")
- {
-
- var startPoint1 = new Point
- {
- lat = points[0].lat / 2 + points[1].lat / 2,
- lon = points[0].lon / 2 + points[1].lon / 2
- };
- var startPoint2 = new Point
- {
- lat = points[2].lat / 2 + points[3].lat / 2,
- lon = points[2].lon / 2 + points[3].lon / 2
- };
- var centerPoint = new Point
- {
- lat = startPoint1.lat / 2 + startPoint2.lat / 2,
- lon = startPoint1.lon / 2 + startPoint2.lon / 2
- };
- waypoints = SectorSearch.sectorSearch(centerPoint, 30, SearchMode.SearchWidth);
- }
- if (SearchMode.SearchMode == "扩展矩形搜索")
- {
-
- var startPoint1 = new Point
- {
- lat = points[0].lat / 2 + points[1].lat / 2,
- lon = points[0].lon / 2 + points[1].lon / 2
- };
-
- var startPoint2 = new Point
- {
- lat = points[2].lat / 2 + points[3].lat / 2,
- lon = points[2].lon / 2 + points[3].lon / 2
- };
-
- var centerPoint = new Point
- {
- lat = startPoint1.lat / 2 + startPoint2.lat / 2,
- lon = startPoint1.lon / 2 + startPoint2.lon / 2
- };
-
-
- var lonD = Math.Abs(points[0].lon - points[1].lon);
- var latD1 = Math.Abs(points[1].lat - points[2].lat);
- var max = Math.Max(lonD, latD1);
-
-
- var temp0 = new Point(centerPoint.lat + max / 2, centerPoint.lon - max / 2);
- var temp1 = new Point(centerPoint.lat + max / 2, centerPoint.lon + max / 2);
- var temp2 = new Point(centerPoint.lat - max / 2, centerPoint.lon + max / 2);
- var temp3 = new Point(centerPoint.lat - max / 2, centerPoint.lon - max / 2);
-
-
-
-
-
- waypoints = TZFX.GenerateWaypoints(temp0, temp1, temp2, temp3, max, SearchMode.SearchWidth);
- }
-
-
-
-
-
- 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);
-
-
-
-
- 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);
-
- 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 date = year + "-" + month + "-" + day;
-
-
- var vis = helper.getVisibilityByDb(targetPoint.x, targetPoint.y, date);
-
-
-
-
-
-
-
-
- Task.Run(() =>
- {
- bool isseePerson = false;
- double temptime = 0;
- CurrentLocation currentLocation = new CurrentLocation();
- double probability = 0;
- double finalProbability = 1.0;
- Random random = new Random();
- int fireIndex = -1;
- double windSpeed = 0;
- do
- {
- if (!isseePerson && temptime >= time)
- {
- FXJHGenerate.SeaSouJiu(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);
- 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, text_ReadNC.times, text_ReadNC.latitudes, text_ReadNC.longitudes, text_ReadNC.times1, text_ReadNC.latitudes1, text_ReadNC.longitudes1, Days, Hour);
- windSpeed = Math.Sqrt(wind[0] * wind[0] + wind[1] * wind[1]);
- var waveHigh = SeaSJ.GetWaveHeightFromAPI(nCread, currentLocation.CurrentLon,
- currentLocation.CurrentLat, temptime, text_ReadNC.times4, text_ReadNC.latitudes4, text_ReadNC.longitudes4, Days, Hour);
- var distance = Utils.Util.GetDistance(currentLocation.CurrentLon, targetPoint.x,
- currentLocation.CurrentLat,
- targetPoint.y);
-
- Log.Info("距离:====================" + distance);
-
- if (searchMissionPayload.SearchPayload == "雷达搜索")
- {
-
- probability = helper.GetRadarPossibility(0.5, Math.Pow(10, -6), Math.Pow(10, -6), 23645, aricraftPoint, FlightPlanEditor.targetpoint[0], FlightPlanEditor.targetpoint[0].TargetType.RadarArea, 5000, vis);
- }
- else if (searchMissionPayload.SearchPayload == "目视搜索")
- {
- probability = helper.GetMushiSeaProbability(aricraftPoint, vis, waveHigh, FlightPlanEditor.targetpoint[0]);
- }
- else if (searchMissionPayload.SearchPayload == "光电(红外)搜索")
- {
-
- 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));
- }
-
-
-
-
- Log.Info(
- $"海上任务:{taskContent.missionInformation.MissionName} 机型: {AircraftId} 当前时间:{temptime},当前位置:{currentLocation.CurrentLon},{currentLocation.CurrentLat},{currentLocation.CurrentHei},概率:{probability},是否看到目标:{isseePerson}");
- double randomValue = random.NextInt64(9006, 10000);
-
- randomValue /= 10000;
-
- if (randomValue < probability)
- {
- isseePerson = true;
- this.isseePerson = true;
- fireIndex = currentLocation.Currentsegnum;
-
- isEndWhile = true;
- }
- else
- {
- isseePerson = false;
- }
- if (temptime >= taskContent.missionInformation.TaskEndConditions.TaskTime)
- {
-
- isEndWhile = true;
- isseePerson = false;
- fireIndex = currentLocation.Currentsegnum;
- }
- temptime += 10;
- } while (!isseePerson && !isEndWhile);
-
- 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 == "落水人员")
- {
- 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 = SurvivalTimeModel.SurvivalTime(getNCData.tempreadNC, latitude, longitude, time, text_ReadNC.times, text_ReadNC.latitudes, text_ReadNC.longitudes, Days, Hour);
-
- resulttime = get_result_time_rope(30, FlightPlanEditor.targetpoint[0].TargetType.Count, windSpeed, vis, 0.75, 1.38).time;
- Console.WriteLine("resulttime:" + resulttime);
- if (survivalTime * 3600 > seeTime)
- {
- Success = true;
- }
-
-
- }
- }
-
-
- Log.Info(
- $"海上任务:{taskContent.missionInformation.MissionName} 机型: {AircraftId} 当前时间:{temptime},当前位置:{currentLocation.CurrentLon},{currentLocation.CurrentLat},{currentLocation.CurrentHei},概率:{probability},是否看到目标:{isseePerson},人员是否幸存:{Success}");
- 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 AircraftSJAwakeSystem : AwakeSystem<AircraftSJ, FlightPlanEditor>
- {
- public override void Awake(AircraftSJ self, FlightPlanEditor flightPlanEditor)
- {
- self.FlightPlanEditor = flightPlanEditor;
- self.helper = new EquationHelper(HttpInterface.baseUrl);
- self.Awake();
- }
- }
|