AircraftXCJJ.cs 14 KB

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