AircraftXCJJ.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370
  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 = 2; i < 4; 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("单机总油耗", "60"); // ?
  132. reportInfo.Add("单机机场使用情况", Airport + "\r\n" + hospitalAirport);
  133. reportInfo.Add("单机导航使用情况", "1000"); //飞行总距离 ?
  134. for (int i = 0; i < load.Count; i++)
  135. {
  136. if (load[i].Split(":")[0].Contains("装备"))
  137. {
  138. device += load[i].Split(":")[1];
  139. if(i != load.Count - 1)
  140. {
  141. device += "\r\n";
  142. }
  143. }
  144. else if (load[i].Split(":")[0].Contains("药品"))
  145. {
  146. medicine += load[i].Split(":")[1] + "\r\n";
  147. if (i != load.Count - 1)
  148. {
  149. medicine += "\r\n";
  150. }
  151. }
  152. }
  153. //Console.WriteLine("医疗任务设备:" + device);
  154. //Console.WriteLine("医疗药品:" + medicine);
  155. if (device != null)
  156. reportInfo.Add("医疗任务设备", device);
  157. else
  158. reportInfo.Add("医疗任务设备", "");
  159. if (medicine != null)
  160. reportInfo.Add("医疗药品", medicine);
  161. else
  162. reportInfo.Add("医疗药品", "");
  163. reportInfo.Add("任务缓急情况", "紧急");
  164. IsOver = true;
  165. End();
  166. }
  167. static double CalculateTotalEmergencyTime(List<string> diseaseTypes)
  168. {
  169. double totalTime = 0;
  170. // 这里假设有一个方法GetEmergencyTimeFromDatabase,它根据疾病类型从数据库获取急救时间,此处应为从数据库中读取
  171. foreach (var diseaseType in diseaseTypes)
  172. {
  173. double emergencyTime = GetEmergencyTimeFromDatabase(diseaseType);
  174. totalTime += emergencyTime;
  175. }
  176. return totalTime;
  177. }
  178. // 模拟从数据库获取急救时间的方法
  179. static double GetEmergencyTimeFromDatabase(string diseaseType)
  180. {
  181. // 这里应该是实际的数据库查询逻辑
  182. // 但为了示例,我们直接返回一个模拟值
  183. switch (diseaseType)
  184. {
  185. case "aa": //HeartAttack
  186. return 2; // 心脏病急救时间为2分钟
  187. case "bb": //Stroke
  188. return 5; // 中风急救时间为5分钟
  189. case "cc": //Trauma
  190. return 10; // 创伤急救时间为10分钟
  191. case "dd":
  192. return 15;
  193. case "ee":
  194. return 20;
  195. default:
  196. return 0;
  197. }
  198. }
  199. // 假设从前端接收到的数据结构
  200. public class Patient
  201. {
  202. public int Id { get; set; }
  203. public string DiseaseType { get; set; }
  204. public double GoldenHour { get; set; } // 患者的黄金救援时间应由黄金救援时间程序获得
  205. }
  206. public class DiseaseInfo
  207. {
  208. public string DiseaseType { get; set; }
  209. public double MinGoldenHour { get; set; }
  210. public double MaxGoldenHour { get; set; }
  211. }
  212. public class MedicalRescue
  213. {
  214. private static Dictionary<string, DiseaseInfo> diseaseDatabase = new Dictionary<string, DiseaseInfo>
  215. {
  216. { "aa", new DiseaseInfo { DiseaseType = "aa", MinGoldenHour = 1, MaxGoldenHour = 3 } },
  217. { "bb", new DiseaseInfo { DiseaseType = "bb", MinGoldenHour = 2, MaxGoldenHour = 4 } },
  218. { "cc", new DiseaseInfo { DiseaseType = "cc", MinGoldenHour = 3, MaxGoldenHour = 5 } },
  219. { "dd", new DiseaseInfo { DiseaseType = "dd", MinGoldenHour = 4, MaxGoldenHour = 6 } },
  220. { "ee", new DiseaseInfo { DiseaseType = "ee", MinGoldenHour = 5, MaxGoldenHour = 7 } },
  221. // 添加更多疾病类型
  222. };
  223. public static List<Patient> ProcessPatients(List<Patient> patients, Random rand)
  224. {
  225. foreach (var patient in patients)
  226. {
  227. var diseaseInfo = GetDiseaseInfo(patient.DiseaseType); // MinGoldenHour MaxGoldenHour 数据库读取
  228. double goldenHour = GenerateRandomGoldenHour(rand, diseaseInfo.MinGoldenHour, diseaseInfo.MaxGoldenHour);
  229. Console.WriteLine($"Patient ID: {patient.Id}, Disease: {patient.DiseaseType}, Golden Hour: {goldenHour:F2}");
  230. patient.GoldenHour = goldenHour;
  231. }
  232. return patients;
  233. }
  234. public static DiseaseInfo GetDiseaseInfo(string diseaseType)
  235. {
  236. if (diseaseDatabase.ContainsKey(diseaseType))
  237. {
  238. return diseaseDatabase[diseaseType];
  239. }
  240. throw new ArgumentException("Unknown disease type.");
  241. }
  242. public static double GenerateRandomGoldenHour(Random rand, double min, double max)
  243. {
  244. double mu = (max + min) / 2;
  245. double sigma = (max - min) / 6;
  246. var normal = new Normal(mu, sigma);
  247. return normal.Sample();
  248. }
  249. }
  250. // 假设数据库中的疾病优先级信息
  251. public class DiseasePriority
  252. {
  253. public string DiseaseType { get; set; }
  254. public int Priority { get; set; } // 优先级,数字越小优先级越高
  255. }
  256. // 静态类,包含与疾病优先级相关的静态方法
  257. public static class DiseasePriorityService
  258. {
  259. // 数据库查询(实际项目中应该是从数据库读取)
  260. public static List<DiseasePriority> GetDiseasePriorities()
  261. {
  262. return new List<DiseasePriority>
  263. {
  264. new DiseasePriority { DiseaseType = "aa", Priority = 5 },
  265. new DiseasePriority { DiseaseType = "bb", Priority = 4 },
  266. new DiseasePriority { DiseaseType = "cc", Priority = 3 },
  267. new DiseasePriority { DiseaseType = "dd", Priority = 2 },
  268. new DiseasePriority { DiseaseType = "ee", Priority = 5 },
  269. };
  270. }
  271. // 根据疾病类型获取优先级
  272. public static int GetPriority(string diseaseType)
  273. {
  274. var priorities = GetDiseasePriorities().ToDictionary(dp => dp.DiseaseType, dp => dp.Priority);
  275. if (priorities.TryGetValue(diseaseType, out int priority))
  276. {
  277. return priority;
  278. }
  279. return int.MaxValue; // 如果没有找到,返回一个很大的数作为默认优先级
  280. }
  281. }
  282. public string TargetQiXiangInfoSave(string s, int hour)
  283. {
  284. string result = hour.ToString() + "-" + s;
  285. for (int i = 0; i < FlightPlanEditor.medicalTargetPoint[0].TargetQiXiangInfos.Length; i++)
  286. {
  287. }
  288. switch (s)
  289. {
  290. case "温度":
  291. break;
  292. case "湿度":
  293. break;
  294. case "能见度":
  295. break;
  296. case "风速":
  297. break;
  298. case "风向":
  299. break;
  300. case "天气":
  301. break;
  302. }
  303. return result;
  304. }
  305. }
  306. [ObjectSystem]
  307. public class AircraftXCJJAwakeSystem : AwakeSystem<AircraftXCJJ, FlightPlanEditor>
  308. {
  309. public override void Awake(AircraftXCJJ self, FlightPlanEditor flightPlanEditor)
  310. {
  311. self.FlightPlanEditor = flightPlanEditor;
  312. self.Awake();
  313. }
  314. }