AircraftXCJJ.cs 11 KB

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