34 lines
1.4 KiB
Python
34 lines
1.4 KiB
Python
from mesa import Agent
|
|
|
|
|
|
class ProductAgent(Agent):
|
|
def __init__(self, unique_id, model, name, type2, device_salvage_values, j_comp_data_consumed, j_comp_data_produced):
|
|
# 调用超类的 __init__ 方法
|
|
super().__init__(unique_id, model)
|
|
|
|
# 初始化代理属性
|
|
self.name = name
|
|
self.product_network = self.model.product_network
|
|
if type2 == 0:
|
|
self.is_equip = True
|
|
else:
|
|
self.is_mater = True
|
|
self.device_salvage_values = device_salvage_values
|
|
|
|
self.j_comp_data_produced = j_comp_data_produced
|
|
self.j_comp_data_consumed = j_comp_data_consumed
|
|
|
|
def a_successors(self):
|
|
# 从 product_network 中找到当前代理的后继节点
|
|
successors = list(self.model.product_network.successors(self.unique_id))
|
|
|
|
# 通过 unique_id 查找后继节点对应的代理对象,从 self.product_agents 中获取
|
|
return [agent for agent in self.model.product_agents if agent.unique_id in successors]
|
|
|
|
def a_predecessors(self):
|
|
# 找到当前代理的前驱节点
|
|
predecessors = list(self.model.product_network.predecessors(self.unique_id))
|
|
|
|
# 通过 unique_id 查找前驱节点对应的代理对象,直接从 self.product_agents 列表中获取
|
|
return [agent for agent in self.model.product_agents if agent.unique_id in predecessors]
|