本模拟将模拟急救车服务的运作流程。在模拟中,需要考虑到调度中心、急救车队、患者等元素,以及它们之间的关系和交互。
将模拟系统分为三个模块:调度中心、急救车队和患者。对于每个模块,定义相应的类:
(1) 调度中心类Central:负责接收患者的呼叫,分派急救车进行救援;
(2) 急救车队类Ambulance:每个急救车都有一个编号和状态(在途或空闲),负责接收调度中心的分派,前往患者处救援,并将患者送到医院;
(3) 患者类Patient:每个患者有一个唯一的呼叫编号、需求类型和救援状态(已得到救援或未得到救援),负责呼叫调度中心进行救援。
根据上述模拟需求及场景,完成以下代码实现:
class Central:
def __init__(self):
self.patients = []
self.ambulances = {}
def add_patient(self, patient):
self.patients.append(patient)
def get_patient(self):
patient = None
for p in self.patients:
if not p.rescued:
patient = p
break
return patient
def add_ambulance(self, ambulance):
self.ambulances[ambulance.id] = ambulance
def dispatch_ambulance(self):
patient = self.get_patient()
if patient is None:
return False
for id, ambulance in