2024-08-24 11:20:13 +08:00
|
|
|
from mesa import Agent
|
|
|
|
|
|
|
|
class ProductAgent(Agent):
|
2024-08-24 19:30:16 +08:00
|
|
|
def __init__(self, unique_id, model, name):
|
2024-08-24 11:20:13 +08:00
|
|
|
# 调用超类的 __init__ 方法
|
|
|
|
super().__init__(unique_id, model)
|
|
|
|
|
|
|
|
# 初始化代理属性
|
|
|
|
self.name = name
|
|
|
|
self.product_network = self.model.product_network
|
|
|
|
|
|
|
|
def a_successors(self):
|
|
|
|
# Find successors of the current product and return them as a list of ProductAgent
|
|
|
|
successors = list(self.product_network.successors(self))
|
|
|
|
return [self.model.schedule.agents[successor] for successor in successors]
|
|
|
|
|
|
|
|
def a_predecessors(self):
|
|
|
|
# Find predecessors of the current product and return them as a list of ProductAgent
|
|
|
|
predecessors = list(self.product_network.predecessors(self))
|
|
|
|
return [self.model.schedule.agents[predecessor] for predecessor in predecessors]
|
|
|
|
def step(self):
|
|
|
|
# 在每个时间步进行的操作
|
|
|
|
pass
|