AircraftXCJJ.cs 12 KB

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