10.09添加git
This commit is contained in:
32
product.py
Normal file
32
product.py
Normal file
@@ -0,0 +1,32 @@
|
||||
from mesa import Agent
|
||||
|
||||
|
||||
class ProductAgent(Agent):
|
||||
def __init__(self, unique_id, model, name, type2, production_ratio):
|
||||
# 调用超类的 __init__ 方法
|
||||
super().__init__(unique_id, model)
|
||||
|
||||
# 初始化代理属性
|
||||
self.name = name
|
||||
self.product_network = self.model.product_network
|
||||
self.production_ratio = production_ratio
|
||||
if type2 == 0:
|
||||
self.is_equip = True
|
||||
else:
|
||||
self.is_mater = True
|
||||
# depreciation ratio 折旧比值
|
||||
# self.depreciation ratio
|
||||
|
||||
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]
|
||||
Reference in New Issue
Block a user