AircraftYLZY.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  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 AircraftYLZY : AircraftEntity
  9. {
  10. public YLZYTask taskContent;
  11. public MissionEndPoint MissionEndPoint;
  12. public bool IsOver;
  13. public bool Success;
  14. public TaskParameter taskParameter;
  15. public MissionEndPoint hospitalPoint;
  16. public Dictionary<string, string> reportInfo = new Dictionary<string, string>();
  17. public List<string> load = new List<string>();
  18. public string device;
  19. public string medicine;
  20. public string hospitalAirport;
  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; // 医护人员数量
  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. for (int i = 0; i < FlightPlanEditor.medicalTargetPoint[0].TargetType.Count; i++)
  82. {
  83. FXJHGenerate.JIJIU(5 * 60, FlightPlanEditor, ref TurningPoints);
  84. FXJHGenerate.JIJIU1(5 * 60, hospitalPoint, ref TurningPoints);
  85. }
  86. FXJHGenerate.FromMissionToEnd(FlightPlanEditor, hospitalPoint, ref TurningPoints);
  87. FXJHGenerate.FXJHTPDiedai(FlightPlanEditor, ref TurningPoints, Velocitys, FuelConsumptions);
  88. for (int i = 0; i < TurningPoints.Count; i++) // 总飞行时间
  89. {
  90. TotalTime += TurningPoints[i].SegmentFlightTime; // 总时间 //仿真轮次1 数值1
  91. }
  92. Console.WriteLine("TotalTime:" + TotalTime);
  93. reportInfo.Add("准备时间", TaskReadyTime.ToString());
  94. double reachTime = 0;
  95. for (int i = 0; i < 2; i++)
  96. {
  97. reachTime += TurningPoints[i].SegmentFlightTime;
  98. }
  99. reportInfo.Add("到达时间", reachTime.ToString());
  100. reportInfo.Add("任务周期时间", TotalTime.ToString());
  101. reportInfo.Add("执行任务飞机型号", Name);
  102. reportInfo.Add("执行任务飞机数量", "1");
  103. reportInfo.Add("单机飞行员人数", taskParameter.pilotPersonnel.ToString());
  104. reportInfo.Add("单机医师人数", taskParameter.doctorPersonnel.ToString());
  105. reportInfo.Add("单机护士人数", taskParameter.nursePersonnel.ToString());
  106. reportInfo.Add("单机重症监护护理人员人数", taskParameter.nurseSeverePersonnel.ToString());
  107. reportInfo.Add("单机地面保障人数", taskParameter.groundSupportPersonnel.ToString());
  108. reportInfo.Add("单机总任务时长", TotalTime.ToString());
  109. reportInfo.Add("单机总油耗", FXJHGenerate.CalculateTotalFuelConsumption(FlightPlanEditor, TurningPoints).ToString());
  110. reportInfo.Add("单机机场使用情况", Airport + "\r\n" + hospitalAirport);
  111. double zhc = 0;
  112. for (int i = 0; i < TurningPoints.Count - 1; i++)
  113. {
  114. zhc += Utils.Util.GetDistance(TurningPoints[i].TurningPointLongitude,
  115. TurningPoints[i + 1].TurningPointLongitude, TurningPoints[i].TurningPointLatitude, TurningPoints[i + 1].TurningPointLatitude);
  116. }
  117. reportInfo.Add("单机导航使用情况", zhc.ToString()); //飞行总距离
  118. for (int i = 0; i < load.Count; i++)
  119. {
  120. if (load[i].Split(":")[0].Contains("装备"))
  121. {
  122. device += load[i].Split(":")[1];
  123. if (i != load.Count - 1)
  124. {
  125. device += "\r\n";
  126. }
  127. }
  128. else if (load[i].Split(":")[0].Contains("药品"))
  129. {
  130. medicine += load[i].Split(":")[1] + "\r\n";
  131. if (i != load.Count - 1)
  132. {
  133. medicine += "\r\n";
  134. }
  135. }
  136. }
  137. //Console.WriteLine("医疗任务设备11:" + device);
  138. //Console.WriteLine("医疗药品11:" + medicine);
  139. if (device != null)
  140. reportInfo.Add("医疗任务设备", device);
  141. else
  142. reportInfo.Add("医疗任务设备", "");
  143. if (medicine != null)
  144. reportInfo.Add("医疗药品", medicine);
  145. else
  146. reportInfo.Add("医疗药品", "");
  147. reportInfo.Add("任务缓急情况", "提前规划");
  148. IsOver = true;
  149. End();
  150. }
  151. static double CalculateTotalEmergencyTime(List<string> diseaseTypes)
  152. {
  153. double totalTime = 0;
  154. // 这里假设有一个方法GetEmergencyTimeFromDatabase,它根据疾病类型从数据库获取急救时间,此处应为从数据库中读取
  155. foreach (var diseaseType in diseaseTypes)
  156. {
  157. double emergencyTime = GetEmergencyTimeFromDatabase(diseaseType);
  158. totalTime += emergencyTime;
  159. }
  160. return totalTime;
  161. }
  162. // 模拟从数据库获取急救时间的方法
  163. static double GetEmergencyTimeFromDatabase(string diseaseType)
  164. {
  165. // 这里应该是实际的数据库查询逻辑
  166. // 但为了示例,我们直接返回一个模拟值
  167. switch (diseaseType)
  168. {
  169. case "aa": //HeartAttack
  170. return 2; // 心脏病急救时间为2分钟
  171. case "bb": //Stroke
  172. return 5; // 中风急救时间为5分钟
  173. case "cc": //Trauma
  174. return 10; // 创伤急救时间为10分钟
  175. case "dd":
  176. return 15;
  177. case "ee":
  178. return 20;
  179. default:
  180. return 0;
  181. }
  182. }
  183. // 假设从前端接收到的数据结构
  184. public class Patient
  185. {
  186. public int Id { get; set; }
  187. public string DiseaseType { get; set; }
  188. public double GoldenHour { get; set; } // 患者的黄金救援时间应由黄金救援时间程序获得
  189. }
  190. public class DiseaseInfo
  191. {
  192. public string DiseaseType { get; set; }
  193. public double MinGoldenHour { get; set; }
  194. public double MaxGoldenHour { get; set; }
  195. }
  196. public class MedicalRescue
  197. {
  198. private static Dictionary<string, DiseaseInfo> diseaseDatabase = new Dictionary<string, DiseaseInfo>
  199. {
  200. { "aa", new DiseaseInfo { DiseaseType = "aa", MinGoldenHour = 1, MaxGoldenHour = 3 } },
  201. { "bb", new DiseaseInfo { DiseaseType = "bb", MinGoldenHour = 2, MaxGoldenHour = 4 } },
  202. { "cc", new DiseaseInfo { DiseaseType = "cc", MinGoldenHour = 3, MaxGoldenHour = 5 } },
  203. { "dd", new DiseaseInfo { DiseaseType = "dd", MinGoldenHour = 4, MaxGoldenHour = 6 } },
  204. { "ee", new DiseaseInfo { DiseaseType = "ee", MinGoldenHour = 5, MaxGoldenHour = 7 } },
  205. // 添加更多疾病类型
  206. };
  207. public static List<Patient> ProcessPatients(List<Patient> patients, Random rand)
  208. {
  209. foreach (var patient in patients)
  210. {
  211. var diseaseInfo = GetDiseaseInfo(patient.DiseaseType); // MinGoldenHour MaxGoldenHour 数据库读取
  212. double goldenHour = GenerateRandomGoldenHour(rand, diseaseInfo.MinGoldenHour, diseaseInfo.MaxGoldenHour);
  213. Console.WriteLine($"Patient ID: {patient.Id}, Disease: {patient.DiseaseType}, Golden Hour: {goldenHour:F2}");
  214. patient.GoldenHour = goldenHour;
  215. }
  216. return patients;
  217. }
  218. public static DiseaseInfo GetDiseaseInfo(string diseaseType)
  219. {
  220. if (diseaseDatabase.ContainsKey(diseaseType))
  221. {
  222. return diseaseDatabase[diseaseType];
  223. }
  224. throw new ArgumentException("Unknown disease type.");
  225. }
  226. public static double GenerateRandomGoldenHour(Random rand, double min, double max)
  227. {
  228. double mu = (max + min) / 2;
  229. double sigma = (max - min) / 6;
  230. var normal = new Normal(mu, sigma);
  231. return normal.Sample();
  232. }
  233. }
  234. // 假设数据库中的疾病优先级信息
  235. public class DiseasePriority
  236. {
  237. public string DiseaseType { get; set; }
  238. public int Priority { get; set; } // 优先级,数字越小优先级越高
  239. }
  240. // 静态类,包含与疾病优先级相关的静态方法
  241. public static class DiseasePriorityService
  242. {
  243. // 数据库查询(实际项目中应该是从数据库读取)
  244. public static List<DiseasePriority> GetDiseasePriorities()
  245. {
  246. return new List<DiseasePriority>
  247. {
  248. new DiseasePriority { DiseaseType = "aa", Priority = 5 },
  249. new DiseasePriority { DiseaseType = "bb", Priority = 4 },
  250. new DiseasePriority { DiseaseType = "cc", Priority = 3 },
  251. new DiseasePriority { DiseaseType = "dd", Priority = 2 },
  252. new DiseasePriority { DiseaseType = "ee", Priority = 5 },
  253. };
  254. }
  255. // 根据疾病类型获取优先级
  256. public static int GetPriority(string diseaseType)
  257. {
  258. var priorities = GetDiseasePriorities().ToDictionary(dp => dp.DiseaseType, dp => dp.Priority);
  259. if (priorities.TryGetValue(diseaseType, out int priority))
  260. {
  261. return priority;
  262. }
  263. return int.MaxValue; // 如果没有找到,返回一个很大的数作为默认优先级
  264. }
  265. }
  266. public string TargetQiXiangInfoSave(string s, int hour)
  267. {
  268. string result = hour.ToString() + "-" + s;
  269. for (int i = 0; i < FlightPlanEditor.medicalTargetPoint[0].TargetQiXiangInfos.Length; i++)
  270. {
  271. }
  272. switch (s)
  273. {
  274. case "温度":
  275. break;
  276. case "湿度":
  277. break;
  278. case "能见度":
  279. break;
  280. case "风速":
  281. break;
  282. case "风向":
  283. break;
  284. case "天气":
  285. break;
  286. }
  287. return result;
  288. }
  289. }
  290. [ObjectSystem]
  291. public class AircraftYLZYAwakeSystem : AwakeSystem<AircraftYLZY, FlightPlanEditor>
  292. {
  293. public override void Awake(AircraftYLZY self, FlightPlanEditor flightPlanEditor)
  294. {
  295. self.FlightPlanEditor = flightPlanEditor;
  296. self.Awake();
  297. }
  298. }