AircraftYLZY.cs 13 KB

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