AircraftXCJJ.cs 13 KB

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