AircraftXCJJ.cs 14 KB

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