AircraftXCJJ.cs 12 KB

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