mesa/product.py

35 lines
1.4 KiB
Python
Raw Normal View History

2024-08-24 11:20:13 +08:00
from mesa import Agent
2024-08-24 11:20:13 +08:00
class ProductAgent(Agent):
2024-09-21 22:39:09 +08:00
def __init__(self, unique_id, model, name, type2, j_comp_data_consumed, j_comp_data_produced):
2024-08-24 11:20:13 +08:00
# 调用超类的 __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
2024-09-21 22:39:09 +08:00
# depreciation ratio 折旧比值
# self.depreciation ratio
self.j_comp_data_produced = j_comp_data_produced
self.j_comp_data_consumed = j_comp_data_consumed
2024-08-24 11:20:13 +08:00
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]
2024-08-24 11:20:13 +08:00
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]