AircraftXCJJ.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  1. using KYFramework;
  2. using MathNet.Numerics.Distributions;
  3. using Model;
  4. using MongoDB.Bson;
  5. using SimulationCommon;
  6. using static SimulationServer.AircraftXCJJ;
  7. namespace SimulationServer;
  8. public class AircraftXCJJ : AircraftEntity
  9. {
  10. public XCJJTask taskContent;
  11. public MissionEndPoint MissionEndPoint;
  12. public bool IsOver;
  13. public bool Success;
  14. public TaskParameter taskParameter;
  15. public GetNCData getNCData;
  16. public double resulttime;
  17. public bool isReadNC;
  18. Text_readNC text_ReadNC;
  19. public override void End()
  20. {
  21. TotalFuelConsumption = TurningPoints[0].RemainingFuel - TurningPoints[^1].RemainingFuel;
  22. }
  23. public override void Reset()
  24. {
  25. base.Reset();
  26. IsOver = false;
  27. Success = false;
  28. TotalTime = 0;
  29. }
  30. public override void Start()
  31. {
  32. if (!isReadNC)
  33. {
  34. getNCData = new GetNCData();
  35. getNCData.initlatitudes = FlightPlanEditor.medicalTargetPoint[0].TargetPointLatitude;
  36. getNCData.initlongitudes = FlightPlanEditor.medicalTargetPoint[0].TargetPointLongitude;
  37. bool isSuccess3 = false;
  38. while (!isSuccess3)
  39. {
  40. isSuccess3 = getNCData.GetData();
  41. }
  42. text_ReadNC = new Text_readNC();
  43. text_ReadNC.initlatitudes = FlightPlanEditor.medicalTargetPoint[0].TargetPointLatitude;
  44. text_ReadNC.initlongitudes = FlightPlanEditor.medicalTargetPoint[0].TargetPointLongitude;
  45. //text_ReadNC = new Text_readNC();
  46. bool isSuccess = false;
  47. while (!isSuccess)
  48. {
  49. isSuccess = text_ReadNC.GetNCData();
  50. }
  51. isReadNC = true;
  52. }
  53. int hour = Convert.ToInt32(taskContent.missionInformation.StartTime.Split("时")[0]);
  54. int Day = Convert.ToInt32(taskContent.missionInformation.StartDate.Split("年")[1].Split("月")[1].Split("日")[0]);
  55. ////Console.WriteLine("hour:" + hour);
  56. //double windSpeed = Convert.ToDouble(TargetQiXiangInfoSave("风速", hour));
  57. ////Console.WriteLine("windSpeed:" + windSpeed);
  58. //double vis = Convert.ToDouble(TargetQiXiangInfoSave("能见度", hour));
  59. ////Console.WriteLine("vis:" + vis);
  60. FlightPlanEditor.missionpoint.MissionPointLatitude = FlightPlanEditor.medicalTargetPoint[0].TargetPointLatitude;
  61. FlightPlanEditor.missionpoint.MissionPointLongitude = FlightPlanEditor.medicalTargetPoint[0].TargetPointLongitude;
  62. FlightPlanEditor.missionpoint.MissionPointHeight = FlightPlanEditor.medicalTargetPoint[0].TargetPointHeight;
  63. Console.WriteLine("Latitude:" + FlightPlanEditor.missionpoint.MissionPointLatitude + "_" + "Longitude:" + FlightPlanEditor.missionpoint.MissionPointLongitude + "_" + "Height:" + FlightPlanEditor.missionpoint.MissionPointHeight);
  64. FXJHGenerate.FromStartToMission(FlightPlanEditor, ref TurningPoints);//生成从起点到任务段起点的航路点
  65. //// 吊运上升速度 吊运下降速度 Task文件读取 // Editor里读天气根据时间
  66. //resulttime = get_result_time_rope(taskParameter.Height, taskParameter.liftPersonnel, windSpeed, vis, taskParameter.liftUpSpeed, taskParameter.liftDownSpeed).time;//索滑降模型输出的索滑降时间
  67. //Console.WriteLine("resulttime:" + resulttime);
  68. //FXJHGenerate.SuoHuaJiang(resulttime, FlightPlanEditor, ref TurningPoints);
  69. FXJHGenerate.FromMissionToEnd(FlightPlanEditor, FXJHGenerate.SuoHuaJiangMissionEndPoint(FlightPlanEditor), ref TurningPoints);
  70. FXJHGenerate.FXJHTPDiedai(FlightPlanEditor, ref TurningPoints, Velocitys, FuelConsumptions);
  71. // 飞到目标点时间与人员存活时间做对比 有一个人活着,整个任务成功
  72. double time = 0;
  73. for (int i = 0; i < TurningPoints.Count - 1; i++)
  74. {
  75. time += TurningPoints[i].SegmentFlightTime; // 判断幸存-1
  76. }
  77. //Console.WriteLine("time:" + time);
  78. // 假设前端输入
  79. int patientCount = FlightPlanEditor.medicalTargetPoint[0].TargetType.Count; // 伤患人数
  80. List<string> diseaseTypes = new List<string>();
  81. for (int i = 0; i < FlightPlanEditor.medicalTargetPoint[0].TargetType.diseaseTypes.Length; i++)
  82. {
  83. diseaseTypes.Add(FlightPlanEditor.medicalTargetPoint[0].TargetType.diseaseTypes[i]);
  84. }
  85. int medicCount = taskParameter.MedicalStaffCount; // 医护人员数量
  86. // 交接时间为5分钟
  87. double handoverTime = 5;
  88. // 计算总急救时间
  89. double totalEmergencyTime = CalculateTotalEmergencyTime(diseaseTypes);
  90. // 计算平均急救时间(每个医护人员分担的时间)
  91. double averageEmergencyTimePerMedic = totalEmergencyTime / medicCount;
  92. // 计算总时间(平均急救时间 + 交接时间)
  93. double totalTime = averageEmergencyTimePerMedic + handoverTime;
  94. Console.WriteLine($"总急救时间(平均每个医护人员): {averageEmergencyTimePerMedic} 分钟");
  95. Console.WriteLine($"总时间(包括交接时间): {totalTime} 分钟");
  96. Random rand = new Random();
  97. List<Patient> patients = new List<Patient>();
  98. for (int i = 0; i < patientCount; i++)
  99. {
  100. patients.Add(new Patient()
  101. {
  102. Id = i + 1,
  103. DiseaseType = diseaseTypes[i],
  104. GoldenHour = 0
  105. });
  106. }
  107. patients = MedicalRescue.ProcessPatients(patients, rand);
  108. // 对患者进行排序
  109. var sortedPatients = patients.OrderBy(p => DiseasePriorityService.GetPriority(p.DiseaseType))
  110. .ThenBy(p => p.GoldenHour)
  111. .ToList();
  112. // 输出排序后的患者列表 // 从是事故点到医院的飞行时间 + 5分钟的交接时间 < 黄金时间 ? 成功:失败
  113. foreach (var patient in sortedPatients)
  114. {
  115. Console.WriteLine($"sortedPatients ID: {patient.Id}, Disease: {patient.DiseaseType}, Golden Hour: {patient.GoldenHour:F2}");
  116. }
  117. // 注意:实际项目中,每次转运一名伤员的操作可能涉及更多的逻辑,比如更新数据库中的转运状态等。
  118. for (int i = 0; i < TurningPoints.Count; i++) // 总飞行时间
  119. {
  120. TotalTime += TurningPoints[i].SegmentFlightTime; // 总时间 //仿真轮次1 数值1
  121. }
  122. Console.WriteLine("TotalTime:" + TotalTime);
  123. IsOver = true;
  124. End();
  125. }
  126. static double CalculateTotalEmergencyTime(List<string> diseaseTypes)
  127. {
  128. double totalTime = 0;
  129. // 这里假设有一个方法GetEmergencyTimeFromDatabase,它根据疾病类型从数据库获取急救时间,此处应为从数据库中读取
  130. foreach (var diseaseType in diseaseTypes)
  131. {
  132. double emergencyTime = GetEmergencyTimeFromDatabase(diseaseType);
  133. totalTime += emergencyTime;
  134. }
  135. return totalTime;
  136. }
  137. // 模拟从数据库获取急救时间的方法
  138. static double GetEmergencyTimeFromDatabase(string diseaseType)
  139. {
  140. // 这里应该是实际的数据库查询逻辑
  141. // 但为了示例,我们直接返回一个模拟值
  142. switch (diseaseType)
  143. {
  144. case "aa": //HeartAttack
  145. return 2; // 心脏病急救时间为2分钟
  146. case "bb": //Stroke
  147. return 5; // 中风急救时间为5分钟
  148. case "cc": //Trauma
  149. return 10; // 创伤急救时间为10分钟
  150. case "dd":
  151. return 15;
  152. case "ee":
  153. return 20;
  154. default:
  155. return 0;
  156. }
  157. }
  158. // 假设从前端接收到的数据结构
  159. public class Patient
  160. {
  161. public int Id { get; set; }
  162. public string DiseaseType { get; set; }
  163. public double GoldenHour { get; set; } // 患者的黄金救援时间应由黄金救援时间程序获得
  164. }
  165. public class DiseaseInfo
  166. {
  167. public string DiseaseType { get; set; }
  168. public double MinGoldenHour { get; set; }
  169. public double MaxGoldenHour { get; set; }
  170. }
  171. public class MedicalRescue
  172. {
  173. private static Dictionary<string, DiseaseInfo> diseaseDatabase = new Dictionary<string, DiseaseInfo>
  174. {
  175. { "aa", new DiseaseInfo { DiseaseType = "aa", MinGoldenHour = 1, MaxGoldenHour = 3 } },
  176. { "bb", new DiseaseInfo { DiseaseType = "bb", MinGoldenHour = 2, MaxGoldenHour = 4 } },
  177. { "cc", new DiseaseInfo { DiseaseType = "cc", MinGoldenHour = 3, MaxGoldenHour = 5 } },
  178. { "dd", new DiseaseInfo { DiseaseType = "dd", MinGoldenHour = 4, MaxGoldenHour = 6 } },
  179. { "ee", new DiseaseInfo { DiseaseType = "ee", MinGoldenHour = 5, MaxGoldenHour = 7 } },
  180. // 添加更多疾病类型
  181. };
  182. public static List<Patient> ProcessPatients(List<Patient> patients, Random rand)
  183. {
  184. foreach (var patient in patients)
  185. {
  186. var diseaseInfo = GetDiseaseInfo(patient.DiseaseType); // MinGoldenHour MaxGoldenHour 数据库读取
  187. double goldenHour = GenerateRandomGoldenHour(rand, diseaseInfo.MinGoldenHour, diseaseInfo.MaxGoldenHour);
  188. Console.WriteLine($"Patient ID: {patient.Id}, Disease: {patient.DiseaseType}, Golden Hour: {goldenHour:F2}");
  189. patient.GoldenHour = goldenHour;
  190. }
  191. return patients;
  192. }
  193. public static DiseaseInfo GetDiseaseInfo(string diseaseType)
  194. {
  195. if (diseaseDatabase.ContainsKey(diseaseType))
  196. {
  197. return diseaseDatabase[diseaseType];
  198. }
  199. throw new ArgumentException("Unknown disease type.");
  200. }
  201. public static double GenerateRandomGoldenHour(Random rand, double min, double max)
  202. {
  203. double mu = (max + min) / 2;
  204. double sigma = (max - min) / 6;
  205. var normal = new Normal(mu, sigma);
  206. return normal.Sample();
  207. }
  208. }
  209. // 假设数据库中的疾病优先级信息
  210. public class DiseasePriority
  211. {
  212. public string DiseaseType { get; set; }
  213. public int Priority { get; set; } // 优先级,数字越小优先级越高
  214. }
  215. // 静态类,包含与疾病优先级相关的静态方法
  216. public static class DiseasePriorityService
  217. {
  218. // 数据库查询(实际项目中应该是从数据库读取)
  219. public static List<DiseasePriority> GetDiseasePriorities()
  220. {
  221. return new List<DiseasePriority>
  222. {
  223. new DiseasePriority { DiseaseType = "aa", Priority = 5 },
  224. new DiseasePriority { DiseaseType = "bb", Priority = 4 },
  225. new DiseasePriority { DiseaseType = "cc", Priority = 3 },
  226. new DiseasePriority { DiseaseType = "dd", Priority = 2 },
  227. new DiseasePriority { DiseaseType = "ee", Priority = 5 },
  228. };
  229. }
  230. // 根据疾病类型获取优先级
  231. public static int GetPriority(string diseaseType)
  232. {
  233. var priorities = GetDiseasePriorities().ToDictionary(dp => dp.DiseaseType, dp => dp.Priority);
  234. if (priorities.TryGetValue(diseaseType, out int priority))
  235. {
  236. return priority;
  237. }
  238. return int.MaxValue; // 如果没有找到,返回一个很大的数作为默认优先级
  239. }
  240. }
  241. // 吊运函数
  242. public static handling_result get_result_time_rope(double H, int person_number, double windspeed, double vis, double upspeed, double downspeed)
  243. {
  244. handling_result result = new handling_result();
  245. if (windspeed < 8 && vis > 3)
  246. {
  247. result.time = (person_number * H) / downspeed + (person_number * H) / upspeed;
  248. result.success = true;
  249. }
  250. else
  251. {
  252. result.success = false;
  253. }
  254. return result;
  255. }
  256. public string TargetQiXiangInfoSave(string s, int hour)
  257. {
  258. string result = hour.ToString() + "-" + s;
  259. for (int i = 0; i < FlightPlanEditor.medicalTargetPoint[0].TargetQiXiangInfos.Length; i++)
  260. {
  261. }
  262. switch (s)
  263. {
  264. case "温度":
  265. break;
  266. case "湿度":
  267. break;
  268. case "能见度":
  269. break;
  270. case "风速":
  271. break;
  272. case "风向":
  273. break;
  274. case "天气":
  275. break;
  276. }
  277. return result;
  278. }
  279. public static int GetDaysInYear(int year, int month, int day)
  280. {
  281. int[] daysInMonths = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
  282. if (IsLeapYear(year))
  283. {
  284. daysInMonths[1] = 29;
  285. }
  286. int days = day;
  287. for (int i = 0; i < month - 1; i++)
  288. {
  289. days += daysInMonths[i];
  290. }
  291. return days;
  292. }
  293. public static bool IsLeapYear(int year)
  294. {
  295. return (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0);
  296. }
  297. }
  298. [ObjectSystem]
  299. public class AircraftXCJJAwakeSystem : AwakeSystem<AircraftXCJJ, FlightPlanEditor>
  300. {
  301. public override void Awake(AircraftXCJJ self, FlightPlanEditor flightPlanEditor)
  302. {
  303. self.FlightPlanEditor = flightPlanEditor;
  304. self.Awake();
  305. }
  306. }