AircraftYLZY.cs 12 KB

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