no message
This commit is contained in:
parent
5c7788e86e
commit
2d359c80f1
Binary file not shown.
Binary file not shown.
4
firm.py
4
firm.py
|
@ -2,7 +2,7 @@ from mesa import Agent
|
|||
|
||||
|
||||
class FirmAgent(Agent):
|
||||
def __init__(self, unique_id, model, type_region, revenue_log, n_equip_c, a_lst_product,
|
||||
def __init__(self, unique_id, model, type_region, revenue_log, a_lst_product,
|
||||
production_output, demand_quantity, R, P, C):
|
||||
# 调用超类的 __init__ 方法
|
||||
super().__init__(unique_id, model)
|
||||
|
@ -38,7 +38,7 @@ class FirmAgent(Agent):
|
|||
self.downer_i = [agent for u, v in self.firm_network.out_edges(self.unique_id)
|
||||
for agent in self.model.company_agents if agent.unique_id == u]
|
||||
# 设备c的数量 (总量) 使用这个来判断设备数量
|
||||
self.n_equip_c = n_equip_c
|
||||
#self.n_equip_c = n_equip_c
|
||||
# 设备c产量 根据设备量进行估算
|
||||
self.c_yield = production_output
|
||||
# 消耗材料量 根据设备量进行估算 { }
|
||||
|
|
40
my_model.py
40
my_model.py
|
@ -68,13 +68,14 @@ class MyModel(Model):
|
|||
|
||||
# 方法执行
|
||||
self.initialize_product_network(params)
|
||||
self.resource_integration()
|
||||
self.j_comp_consumed_produced()
|
||||
self.initialize_agents()
|
||||
|
||||
self.initialize_firm_network()
|
||||
self.initialize_firm_product_network()
|
||||
self.add_edges_to_firm_network()
|
||||
self.connect_unconnected_nodes()
|
||||
self.resource_integration()
|
||||
self.j_comp_consumed_produced()
|
||||
self.initialize_agents()
|
||||
self.initialize_disruptions()
|
||||
|
||||
def initialize_product_network(self, params):
|
||||
|
@ -94,7 +95,7 @@ class MyModel(Model):
|
|||
def initialize_firm_network(self):
|
||||
# Read the firm data
|
||||
|
||||
firm = pd.read_csv("input_data/input_firm_data/Firm_amended.csv")
|
||||
firm = pd.read_csv("input_data/input_firm_data/firm_amended.csv")
|
||||
|
||||
firm['Code'] = firm['Code'].astype(str)
|
||||
|
||||
|
@ -316,18 +317,16 @@ class MyModel(Model):
|
|||
for ag_node, attr in self.product_network.nodes(data=True):
|
||||
# 产业种类
|
||||
|
||||
type2 = self.type2[self.type2["Index"] == ag_node]["产业种类"]
|
||||
# type2 = self.type2[self.type2["Index"] == ag_node]["产业种类"]
|
||||
# depreciation ratio 折旧比值
|
||||
# product_id = product_id.iloc[0]
|
||||
product = ProductAgent(ag_node, self, name=attr['Name'], type2=type2)
|
||||
product = ProductAgent(ag_node, self, name=attr['Name'], type2=0)
|
||||
self.add_agent(product)
|
||||
# self.grid.place_agent(product, ag_node)
|
||||
##print(f"Product agent created: {product.name}, ID: {product.unique_id}")
|
||||
|
||||
for ag_node, attr in self.firm_network.nodes(data=True):
|
||||
a_lst_product = [agent for agent in self.product_agents if agent.unique_id in attr['Product_Code']]
|
||||
firm_id = self.Firm['Code'] == ag_node
|
||||
n_equip_c = self.Firm.loc[firm_id, '设备数量'].values[0]
|
||||
|
||||
demand_quantity = self.data_consumed[self.data_consumed['Firm_Code'] == ag_node]
|
||||
|
||||
|
@ -335,17 +334,16 @@ class MyModel(Model):
|
|||
|
||||
# c购买价格? 数据预处理
|
||||
# c_price = self.Firm.loc[self.Firm['Code'] == ag_node, 'c_price'].values[0]
|
||||
|
||||
# 资源 资源库存信息 利用 firm_resource
|
||||
R = self.firm_resource_R.loc[firm_id].to_list()[0]
|
||||
P = self.firm_resource_P.loc[firm_id].to_list()[0]
|
||||
C = self.firm_resource_C.loc[firm_id].to_list()[0]
|
||||
|
||||
R = self.firm_resource_R.loc[int(ag_node)]
|
||||
P = self.firm_resource_P.loc[int(ag_node)]
|
||||
C = self.firm_resource_C.loc[int(ag_node)]
|
||||
|
||||
firm_agent = FirmAgent(
|
||||
ag_node, self,
|
||||
type_region=attr['Type_Region'],
|
||||
revenue_log=attr['Revenue_Log'],
|
||||
n_equip_c=n_equip_c,
|
||||
a_lst_product=a_lst_product,
|
||||
demand_quantity=demand_quantity,
|
||||
production_output=production_output,
|
||||
|
@ -396,6 +394,7 @@ class MyModel(Model):
|
|||
self.product_agents.append(agent)
|
||||
|
||||
def resource_integration(self):
|
||||
|
||||
data_R = pd.read_csv("input_data/input_firm_data/firms_materials.csv")
|
||||
data_C = pd.read_csv("input_data/input_firm_data/firms_devices.csv")
|
||||
data_P = pd.read_csv("input_data/input_firm_data/firms_products.csv")
|
||||
|
@ -422,18 +421,21 @@ class MyModel(Model):
|
|||
data_consumed = pd.read_csv('input_data/input_firm_data/firms_materials.csv')
|
||||
data_produced = pd.read_csv('input_data/input_firm_data/firms_products.csv')
|
||||
|
||||
data_not_consumed = data_consumed.groupby('Firm_Code')[['消耗材料id', '材料数量']] \
|
||||
.apply(lambda x: dict(zip(x['消耗材料id'], x['材料数量']))) \
|
||||
data_not_consumed = data_consumed.groupby('Firm_Code')[['材料id', '材料数量']] \
|
||||
.apply(lambda x: dict(zip(x['材料id'], x['材料数量']))) \
|
||||
.reset_index(name='Material_not_Consumed')
|
||||
|
||||
# 这里简单设置为折半 考虑 企业的设备量
|
||||
# 可以引入 换算率 也就是 材料——计算产品比例 通过上游产业 现在假设为 2:1 的比例
|
||||
data_consumed = data_consumed.groupby('Firm_Code')[['消耗材料id', '材料数量']] \
|
||||
.apply(lambda x: dict(zip(x['消耗材料id'], x['材料数量'] / 2))) \
|
||||
data_consumed0 = data_consumed.groupby('Firm_Code')[['材料id', '材料数量']] \
|
||||
.apply(lambda x: dict(zip(x['材料id'], x['材料数量'] / 2))) \
|
||||
.reset_index(name='Material_not_Consumed')
|
||||
data_produced = data_consumed.groupby('Firm_Code')[['材料id', '材料数量']] \
|
||||
.apply(lambda x: dict(zip(x['材料id'], x['材料数量'] / 4))) \
|
||||
.reset_index(name='Material_not_Consumed')
|
||||
|
||||
self.data_consumed = data_consumed
|
||||
self.data_produced = data_consumed / 2
|
||||
self.data_consumed = data_consumed0
|
||||
self.data_produced = data_produced
|
||||
|
||||
def step(self):
|
||||
# 1. Remove edge to customer and disrupt customer up product
|
||||
|
|
Loading…
Reference in New Issue