AircraftXCJJ.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  1. using KYFramework;
  2. using MathNet.Numerics.Distributions;
  3. using Model;
  4. using MongoDB.Bson;
  5. using SimulationCommon;
  6. using SimulationServer.Utils;
  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 MissionEndPoint hospitalPoint;
  16. public List<double> jiuzhuTimes = new List<double>();
  17. public Dictionary<string, string> reportInfo = new Dictionary<string, string>();
  18. public List<string> load = new List<string>();
  19. public string device;
  20. public string medicine;
  21. public string hospitalAirport;
  22. public override void End()
  23. {
  24. TotalFuelConsumption = TurningPoints[0].RemainingFuel - TurningPoints[^1].RemainingFuel;
  25. }
  26. public override void Reset()
  27. {
  28. base.Reset();
  29. IsOver = false;
  30. Success = false;
  31. TotalTime = 0;
  32. reportInfo = new Dictionary<string, string>();
  33. device = string.Empty;
  34. medicine = string.Empty;
  35. }
  36. public override void Start()
  37. {
  38. FlightPlanEditor.missionpoint.MissionPointLatitude = FlightPlanEditor.medicalTargetPoint[0].TargetPointLatitude;
  39. FlightPlanEditor.missionpoint.MissionPointLongitude = FlightPlanEditor.medicalTargetPoint[0].TargetPointLongitude;
  40. FlightPlanEditor.missionpoint.MissionPointHeight = FlightPlanEditor.medicalTargetPoint[0].TargetPointHeight;
  41. //Console.WriteLine("Latitude:" + FlightPlanEditor.missionpoint.MissionPointLatitude + "_" + "Longitude:" + FlightPlanEditor.missionpoint.MissionPointLongitude + "_" + "Height:" + FlightPlanEditor.missionpoint.MissionPointHeight);
  42. int patientCount = FlightPlanEditor.medicalTargetPoint[0].TargetType.Count; // 伤患人数
  43. List<string> diseaseTypes = new List<string>();
  44. for (int i = 0; i < FlightPlanEditor.medicalTargetPoint[0].TargetType.diseaseTypes.Length; i++)
  45. {
  46. diseaseTypes.Add(FlightPlanEditor.medicalTargetPoint[0].TargetType.diseaseTypes[i]);
  47. }
  48. int medicCount = taskParameter.doctorPersonnel + taskParameter.nursePersonnel + taskParameter.nurseSeverePersonnel;//taskParameter.MedicalStaffCount; // 医护人员数量
  49. //Console.WriteLine("medicCount:" + medicCount);
  50. // 交接时间为5分钟
  51. double handoverTime = 5;
  52. // 计算总急救时间 需要飞机停留时间
  53. double totalEmergencyTime = CalculateTotalEmergencyTime(diseaseTypes);
  54. // 计算平均急救时间(每个医护人员分担的时间)
  55. double averageEmergencyTimePerMedic = totalEmergencyTime / medicCount;
  56. // 计算总时间(平均急救时间 + 交接时间)
  57. double totalTime = averageEmergencyTimePerMedic + handoverTime;
  58. Console.WriteLine($"总急救时间(平均每个医护人员): {averageEmergencyTimePerMedic} 分钟");
  59. Console.WriteLine($"总时间(包括交接时间): {totalTime} 分钟");
  60. Random rand = new Random();
  61. List<Patient> patients = new List<Patient>();
  62. for (int i = 0; i < patientCount; i++)
  63. {
  64. patients.Add(new Patient()
  65. {
  66. Id = i + 1,
  67. DiseaseType = diseaseTypes[i],
  68. GoldenHour = 0
  69. });
  70. }
  71. patients = MedicalRescue.ProcessPatients(patients, rand);
  72. // 对患者进行排序
  73. var sortedPatients = patients.OrderBy(p => DiseasePriorityService.GetPriority(p.DiseaseType))
  74. .ThenBy(p => p.GoldenHour)
  75. .ToList();
  76. // 输出排序后的患者列表 // 从是事故点到医院的飞行时间 + 5分钟的交接时间 < 黄金时间 ? 成功:失败
  77. foreach (var patient in sortedPatients)
  78. {
  79. Console.WriteLine($"sortedPatients ID: {patient.Id}, Disease: {patient.DiseaseType}, Golden Hour: {patient.GoldenHour:F2}");
  80. }
  81. // 注意:实际项目中,每次转运一名伤员的操作可能涉及更多的逻辑,比如更新数据库中的转运状态等。
  82. FXJHGenerate.FromStartToMission(FlightPlanEditor, ref TurningPoints);//生成从起点到任务段起点的航路点
  83. FXJHGenerate.JIJIU(totalTime, FlightPlanEditor, ref TurningPoints);
  84. FXJHGenerate.JIJIU1(5 * 60, hospitalPoint, ref TurningPoints);
  85. for (int i = 0; i < FlightPlanEditor.medicalTargetPoint[0].TargetType.Count - 1; i++)
  86. {
  87. FXJHGenerate.JIJIU(5 * 60, FlightPlanEditor, ref TurningPoints);
  88. FXJHGenerate.JIJIU1(5 * 60, hospitalPoint, ref TurningPoints);
  89. }
  90. FXJHGenerate.FromMissionToEnd(FlightPlanEditor, hospitalPoint, ref TurningPoints);
  91. FXJHGenerate.FXJHTPDiedai(FlightPlanEditor, ref TurningPoints, Velocitys, FuelConsumptions);
  92. double time = 0;
  93. for (int i = 2; i < 5; i++)
  94. {
  95. time += TurningPoints[i].SegmentFlightTime;
  96. }
  97. jiuzhuTimes.Add(time);
  98. int p = 5;
  99. int c = 0;
  100. for (int i = p; i < FlightPlanEditor.medicalTargetPoint[0].TargetType.Count * 4 + 1; i++)
  101. {
  102. time += TurningPoints[i].SegmentFlightTime;
  103. c++;
  104. if (c == 4)
  105. {
  106. jiuzhuTimes.Add(time);
  107. c = 0;
  108. }
  109. }
  110. for (int i = 0; i < TurningPoints.Count; i++) // 总飞行时间
  111. {
  112. TotalTime += TurningPoints[i].SegmentFlightTime; // 总时间 //仿真轮次1 数值1
  113. }
  114. Console.WriteLine("TotalTime:" + TotalTime);
  115. reportInfo.Add("准备时间", TaskReadyTime.ToString());
  116. double reachTime = 0;
  117. for (int i = 0; i < 2; i++)
  118. {
  119. reachTime += TurningPoints[i].SegmentFlightTime;
  120. }
  121. reportInfo.Add("到达时间", reachTime.ToString()); // 基地 -> 目标点
  122. reportInfo.Add("任务周期时间", TotalTime.ToString());
  123. reportInfo.Add("执行任务飞机型号", Name);
  124. reportInfo.Add("执行任务飞机数量", "1");
  125. reportInfo.Add("单机飞行员人数", taskParameter.pilotPersonnel.ToString());
  126. reportInfo.Add("单机医师人数", taskParameter.doctorPersonnel.ToString());
  127. reportInfo.Add("单机护士人数", taskParameter.nursePersonnel.ToString());
  128. reportInfo.Add("单机重症监护护理人员人数", taskParameter.nurseSeverePersonnel.ToString());
  129. reportInfo.Add("单机地面保障人数", taskParameter.groundSupportPersonnel.ToString());
  130. reportInfo.Add("单机总任务时长", TotalTime.ToString());
  131. reportInfo.Add("单机总油耗", FXJHGenerate.CalculateTotalFuelConsumption(FlightPlanEditor, TurningPoints).ToString());
  132. reportInfo.Add("单机机场使用情况", Airport + "\r\n" + hospitalAirport);
  133. double zhc = 0;
  134. for (int i = 0; i < TurningPoints.Count - 1; i++)
  135. {
  136. zhc += Utils.Util.GetDistance(TurningPoints[i].TurningPointLongitude,
  137. TurningPoints[i + 1].TurningPointLongitude, TurningPoints[i].TurningPointLatitude, TurningPoints[i + 1].TurningPointLatitude);
  138. }
  139. reportInfo.Add("单机导航使用情况", zhc.ToString()); //飞行总距离
  140. for (int i = 0; i < load.Count; i++)
  141. {
  142. if (load[i].Split(":")[0].Contains("装备"))
  143. {
  144. device += load[i].Split(":")[1];
  145. if (i != load.Count - 1)
  146. {
  147. device += "\r\n";
  148. }
  149. }
  150. else if (load[i].Split(":")[0].Contains("药品"))
  151. {
  152. medicine += load[i].Split(":")[1] + "\r\n";
  153. if (i != load.Count - 1)
  154. {
  155. medicine += "\r\n";
  156. }
  157. }
  158. }
  159. //Console.WriteLine("医疗任务设备:" + device);
  160. //Console.WriteLine("医疗药品:" + medicine);
  161. if (device != null)
  162. reportInfo.Add("医疗任务设备", device);
  163. else
  164. reportInfo.Add("医疗任务设备", "");
  165. if (medicine != null)
  166. reportInfo.Add("医疗药品", medicine);
  167. else
  168. reportInfo.Add("医疗药品", "");
  169. reportInfo.Add("任务缓急情况", "紧急");
  170. IsOver = true;
  171. End();
  172. }
  173. static double CalculateTotalEmergencyTime(List<string> diseaseTypes)
  174. {
  175. double totalTime = 0;
  176. // 这里假设有一个方法GetEmergencyTimeFromDatabase,它根据疾病类型从数据库获取急救时间,此处应为从数据库中读取
  177. foreach (var diseaseType in diseaseTypes)
  178. {
  179. double emergencyTime = GetEmergencyTimeFromDatabase(diseaseType);
  180. totalTime += emergencyTime;
  181. }
  182. return totalTime;
  183. }
  184. // 模拟从数据库获取急救时间的方法
  185. static double GetEmergencyTimeFromDatabase(string diseaseType)
  186. {
  187. // 这里应该是实际的数据库查询逻辑
  188. // 但为了示例,我们直接返回一个模拟值
  189. switch (diseaseType)
  190. {
  191. case "aa": //HeartAttack
  192. return 2; // 心脏病急救时间为2分钟
  193. case "bb": //Stroke
  194. return 5; // 中风急救时间为5分钟
  195. case "cc": //Trauma
  196. return 10; // 创伤急救时间为10分钟
  197. case "dd":
  198. return 15;
  199. case "ee":
  200. return 20;
  201. default:
  202. return 0;
  203. }
  204. }
  205. // 假设从前端接收到的数据结构
  206. public class Patient
  207. {
  208. public int Id { get; set; }
  209. public string DiseaseType { get; set; }
  210. public double GoldenHour { get; set; } // 患者的黄金救援时间应由黄金救援时间程序获得
  211. }
  212. public class DiseaseInfo
  213. {
  214. public string DiseaseType { get; set; }
  215. public double MinGoldenHour { get; set; }
  216. public double MaxGoldenHour { get; set; }
  217. }
  218. public class MedicalRescue
  219. {
  220. private static Dictionary<string, DiseaseInfo> diseaseDatabase = new Dictionary<string, DiseaseInfo>
  221. {
  222. { "aa", new DiseaseInfo { DiseaseType = "aa", MinGoldenHour = 1, MaxGoldenHour = 3 } },
  223. { "bb", new DiseaseInfo { DiseaseType = "bb", MinGoldenHour = 2, MaxGoldenHour = 4 } },
  224. { "cc", new DiseaseInfo { DiseaseType = "cc", MinGoldenHour = 3, MaxGoldenHour = 5 } },
  225. { "dd", new DiseaseInfo { DiseaseType = "dd", MinGoldenHour = 4, MaxGoldenHour = 6 } },
  226. { "ee", new DiseaseInfo { DiseaseType = "ee", MinGoldenHour = 5, MaxGoldenHour = 7 } },
  227. // 添加更多疾病类型
  228. };
  229. public static List<Patient> ProcessPatients(List<Patient> patients, Random rand)
  230. {
  231. foreach (var patient in patients)
  232. {
  233. var diseaseInfo = GetDiseaseInfo(patient.DiseaseType); // MinGoldenHour MaxGoldenHour 数据库读取
  234. double goldenHour = GenerateRandomGoldenHour(rand, diseaseInfo.MinGoldenHour, diseaseInfo.MaxGoldenHour);
  235. Console.WriteLine($"Patient ID: {patient.Id}, Disease: {patient.DiseaseType}, Golden Hour: {goldenHour:F2}");
  236. patient.GoldenHour = goldenHour;
  237. }
  238. return patients;
  239. }
  240. public static DiseaseInfo GetDiseaseInfo(string diseaseType)
  241. {
  242. if (diseaseDatabase.ContainsKey(diseaseType))
  243. {
  244. return diseaseDatabase[diseaseType];
  245. }
  246. throw new ArgumentException("Unknown disease type.");
  247. }
  248. public static double GenerateRandomGoldenHour(Random rand, double min, double max)
  249. {
  250. double mu = (max + min) / 2;
  251. double sigma = (max - min) / 6;
  252. var normal = new Normal(mu, sigma);
  253. return normal.Sample();
  254. }
  255. }
  256. // 假设数据库中的疾病优先级信息
  257. public class DiseasePriority
  258. {
  259. public string DiseaseType { get; set; }
  260. public int Priority { get; set; } // 优先级,数字越小优先级越高
  261. }
  262. // 静态类,包含与疾病优先级相关的静态方法
  263. public static class DiseasePriorityService
  264. {
  265. // 数据库查询(实际项目中应该是从数据库读取)
  266. public static List<DiseasePriority> GetDiseasePriorities()
  267. {
  268. return new List<DiseasePriority>
  269. {
  270. new DiseasePriority { DiseaseType = "aa", Priority = 5 },
  271. new DiseasePriority { DiseaseType = "bb", Priority = 4 },
  272. new DiseasePriority { DiseaseType = "cc", Priority = 3 },
  273. new DiseasePriority { DiseaseType = "dd", Priority = 2 },
  274. new DiseasePriority { DiseaseType = "ee", Priority = 5 },
  275. };
  276. }
  277. // 根据疾病类型获取优先级
  278. public static int GetPriority(string diseaseType)
  279. {
  280. var priorities = GetDiseasePriorities().ToDictionary(dp => dp.DiseaseType, dp => dp.Priority);
  281. if (priorities.TryGetValue(diseaseType, out int priority))
  282. {
  283. return priority;
  284. }
  285. return int.MaxValue; // 如果没有找到,返回一个很大的数作为默认优先级
  286. }
  287. }
  288. public string TargetQiXiangInfoSave(string s, int hour)
  289. {
  290. string result = hour.ToString() + "-" + s;
  291. for (int i = 0; i < FlightPlanEditor.medicalTargetPoint[0].TargetQiXiangInfos.Length; i++)
  292. {
  293. }
  294. switch (s)
  295. {
  296. case "温度":
  297. break;
  298. case "湿度":
  299. break;
  300. case "能见度":
  301. break;
  302. case "风速":
  303. break;
  304. case "风向":
  305. break;
  306. case "天气":
  307. break;
  308. }
  309. return result;
  310. }
  311. }
  312. [ObjectSystem]
  313. public class AircraftXCJJAwakeSystem : AwakeSystem<AircraftXCJJ, FlightPlanEditor>
  314. {
  315. public override void Awake(AircraftXCJJ self, FlightPlanEditor flightPlanEditor)
  316. {
  317. self.FlightPlanEditor = flightPlanEditor;
  318. self.Awake();
  319. }
  320. }