AircraftYLZY.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355
  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 TaskLoad load;
  18. public string device;
  19. public string medicine;
  20. public string hospitalAirport;
  21. private Dictionary<string, DiseaseInfo> diseaseDatabase = new Dictionary<string, DiseaseInfo>();
  22. public override void End()
  23. {
  24. TotalFuelConsumption = TurningPoints[0].RemainingFuel - TurningPoints[^1].RemainingFuel;
  25. }
  26. public override void Reset()
  27. {
  28. base.Reset();
  29. IsOver = false;
  30. Success = false;
  31. TotalTime = 0;
  32. reportInfo = new Dictionary<string, string>();
  33. device = string.Empty;
  34. medicine = string.Empty;
  35. diseaseDatabase = new Dictionary<string, DiseaseInfo>();
  36. }
  37. public override void Start()
  38. {
  39. for (int i = 1; i < 19; i++)
  40. {
  41. string s = Utils.Util.GetYL(i.ToString());
  42. string[] r = s.Split('-');
  43. diseaseDatabase.Add(r[0], new DiseaseInfo { MinGoldenHour = Convert.ToDouble(r[1]), MaxGoldenHour = Convert.ToDouble(r[2]), Priority = Convert.ToDouble(r[3]), RescueTime = Convert.ToDouble(r[4]) });
  44. }
  45. //foreach (var item in diseaseDatabase)
  46. //{
  47. // Console.WriteLine("疾病类型:" + item.Key);
  48. // Console.WriteLine("最小黄金救援时间:" + item.Value.MinGoldenHour);
  49. // Console.WriteLine("最大黄金救援时间:" + item.Value.MaxGoldenHour);
  50. // Console.WriteLine("优先级:" + item.Value.Priority);
  51. // Console.WriteLine("抢救时间:" + item.Value.RescueTime);
  52. //}
  53. FlightPlanEditor.missionpoint.MissionPointLatitude = FlightPlanEditor.medicalTargetPoint[0].TargetPointLatitude;
  54. FlightPlanEditor.missionpoint.MissionPointLongitude = FlightPlanEditor.medicalTargetPoint[0].TargetPointLongitude;
  55. FlightPlanEditor.missionpoint.MissionPointHeight = FlightPlanEditor.medicalTargetPoint[0].TargetPointHeight;
  56. //Console.WriteLine("Latitude:" + FlightPlanEditor.missionpoint.MissionPointLatitude + "_" + "Longitude:" + FlightPlanEditor.missionpoint.MissionPointLongitude + "_" + "Height:" + FlightPlanEditor.missionpoint.MissionPointHeight);
  57. int patientCount = FlightPlanEditor.medicalTargetPoint[0].TargetType.Count; // 伤患人数
  58. List<string> diseaseTypes = new List<string>();
  59. for (int i = 0; i < FlightPlanEditor.medicalTargetPoint[0].TargetType.diseaseTypes.Length; i++)
  60. {
  61. diseaseTypes.Add(FlightPlanEditor.medicalTargetPoint[0].TargetType.diseaseTypes[i]);
  62. }
  63. int medicCount = taskParameter.doctorPersonnel + taskParameter.nursePersonnel + taskParameter.nurseSeverePersonnel; // 医护人员数量
  64. // 交接时间为5分钟
  65. double handoverTime = 5;
  66. // 计算总急救时间
  67. double totalEmergencyTime = CalculateTotalEmergencyTime(diseaseTypes);
  68. // 计算平均急救时间(每个医护人员分担的时间)
  69. double averageEmergencyTimePerMedic = totalEmergencyTime / medicCount;
  70. // 计算总时间(平均急救时间 + 交接时间)
  71. double totalTime = averageEmergencyTimePerMedic + handoverTime;
  72. //Console.WriteLine($"总急救时间(平均每个医护人员): {averageEmergencyTimePerMedic} 分钟");
  73. //Console.WriteLine($"总时间(包括交接时间): {totalTime} 分钟");
  74. Random rand = new Random();
  75. List<Patient> patients = new List<Patient>();
  76. for (int i = 0; i < patientCount; i++)
  77. {
  78. patients.Add(new Patient()
  79. {
  80. Id = i + 1,
  81. DiseaseType = diseaseTypes[i],
  82. GoldenHour = 0
  83. });
  84. }
  85. patients = ProcessPatients(patients, rand);
  86. // 对患者进行排序
  87. var sortedPatients = patients.OrderBy(p => GetPriority(p.DiseaseType))
  88. .ThenBy(p => p.GoldenHour)
  89. .ToList();
  90. // 输出排序后的患者列表 // 从是事故点到医院的飞行时间 + 5分钟的交接时间 < 黄金时间 ? 成功:失败
  91. foreach (var patient in sortedPatients)
  92. {
  93. //Console.WriteLine($"sortedPatients ID: {patient.Id}, Disease: {patient.DiseaseType}, Golden Hour: {patient.GoldenHour:F2}");
  94. }
  95. // 注意:实际项目中,每次转运一名伤员的操作可能涉及更多的逻辑,比如更新数据库中的转运状态等。
  96. FXJHGenerate.FromStartToMission(FlightPlanEditor, ref TurningPoints);//生成从起点到任务段起点的航路点
  97. for (int i = 0; i < FlightPlanEditor.medicalTargetPoint[0].TargetType.Count; i++)
  98. {
  99. FXJHGenerate.JIJIU(5 * 60, FlightPlanEditor, ref TurningPoints);
  100. FXJHGenerate.JIJIU1(5 * 60, hospitalPoint, ref TurningPoints);
  101. }
  102. FXJHGenerate.FromMissionToEnd(FlightPlanEditor, hospitalPoint, ref TurningPoints);
  103. FXJHGenerate.FXJHTPDiedai(FlightPlanEditor, ref TurningPoints, Velocitys, FuelConsumptions);
  104. int refuelCount = 0;
  105. for (int i = 0; i < TurningPoints.Count; i++) // 总飞行时间
  106. {
  107. TotalTime += TurningPoints[i].SegmentFlightTime; // 总时间 //仿真轮次1 数值1
  108. if (TurningPoints[i].TurningPointName == "加油")
  109. refuelCount++;
  110. }
  111. Console.WriteLine("加油次数:" + refuelCount);
  112. Console.WriteLine("TotalTime:" + TotalTime);
  113. reportInfo.Add("准备时间", TaskReadyTime.ToString());
  114. double reachTime = 0;
  115. for (int i = 0; i < 2; i++)
  116. {
  117. reachTime += TurningPoints[i].SegmentFlightTime;
  118. }
  119. reportInfo.Add("到达时间", reachTime.ToString());
  120. reportInfo.Add("任务周期时间", TotalTime.ToString());
  121. reportInfo.Add("航程利用率", refuelCount.ToString());
  122. reportInfo.Add("执行任务飞机型号", Name);
  123. reportInfo.Add("执行任务飞机数量", "1");
  124. reportInfo.Add("单机飞行员人数", taskParameter.pilotPersonnel.ToString());
  125. reportInfo.Add("单机医师人数", taskParameter.doctorPersonnel.ToString());
  126. reportInfo.Add("单机护士人数", taskParameter.nursePersonnel.ToString());
  127. reportInfo.Add("单机重症监护护理人员人数", taskParameter.nurseSeverePersonnel.ToString());
  128. reportInfo.Add("单机地面保障人数", taskParameter.groundSupportPersonnel.ToString());
  129. reportInfo.Add("单机总任务时长", TotalTime.ToString());
  130. reportInfo.Add("单机总油耗", FXJHGenerate.CalculateTotalFuelConsumption(FlightPlanEditor, TurningPoints).ToString());
  131. reportInfo.Add("单机机场使用情况", Airport + "\r\n" + hospitalAirport);
  132. double zhc = 0;
  133. for (int i = 0; i < TurningPoints.Count - 1; i++)
  134. {
  135. zhc += Utils.Util.GetDistance(TurningPoints[i].TurningPointLongitude,
  136. TurningPoints[i + 1].TurningPointLongitude, TurningPoints[i].TurningPointLatitude, TurningPoints[i + 1].TurningPointLatitude);
  137. }
  138. reportInfo.Add("单机导航使用情况", zhc.ToString()); //飞行总距离
  139. if (load.FirstAid != null)
  140. {
  141. for (int i = 0; i < load.FirstAid.Length; i++)
  142. {
  143. device += load.FirstAid[i];
  144. device += "\r\n";
  145. }
  146. }
  147. if (load.HandlingAndFixing != null)
  148. {
  149. for (int i = 0; i < load.HandlingAndFixing.Length; i++)
  150. {
  151. device += load.HandlingAndFixing[i];
  152. device += "\r\n";
  153. }
  154. }
  155. if (load.DiagnosisAndMonitoring != null)
  156. {
  157. for (int i = 0; i < load.DiagnosisAndMonitoring.Length; i++)
  158. {
  159. device += load.DiagnosisAndMonitoring[i];
  160. device += "\r\n";
  161. }
  162. }
  163. if (load.Trauma != null)
  164. {
  165. for (int i = 0; i < load.Trauma.Length; i++)
  166. {
  167. device += load.Trauma[i];
  168. device += "\r\n";
  169. }
  170. }
  171. if (load.Infusion != null)
  172. {
  173. for (int i = 0; i < load.Infusion.Length; i++)
  174. {
  175. device += load.Infusion[i];
  176. device += "\r\n";
  177. }
  178. }
  179. if (load.Drug != null)
  180. {
  181. for (int i = 0; i < load.Drug.Length; i++)
  182. {
  183. medicine += load.Drug[i];
  184. if (i != load.Drug.Length - 1)
  185. medicine += "\r\n";
  186. }
  187. }
  188. char[] cs = { '\r', '\n' };
  189. device = device.TrimEnd(cs);
  190. //Console.WriteLine("医疗任务设备11:" + device);
  191. //Console.WriteLine("医疗药品11:" + medicine);
  192. if (device != null)
  193. reportInfo.Add("医疗任务设备", device);
  194. else
  195. reportInfo.Add("医疗任务设备", "");
  196. if (medicine != null)
  197. reportInfo.Add("医疗药品", medicine);
  198. else
  199. reportInfo.Add("医疗药品", "");
  200. reportInfo.Add("任务缓急情况", "提前规划");
  201. IsOver = true;
  202. End();
  203. }
  204. public double CalculateTotalEmergencyTime(List<string> diseaseTypes)
  205. {
  206. double totalTime = 0;
  207. // 这里假设有一个方法GetEmergencyTimeFromDatabase,它根据疾病类型从数据库获取急救时间,此处应为从数据库中读取
  208. foreach (var diseaseType in diseaseTypes)
  209. {
  210. double emergencyTime = GetEmergencyTimeFromDatabase(diseaseType);
  211. totalTime += emergencyTime;
  212. }
  213. return totalTime;
  214. }
  215. // 模拟从数据库获取急救时间的方法
  216. public double GetEmergencyTimeFromDatabase(string diseaseType)
  217. {
  218. if (diseaseDatabase.ContainsKey(diseaseType))
  219. {
  220. return diseaseDatabase[diseaseType].RescueTime;
  221. }
  222. throw new ArgumentException("Unknown disease type.");
  223. }
  224. // 假设从前端接收到的数据结构
  225. public class Patient
  226. {
  227. public int Id { get; set; }
  228. public string DiseaseType { get; set; }
  229. public double GoldenHour { get; set; } // 患者的黄金救援时间应由黄金救援时间程序获得
  230. }
  231. public class DiseaseInfo
  232. {
  233. public double MinGoldenHour { get; set; }
  234. public double MaxGoldenHour { get; set; }
  235. public double Priority { get; set; }
  236. public double RescueTime { get; set; }
  237. }
  238. public List<Patient> ProcessPatients(List<Patient> patients, Random rand)
  239. {
  240. foreach (var patient in patients)
  241. {
  242. var diseaseInfo = GetDiseaseInfo(patient.DiseaseType); // MinGoldenHour MaxGoldenHour 数据库读取
  243. double goldenHour = GenerateRandomGoldenHour(rand, diseaseInfo.MinGoldenHour, diseaseInfo.MaxGoldenHour);
  244. //Console.WriteLine($"Patient ID: {patient.Id}, Disease: {patient.DiseaseType}, Golden Hour: {goldenHour:F2}");
  245. patient.GoldenHour = goldenHour;
  246. }
  247. return patients;
  248. }
  249. public DiseaseInfo GetDiseaseInfo(string diseaseType)
  250. {
  251. if (diseaseDatabase.ContainsKey(diseaseType))
  252. {
  253. return diseaseDatabase[diseaseType];
  254. }
  255. throw new ArgumentException("Unknown disease type.");
  256. }
  257. public static double GenerateRandomGoldenHour(Random rand, double min, double max)
  258. {
  259. double mu = (max + min) / 2;
  260. double sigma = (max - min) / 6;
  261. var normal = new Normal(mu, sigma);
  262. return normal.Sample();
  263. }
  264. public double GetPriority(string diseaseType)
  265. {
  266. if (diseaseDatabase.ContainsKey(diseaseType))
  267. {
  268. return diseaseDatabase[diseaseType].Priority;
  269. }
  270. throw new ArgumentException("Unknown disease type.");
  271. }
  272. public string TargetQiXiangInfoSave(string s, int hour)
  273. {
  274. string result = hour.ToString() + "-" + s;
  275. for (int i = 0; i < FlightPlanEditor.medicalTargetPoint[0].TargetQiXiangInfos.Length; i++)
  276. {
  277. }
  278. switch (s)
  279. {
  280. case "温度":
  281. break;
  282. case "湿度":
  283. break;
  284. case "能见度":
  285. break;
  286. case "风速":
  287. break;
  288. case "风向":
  289. break;
  290. case "天气":
  291. break;
  292. }
  293. return result;
  294. }
  295. }
  296. [ObjectSystem]
  297. public class AircraftYLZYAwakeSystem : AwakeSystem<AircraftYLZY, FlightPlanEditor>
  298. {
  299. public override void Awake(AircraftYLZY self, FlightPlanEditor flightPlanEditor)
  300. {
  301. self.FlightPlanEditor = flightPlanEditor;
  302. self.Awake();
  303. }
  304. }