AircraftYLZY.cs 10 KB

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