到达是根据随机过程发生的。我希望可以指定到达事件是与已经存在的客户有关(在本例中,我应该将其作为参数给出)还是将成为新客户,在这种情况下,我的到达构造函数应该创建一个新的客户实例。
这只是dict和setdefault的用法:
customers = {}
for co in all_customers:
known_customer = customers.setdefault(hash(co), customer(co))
或者,如果您想让它作为构造函数:
class arrival:
known_cos = {}# quasi static
def __init__(self, co)
self.customer = known_cos.setdefault(hash(co) , customer(co))