From 2d359c80f1961cd1da912685b2a2c3f2ba57b7ea Mon Sep 17 00:00:00 2001 From: Cricial <2911646453@qq.com> Date: Wed, 11 Dec 2024 15:58:06 +0800 Subject: [PATCH] no message --- __pycache__/firm.cpython-38.pyc | Bin 11523 -> 11499 bytes __pycache__/my_model.cpython-38.pyc | Bin 16398 -> 16494 bytes firm.py | 4 +-- my_model.py | 40 +++++++++++++++------------- 4 files changed, 23 insertions(+), 21 deletions(-) diff --git a/__pycache__/firm.cpython-38.pyc b/__pycache__/firm.cpython-38.pyc index 29fcd9a30442a5d205c4a48b5a3aa5ef02503afb..d5d075f5b34b67739097f4209f1ca27b68d1ee35 100644 GIT binary patch delta 1878 zcmZ{kO>7%Q6vubA$$IUL?Sv+^^U>H&QYTJKS|mz72nc8ZQI#NC5=5Z5iFf1J`EWA3 zPD!k{KW-Z*DVFxE@m#|{oqilBDRXUlHi)5HccJ;7yI-1vX zHAQr{?l~{n+GbBt8kW|Gu3eY;0hg@}NgHIbU+le+ui;vUUNfU?5Yx8e?3Ub6=xmnq zUZMMD))xjP)s7j_S%2;%67s2>VvOLMGXuJ4&jZ zq`OWgr&vyVOM97jkyZh(JHKgv6Eenr@t#v&g>sTbTAyTBeb13;_OoxLsSn~XM~PT5 zjbad}I6uYG{*zh~wg_c7TmIX!n&Co>&=K~@BbT%kylEiA{Ph9$?EVBd`YVa!p0ig3dp%sowkfQlXmg7 zxNFHbkxUv3R)QLfIm5KJ%R|p&&vs=V6otMAhbRaNT2iPnmt8Vq>UKHC#l2AudI6hJ z3z=SI|1=&Vt4^rt8&a6%67Q*)j~47X05k&)aMg((RU~l?F8p6m6TtgR>V&SBJ18!M z8`2MePT&+Ex|+jEOdT?gRa5^FC|3ZqZ(QR&(i7!Ult)q2TtF25va{Us72)&yuxb}t z^A*)zVXjb^?Cnc7bf#k0Dl3KJy&^j?a}UO{;>x>A&K?iH7%k70nVU?^rg^_E;tuNo zlKonyClWq<)61D^t)0iOe30M~&pfg-Q~EVJ48 LLG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BYjgfbC~8%i@_CQc??X>(SFWg}d#EkGln%m^t$ihQK6RTF z7ZcQ@-E`o^Id#^QMK@K<2Gt%1c-FSO;$>{RMpyH{p^ zgLhZ^#qnu{zprjoXYNdLo+M<@Lit1PM;qE}O{2vJh0^3;(J`EJH JZQ$q%{~xeE3n2gi diff --git a/firm.py b/firm.py index d3ab4fe..81f48cf 100644 --- a/firm.py +++ b/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 # 消耗材料量 根据设备量进行估算 { } diff --git a/my_model.py b/my_model.py index e7634b5..c78cfc1 100644 --- a/my_model.py +++ b/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