AircraftYLZY.cs 13 KB

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