Compare commits
20 Commits
5c7788e86e
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d57216d51f | ||
|
|
8f4c5929bb | ||
|
|
c30ec71014 | ||
|
|
46df9bace7 | ||
|
|
66e40a1250 | ||
|
|
ebc8159bf8 | ||
|
|
0233f642e4 | ||
|
|
5b2cf3a3e5 | ||
|
|
0da29d58d6 | ||
|
|
42fba119d1 | ||
|
|
30e7e56c11 | ||
|
|
0f7f9c1a4b | ||
|
|
3a46d09b8e | ||
|
|
13521ff752 | ||
|
|
09622cf33d | ||
|
|
3ba41c3491 | ||
|
|
3d97db42d0 | ||
|
|
2ccdc976e7 | ||
|
|
11b7b738f9 | ||
|
|
2d359c80f1 |
30
.idea/csv-editor.xml
generated
@@ -3,7 +3,7 @@
|
|||||||
<component name="CsvFileAttributes">
|
<component name="CsvFileAttributes">
|
||||||
<option name="attributeMap">
|
<option name="attributeMap">
|
||||||
<map>
|
<map>
|
||||||
<entry key="C:\Users\www\Desktop\半导体数据——暂时的数据\我做的数据\汇总数据\BomCateNet.csv">
|
<entry key="C:\Users\www\Desktop\python项目\数据\抽样第3次数据\firm_amended.csv">
|
||||||
<value>
|
<value>
|
||||||
<Attribute>
|
<Attribute>
|
||||||
<option name="separator" value="," />
|
<option name="separator" value="," />
|
||||||
@@ -136,6 +136,34 @@
|
|||||||
</Attribute>
|
</Attribute>
|
||||||
</value>
|
</value>
|
||||||
</entry>
|
</entry>
|
||||||
|
<entry key="\input_data\产品消耗制造比例.csv">
|
||||||
|
<value>
|
||||||
|
<Attribute>
|
||||||
|
<option name="separator" value="," />
|
||||||
|
</Attribute>
|
||||||
|
</value>
|
||||||
|
</entry>
|
||||||
|
<entry key="\output_result\resilience\anova.csv">
|
||||||
|
<value>
|
||||||
|
<Attribute>
|
||||||
|
<option name="separator" value="," />
|
||||||
|
</Attribute>
|
||||||
|
</value>
|
||||||
|
</entry>
|
||||||
|
<entry key="\output_result\resilience\anova_visualization.csv">
|
||||||
|
<value>
|
||||||
|
<Attribute>
|
||||||
|
<option name="separator" value="," />
|
||||||
|
</Attribute>
|
||||||
|
</value>
|
||||||
|
</entry>
|
||||||
|
<entry key="\output_result\resilience\experiment_result.csv">
|
||||||
|
<value>
|
||||||
|
<Attribute>
|
||||||
|
<option name="separator" value="," />
|
||||||
|
</Attribute>
|
||||||
|
</value>
|
||||||
|
</entry>
|
||||||
<entry key="\output_result\risk\count.csv">
|
<entry key="\output_result\risk\count.csv">
|
||||||
<value>
|
<value>
|
||||||
<Attribute>
|
<Attribute>
|
||||||
|
|||||||
22
.idea/dataSources.local.xml
generated
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="dataSourceStorageLocal" created-in="PY-242.23726.102">
|
||||||
|
<data-source name="iiabmdb@localhost" uuid="8145438e-516b-4005-a581-b91b5eedc759">
|
||||||
|
<database-info product="MySQL" version="8.0.36" jdbc-version="4.2" driver-name="MySQL Connector/J" driver-version="mysql-connector-j-8.2.0 (Revision: 06a1f724497fd81c6a659131fda822c9e5085b6c)" dbms="MYSQL" exact-version="8.0.36" exact-driver-version="8.2">
|
||||||
|
<extra-name-characters>#@</extra-name-characters>
|
||||||
|
<identifier-quote-string>`</identifier-quote-string>
|
||||||
|
</database-info>
|
||||||
|
<case-sensitivity plain-identifiers="lower" quoted-identifiers="lower" />
|
||||||
|
<secret-storage>master_key</secret-storage>
|
||||||
|
<user-name>iiabm_user</user-name>
|
||||||
|
<schema-mapping>
|
||||||
|
<introspection-scope>
|
||||||
|
<node kind="schema">
|
||||||
|
<name qname="@" />
|
||||||
|
<name qname="information_schema" />
|
||||||
|
</node>
|
||||||
|
</introspection-scope>
|
||||||
|
</schema-mapping>
|
||||||
|
</data-source>
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
12
.idea/dataSources.xml
generated
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="DataSourceManagerImpl" format="xml" multifile-model="true">
|
||||||
|
<data-source source="LOCAL" name="iiabmdb@localhost" uuid="8145438e-516b-4005-a581-b91b5eedc759">
|
||||||
|
<driver-ref>mysql.8</driver-ref>
|
||||||
|
<synchronize>true</synchronize>
|
||||||
|
<jdbc-driver>com.mysql.cj.jdbc.Driver</jdbc-driver>
|
||||||
|
<jdbc-url>jdbc:mysql://localhost:3306/iiabmdb</jdbc-url>
|
||||||
|
<working-dir>$ProjectFileDir$</working-dir>
|
||||||
|
</data-source>
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
5486
.idea/dataSources/8145438e-516b-4005-a581-b91b5eedc759.xml
generated
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
#n:iiabmdb
|
||||||
|
!<md> [0, 0, null, null, -2147483648, -2147483648]
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
#n:information_schema
|
||||||
|
!<md> [0, 0, null, null, -2147483648, -2147483648]
|
||||||
6
.idea/developer-tools.xml
generated
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="DeveloperToolsToolWindowSettingsV1" lastSelectedContentNodeId="base64-encoder-decoder">
|
||||||
|
<developerToolsConfigurations />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
4
.idea/encodings.xml
generated
@@ -1,6 +1,8 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project version="4">
|
<project version="4">
|
||||||
<component name="Encoding">
|
<component name="Encoding">
|
||||||
<file url="file://$PROJECT_DIR$/input_data/input_firm_data/Firm_amended.csv" charset="UTF-8" />
|
<file url="file://$PROJECT_DIR$/input_data/input_firm_data/firm_amended.csv" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/output_result/resilience/anova_visualization.csv" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/查看进度.py" charset="GBK" />
|
||||||
</component>
|
</component>
|
||||||
</project>
|
</project>
|
||||||
11
.idea/sqldialects.xml
generated
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="SqlDialectMappings">
|
||||||
|
<file url="file://$PROJECT_DIR$/SQL_analysis_experiment.sql" dialect="MySQL" />
|
||||||
|
<file url="file://$PROJECT_DIR$/SQL_analysis_risk.sql" dialect="MySQL" />
|
||||||
|
<file url="file://$PROJECT_DIR$/SQL_db_user_create.sql" dialect="MySQL" />
|
||||||
|
<file url="file://$PROJECT_DIR$/SQL_export_high_risk_setting.sql" dialect="MySQL" />
|
||||||
|
<file url="file://$PROJECT_DIR$/SQL_migrate_db.sql" dialect="MySQL" />
|
||||||
|
<file url="file://$PROJECT_DIR$/iiabmdb_basic_info.sql" dialect="MySQL" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
29
11.py
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
import pickle
|
||||||
|
import os
|
||||||
|
|
||||||
|
from 查看进度 import visualize_progress
|
||||||
|
|
||||||
|
|
||||||
|
def load_cached_data(file_path):
|
||||||
|
"""
|
||||||
|
从指定的缓存文件加载数据。
|
||||||
|
如果文件不存在或加载失败,则返回空字典。
|
||||||
|
"""
|
||||||
|
if not os.path.exists(file_path):
|
||||||
|
print(f"Warning: Cache file '{file_path}' does not exist.")
|
||||||
|
return {}
|
||||||
|
|
||||||
|
try:
|
||||||
|
with open(file_path, 'rb') as f:
|
||||||
|
data = pickle.load(f)
|
||||||
|
print(f"Successfully loaded cache from '{file_path}'.")
|
||||||
|
return data
|
||||||
|
except (pickle.UnpicklingError, FileNotFoundError, EOFError) as e:
|
||||||
|
print(f"Error loading cache from '{file_path}': {e}")
|
||||||
|
return {}
|
||||||
|
|
||||||
|
|
||||||
|
# 示例用法
|
||||||
|
# data_dct = load_cached_data("G_Firm_add_edges.pkl")
|
||||||
|
|
||||||
|
visualize_progress()
|
||||||
36
README.md
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
## 安装内容
|
||||||
|
1. 数据库,推荐使用mysql 8.0以上版本
|
||||||
|
2. Python 3.8
|
||||||
|
3. 通过pip等方法安装*requirements_manual_selected_20230304.txt*文件中的包
|
||||||
|
|
||||||
|
## 前期准备工作
|
||||||
|
1. 复制整个代码到本地
|
||||||
|
2. 用root及密码登录mysql,在本地数据库中创建一个数据库,命名为*iiabmdb*
|
||||||
|
3. 在mysql中运行*SQL_db_user_create.sql*里的sql命令,创建数据库用户。如果创建用户报错,需打开该文件,并运行第三行被注释掉的代码。该文件后面的sql命令也需要运行,将数据库用户的权限赋予*iiabmdb*数据库
|
||||||
|
4. 之后直接运行controller.py文件,如果没有报错,则说明前期准备工作完成
|
||||||
|
|
||||||
|
## 运行程序
|
||||||
|
1. 将*conf_db_prefix.yaml*文件中的*db_prefix*改为*db_name_prefix: without_exp*
|
||||||
|
2. 打开命令行,进入代码所在目录,运行
|
||||||
|
```shell
|
||||||
|
python main.py --exp without_exp --job 6 --reset_db True
|
||||||
|
```
|
||||||
|
3. 等待运行完成(1.2万个样本)。结束后,将*db_name_prefix: without_exp*改为*db_name_prefix: with_exp*,并运行
|
||||||
|
```shell
|
||||||
|
python main.py --exp with_exp --job 6 --reset_db True
|
||||||
|
```
|
||||||
|
4. 漫长的等待(3.4万个样本),直到运行完成
|
||||||
|
|
||||||
|
## 获得结果,绘制图表
|
||||||
|
|
||||||
|
### 风险节点分析
|
||||||
|
1. 运行*risk_analysis_sum_result.py*文件,该程序自动产生风险节点分析统计数据并放置到output_result/risk文件夹中
|
||||||
|
2. 依次运行*risk_analysis_prod_network.py*,*risk_analysis_firm_network.py*文件,将自动产生相关结果放置到output_result/risk文件夹中
|
||||||
|
|
||||||
|
### 韧性影响因素分析
|
||||||
|
1. 运行*SQL_analysis_experiment.sql*文件,将汇总结果手工复制至output_result/resilience文件夹*experiment_result.csv*文件中
|
||||||
|
2. 使用Minitab进行田口设计分析
|
||||||
|
3. 新建田口设计(统计——DOE——田口——创建田口设计——混合水平设计),因子数选项设置为8,设计选项设置为L36,水平^列为2^3,3^5,因子选项中将列名依次修改为:is_prf_size,is_prf_conn,ex_cap_type,n_max_trial,ex_cap_para,prob_new_conn,t_max_trial,n_sourcing
|
||||||
|
4. 将output_result/resilience文件夹*experiment_result.csv*文件中结果复制入田口设计表格右侧列
|
||||||
|
5. 依次对各个韧性指标进行田口设计分析(统计——DOE——田口——分析田口设计),从mean_count_firm_prod,mean_max_ts_firm_prod,mean_n_remove_firm_prod,mean_end_ts中选择一个韧性指标,图形选项勾选均值,分析选项中显示响应表勾选均值,拟合线性模型勾选均值,点击确定
|
||||||
|
6. 手工汇总方差分析结果至output_result/resilience文件夹*anova.csv*文件中,汇总响应表结果至*anova_visualization.csv*文件中
|
||||||
@@ -74,7 +74,7 @@ left join
|
|||||||
from iiabmdb.with_exp_result
|
from iiabmdb.with_exp_result
|
||||||
where `status` = "R"
|
where `status` = "R"
|
||||||
group by s_id, id_firm) as s_n_remove_prod
|
group by s_id, id_firm) as s_n_remove_prod
|
||||||
left join iiabmdb_basic_info.firm_n_prod as firm_n_prod
|
left join iiabmdb.firm_n_prod as firm_n_prod
|
||||||
on s_n_remove_prod.id_firm = firm_n_prod.code
|
on s_n_remove_prod.id_firm = firm_n_prod.code
|
||||||
where n_remove_prod = n_prod
|
where n_remove_prod = n_prod
|
||||||
group by s_id) as s_n_all_prod_remove_firm
|
group by s_id) as s_n_all_prod_remove_firm
|
||||||
|
|||||||
@@ -1,13 +1,16 @@
|
|||||||
CREATE DATABASE iiabmdb20230829;
|
-- 创建新的数据库
|
||||||
RENAME TABLE iiabmdb.not_test_experiment TO iiabmdb20230829.not_test_experiment,
|
CREATE DATABASE iiabmdb2025211;
|
||||||
iiabmdb.not_test_result TO iiabmdb20230829.not_test_result,
|
|
||||||
iiabmdb.not_test_sample TO iiabmdb20230829.not_test_sample,
|
-- 重命名表到新数据库
|
||||||
iiabmdb.test_experiment TO iiabmdb20230829.test_experiment,
|
RENAME TABLE
|
||||||
iiabmdb.test_result TO iiabmdb20230829.test_result,
|
iiabmdb.test_experiment TO iiabmdb2025211.test_experiment,
|
||||||
iiabmdb.test_sample TO iiabmdb20230829.test_sample;
|
iiabmdb.test_result TO iiabmdb2025211.test_result,
|
||||||
RENAME TABLE iiabmdb.with_exp_experiment TO iiabmdb20230829.with_exp_experiment,
|
iiabmdb.test_sample TO iiabmdb2025211.test_sample;
|
||||||
iiabmdb.with_exp_result TO iiabmdb20230829.with_exp_result,
|
|
||||||
iiabmdb.with_exp_sample TO iiabmdb20230829.with_exp_sample,
|
RENAME TABLE
|
||||||
iiabmdb.without_exp_experiment TO iiabmdb20230829.without_exp_experiment,
|
iiabmdb.with_exp_experiment TO iiabmdb2025211.with_exp_experiment,
|
||||||
iiabmdb.without_exp_result TO iiabmdb20230829.without_exp_result,
|
iiabmdb.with_exp_result TO iiabmdb2025211.with_exp_result,
|
||||||
iiabmdb.without_exp_sample TO iiabmdb20230829.without_exp_sample;
|
iiabmdb.with_exp_sample TO iiabmdb2025211.with_exp_sample,
|
||||||
|
iiabmdb.without_exp_experiment TO iiabmdb2025211.without_exp_experiment,
|
||||||
|
iiabmdb.without_exp_result TO iiabmdb2025211.without_exp_result,
|
||||||
|
iiabmdb.without_exp_sample TO iiabmdb2025211.without_exp_sample;
|
||||||
|
|||||||
BIN
__pycache__/Model.cpython-38.pyc
Normal file
BIN
__pycache__/computation.cpython-311.pyc
Normal file
BIN
__pycache__/main.cpython-38.pyc
Normal file
BIN
__pycache__/查看进度.cpython-38.pyc
Normal file
228
computation.py
@@ -1,6 +1,7 @@
|
|||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
import datetime
|
import datetime
|
||||||
|
import time
|
||||||
|
|
||||||
import networkx as nx
|
import networkx as nx
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
@@ -41,230 +42,7 @@ class Computation:
|
|||||||
'seed': sample_random.seed,
|
'seed': sample_random.seed,
|
||||||
**dct_exp}
|
**dct_exp}
|
||||||
|
|
||||||
product_network_test = nx.adjacency_graph(json.loads(dct_sample_para['g_bom']))
|
|
||||||
|
|
||||||
model = MyModel(dct_sample_para)
|
model = MyModel(dct_sample_para)
|
||||||
for i in range(1):
|
|
||||||
model.step()
|
|
||||||
print(i, datetime.datetime.now())
|
|
||||||
model.end()
|
|
||||||
return False
|
|
||||||
|
|
||||||
def initialize_firm_network(self):
|
model.step() # 运行仿真一步
|
||||||
# Read the firm data
|
model.end() # 汇总结果
|
||||||
|
|
||||||
firm = pd.read_csv("input_data/input_firm_data/Firm_amended.csv")
|
|
||||||
|
|
||||||
firm['Code'] = firm['Code'].astype(str)
|
|
||||||
|
|
||||||
firm.fillna(0, inplace=True)
|
|
||||||
|
|
||||||
firm_attr = firm.loc[:, ["Code", "Type_Region", "Revenue_Log"]]
|
|
||||||
|
|
||||||
firm_industry_relation = pd.read_csv("input_data/firm_industry_relation.csv")
|
|
||||||
firm_industry_relation['Firm_Code'] = firm_industry_relation['Firm_Code'].astype('string')
|
|
||||||
|
|
||||||
firm_product = []
|
|
||||||
|
|
||||||
grouped = firm_industry_relation.groupby('Firm_Code')['Product_Code'].apply(list)
|
|
||||||
firm_product.append(grouped)
|
|
||||||
|
|
||||||
firm_attr['Product_Code'] = firm_attr['Code'].map(grouped)
|
|
||||||
firm_attr.set_index('Code', inplace=True)
|
|
||||||
|
|
||||||
grouped = firm_industry_relation.groupby('Firm_Code')
|
|
||||||
self.firm_prod_labels_dict = {code: group['Product_Code'].tolist() for code, group in grouped}
|
|
||||||
|
|
||||||
# 遍历'Product_Code' 与 index 交换
|
|
||||||
for index, row in firm_attr.iterrows():
|
|
||||||
id_index_list = []
|
|
||||||
for i in row['Product_Code']:
|
|
||||||
for key_values in self.id_code.items():
|
|
||||||
if int(key_values[0]) == i:
|
|
||||||
for id in key_values[1]:
|
|
||||||
id_index_list.append(id)
|
|
||||||
firm_attr.at[index, 'Product_Code'] = id_index_list
|
|
||||||
|
|
||||||
self.G_Firm.add_nodes_from(firm["Code"])
|
|
||||||
# Assign attributes to the firm nodes
|
|
||||||
firm_labels_dict = {code: firm_attr.loc[code].to_dict() for code in self.G_Firm.nodes}
|
|
||||||
nx.set_node_attributes(self.G_Firm, firm_labels_dict)
|
|
||||||
|
|
||||||
self.Firm = firm
|
|
||||||
|
|
||||||
def initialize_firm_product_network(self):
|
|
||||||
|
|
||||||
firm_industry_relation = pd.read_csv("input_data/firm_industry_relation.csv")
|
|
||||||
firm_industry_relation['Firm_Code'] = firm_industry_relation['Firm_Code'].astype('string')
|
|
||||||
firm_industry_relation['Product_Code'] = firm_industry_relation['Product_Code'].apply(lambda x: [x])
|
|
||||||
# 将 'firm_prod' 表中的每一行作为图中的节点
|
|
||||||
self.G_FirmProd.add_nodes_from(firm_industry_relation.index)
|
|
||||||
# 为每个节点分配属性
|
|
||||||
|
|
||||||
# 遍历'Product_Code' 与 index 交换
|
|
||||||
for index, row in firm_industry_relation.iterrows():
|
|
||||||
id_index_list = []
|
|
||||||
for i in row['Product_Code']:
|
|
||||||
for key_values in self.id_code.items():
|
|
||||||
if int(key_values[0]) == i:
|
|
||||||
for id in key_values[1]:
|
|
||||||
id_index_list.append(id)
|
|
||||||
firm_industry_relation.at[index, 'Product_Code'] = id_index_list
|
|
||||||
|
|
||||||
firm_prod_labels_dict = {code: firm_industry_relation.loc[code].to_dict() for code in
|
|
||||||
firm_industry_relation.index}
|
|
||||||
nx.set_node_attributes(self.G_FirmProd, firm_prod_labels_dict)
|
|
||||||
|
|
||||||
def add_edges_to_firm_network(self):
|
|
||||||
""" Add edges between firms based on the product BOM relationships """
|
|
||||||
# Add edges to G_Firm according to G_bom
|
|
||||||
for node in nx.nodes(self.G_Firm):
|
|
||||||
lst_pred_product_code = []
|
|
||||||
for product_code in self.G_Firm.nodes[node]['Product_Code']:
|
|
||||||
lst_pred_product_code += list(self.G_bom.predecessors(product_code))
|
|
||||||
lst_pred_product_code = list(set(lst_pred_product_code))
|
|
||||||
lst_pred_product_code = list(sorted(lst_pred_product_code)) # Ensure consistency
|
|
||||||
|
|
||||||
for pred_product_code in lst_pred_product_code:
|
|
||||||
# Get a list of firms producing the component (pred_product_code)
|
|
||||||
lst_pred_firm = [firm_code for firm_code, product in self.firm_prod_labels_dict.items() if
|
|
||||||
pred_product_code in product]
|
|
||||||
|
|
||||||
# Select multiple suppliers (multi-sourcing)
|
|
||||||
n_pred_firm = self.int_netw_prf_n
|
|
||||||
if n_pred_firm > len(lst_pred_firm):
|
|
||||||
n_pred_firm = len(lst_pred_firm)
|
|
||||||
|
|
||||||
if self.is_prf_size:
|
|
||||||
# 获取 firm 的 size 列表
|
|
||||||
lst_pred_firm_size = [self.G_Firm.nodes[pred_firm]['Revenue_Log'] for pred_firm in lst_pred_firm]
|
|
||||||
# 检查 lst_pred_firm_size 是否为空或总和为 0
|
|
||||||
if len(lst_pred_firm_size) == 0 or sum(lst_pred_firm_size) == 0:
|
|
||||||
# print("警告: lst_pred_firm_size 为空或总和为 0,无法生成概率分布")
|
|
||||||
lst_choose_firm = [] # 返回空结果,或根据需要处理
|
|
||||||
else:
|
|
||||||
# 计算总和
|
|
||||||
sum_pred_firm_size = sum(lst_pred_firm_size)
|
|
||||||
# 归一化生成 lst_prob
|
|
||||||
lst_prob = [size / sum_pred_firm_size for size in lst_pred_firm_size]
|
|
||||||
# 使用 np.isclose() 确保概率总和接近 1
|
|
||||||
if not np.isclose(sum(lst_prob), 1.0):
|
|
||||||
# print(f"警告: 概率总和为 {sum(lst_prob)},现在进行修正")
|
|
||||||
lst_prob = [prob / sum(lst_prob) for prob in lst_prob]
|
|
||||||
# 确保没有负值或 0
|
|
||||||
lst_prob = [max(0, prob) for prob in lst_prob]
|
|
||||||
# 根据修正后的概率选择 firm
|
|
||||||
lst_choose_firm = self.nprandom.choice(lst_pred_firm, n_pred_firm, replace=False, p=lst_prob)
|
|
||||||
else:
|
|
||||||
# 直接进行随机选择
|
|
||||||
lst_choose_firm = self.nprandom.choice(lst_pred_firm, n_pred_firm, replace=False)
|
|
||||||
|
|
||||||
# Add edges from predecessor firms to current node (firm)
|
|
||||||
lst_add_edge = [(pred_firm, node, {'Product': pred_product_code}) for pred_firm in lst_choose_firm]
|
|
||||||
self.G_Firm.add_edges_from(lst_add_edge)
|
|
||||||
|
|
||||||
# Add edges to firm-product network
|
|
||||||
self.add_edges_to_firm_product_network(node, pred_product_code, lst_choose_firm)
|
|
||||||
|
|
||||||
def add_edges_to_firm_product_network(self, node, pred_product_code, lst_choose_firm):
|
|
||||||
""" Helper function to add edges to the firm-product network """
|
|
||||||
set_node_prod_code = set(self.G_Firm.nodes[node]['Product_Code'])
|
|
||||||
set_pred_succ_code = set(self.G_bom.successors(pred_product_code))
|
|
||||||
lst_use_pred_prod_code = list(set_node_prod_code & set_pred_succ_code)
|
|
||||||
|
|
||||||
if len(lst_use_pred_prod_code) == 0:
|
|
||||||
print("错误")
|
|
||||||
|
|
||||||
pred_node_list = []
|
|
||||||
for pred_firm in lst_choose_firm:
|
|
||||||
for n, v in self.G_FirmProd.nodes(data=True):
|
|
||||||
for v1 in v['Product_Code']:
|
|
||||||
if v1 == pred_product_code and v['Firm_Code'] == pred_firm:
|
|
||||||
pred_node_list.append(n)
|
|
||||||
if len(pred_node_list) != 0:
|
|
||||||
pred_node = pred_node_list[0]
|
|
||||||
else:
|
|
||||||
pred_node = -1
|
|
||||||
current_node_list = []
|
|
||||||
for use_pred_prod_code in lst_use_pred_prod_code:
|
|
||||||
for n, v in self.G_FirmProd.nodes(data=True):
|
|
||||||
for v1 in v['Product_Code']:
|
|
||||||
if v1 == use_pred_prod_code and v['Firm_Code'] == node:
|
|
||||||
current_node_list.append(n)
|
|
||||||
if len(current_node_list) != 0:
|
|
||||||
current_node = current_node_list[0]
|
|
||||||
else:
|
|
||||||
current_node = -1
|
|
||||||
if current_node != -1 and pred_node != -1:
|
|
||||||
self.G_FirmProd.add_edge(pred_node, current_node)
|
|
||||||
|
|
||||||
def connect_unconnected_nodes(self):
|
|
||||||
""" Connect unconnected nodes in the firm network """
|
|
||||||
for node in nx.nodes(self.G_Firm):
|
|
||||||
if self.G_Firm.degree(node) == 0:
|
|
||||||
current_node_list = []
|
|
||||||
for product_code in self.G_Firm.nodes[node]['Product_Code']:
|
|
||||||
for n, v in self.G_FirmProd.nodes(data=True):
|
|
||||||
for v1 in v['Product_Code']:
|
|
||||||
if v['Firm_Code'] == node and v1 == product_code:
|
|
||||||
current_node_list.append(n)
|
|
||||||
if len(current_node_list) != 0:
|
|
||||||
current_node = current_node_list[0]
|
|
||||||
else:
|
|
||||||
current_node = -1
|
|
||||||
lst_succ_product_code = list(self.G_bom.successors(product_code))
|
|
||||||
|
|
||||||
for succ_product_code in lst_succ_product_code:
|
|
||||||
lst_succ_firm = [firm_code for firm_code, product in self.firm_prod_labels_dict.items() if
|
|
||||||
succ_product_code in product]
|
|
||||||
|
|
||||||
n_succ_firm = self.int_netw_prf_n
|
|
||||||
if n_succ_firm > len(lst_succ_firm):
|
|
||||||
n_succ_firm = len(lst_succ_firm)
|
|
||||||
|
|
||||||
if self.is_prf_size:
|
|
||||||
lst_succ_firm_size = [self.G_Firm.nodes[succ_firm]['Revenue_Log'] for succ_firm in
|
|
||||||
lst_succ_firm]
|
|
||||||
if len(lst_succ_firm_size) == 0 or sum(lst_succ_firm_size) == 0:
|
|
||||||
# print("警告: lst_pred_firm_size 为空或总和为 0,无法生成概率分布")
|
|
||||||
lst_choose_firm = [] # 返回空结果,或根据需要处理
|
|
||||||
else:
|
|
||||||
# 计算总和
|
|
||||||
sum_pred_firm_size = sum(lst_succ_firm_size)
|
|
||||||
# 归一化生成 lst_prob
|
|
||||||
lst_prob = [size / sum_pred_firm_size for size in lst_succ_firm_size]
|
|
||||||
# 使用 np.isclose() 确保概率总和接近 1
|
|
||||||
if not np.isclose(sum(lst_prob), 1.0):
|
|
||||||
# print(f"警告: 概率总和为 {sum(lst_prob)},现在进行修正")
|
|
||||||
lst_prob = [prob / sum(lst_prob) for prob in lst_prob]
|
|
||||||
|
|
||||||
# 确保没有负值或 0
|
|
||||||
lst_prob = [max(0, prob) for prob in lst_prob]
|
|
||||||
|
|
||||||
lst_choose_firm = self.nprandom.choice(lst_succ_firm, n_succ_firm, replace=False,
|
|
||||||
p=lst_prob)
|
|
||||||
else:
|
|
||||||
lst_choose_firm = self.nprandom.choice(lst_succ_firm, n_succ_firm, replace=False)
|
|
||||||
|
|
||||||
lst_add_edge = [(node, succ_firm, {'Product': product_code}) for succ_firm in
|
|
||||||
lst_choose_firm]
|
|
||||||
self.G_Firm.add_edges_from(lst_add_edge)
|
|
||||||
|
|
||||||
# Add edges to firm-product network
|
|
||||||
succ_node_list = []
|
|
||||||
for succ_firm in lst_choose_firm:
|
|
||||||
for n, v in self.G_FirmProd.nodes(data=True):
|
|
||||||
for v1 in v['Product_Code']:
|
|
||||||
if v1 == succ_product_code and v['Firm_Code'] == succ_firm:
|
|
||||||
succ_node_list.append(n)
|
|
||||||
if len(succ_node_list) != 0:
|
|
||||||
succ_node = succ_node_list[0]
|
|
||||||
else:
|
|
||||||
succ_node = -1
|
|
||||||
|
|
||||||
if current_node != -1 and succ_node != -1:
|
|
||||||
self.G_FirmProd.add_edge(current_node, succ_node)
|
|
||||||
|
|
||||||
self.sample.g_firm = json.dumps(nx.adjacency_data(self.G_Firm))
|
|
||||||
self.firm_network = self.G_Firm # 直接使用 networkx 图对象
|
|
||||||
self.firm_prod_network = self.G_FirmProd # 直接使用 networkx 图对象
|
|
||||||
|
|||||||
@@ -53,7 +53,6 @@ class ControllerDB:
|
|||||||
|
|
||||||
# fill dct_lst_init_disrupt_firm_prod
|
# fill dct_lst_init_disrupt_firm_prod
|
||||||
# 存储 公司-在供应链结点的位置.. 0 :‘1.1’
|
# 存储 公司-在供应链结点的位置.. 0 :‘1.1’
|
||||||
list_dct = [] # 存储 公司编码code 和对应的产业链 结点
|
|
||||||
if self.is_with_exp:
|
if self.is_with_exp:
|
||||||
# 对于方差分析时候使用
|
# 对于方差分析时候使用
|
||||||
with open('SQL_export_high_risk_setting.sql', 'r') as f:
|
with open('SQL_export_high_risk_setting.sql', 'r') as f:
|
||||||
@@ -67,12 +66,27 @@ class ControllerDB:
|
|||||||
# 行索引 (index):这一行在数据帧中的索引值。
|
# 行索引 (index):这一行在数据帧中的索引值。
|
||||||
# 行数据 (row):这一行的数据,是一个 pandas.Series 对象,包含该行的所有列和值。
|
# 行数据 (row):这一行的数据,是一个 pandas.Series 对象,包含该行的所有列和值。
|
||||||
|
|
||||||
|
# 读取企业与产品关系数据
|
||||||
firm_industry = pd.read_csv("input_data/firm_industry_relation.csv")
|
firm_industry = pd.read_csv("input_data/firm_industry_relation.csv")
|
||||||
firm_industry['Firm_Code'] = firm_industry['Firm_Code'].astype('string')
|
firm_industry['Firm_Code'] = firm_industry['Firm_Code'].astype('string')
|
||||||
|
|
||||||
|
# 假设已从 BOM 数据构建了 code_to_indices
|
||||||
|
bom_nodes = pd.read_csv("input_data/input_product_data/BomNodes.csv")
|
||||||
|
code_to_indices = bom_nodes.groupby('Code')['Index'].apply(list).to_dict()
|
||||||
|
|
||||||
|
# 初始化存储映射结果的列表
|
||||||
|
list_dct = []
|
||||||
|
|
||||||
|
# 遍历 firm_industry 数据
|
||||||
for _, row in firm_industry.iterrows():
|
for _, row in firm_industry.iterrows():
|
||||||
code = row['Firm_Code']
|
firm_code = row['Firm_Code'] # 企业代码
|
||||||
row = row['Product_Code']
|
product_code = row['Product_Code'] # 原始产品代码
|
||||||
dct = {code: [row]}
|
|
||||||
|
# 使用 code_to_indices 映射 Product_Code 到 Product_Indices
|
||||||
|
mapped_indices = code_to_indices.get(product_code, []) # 如果找不到则返回空列表
|
||||||
|
|
||||||
|
# 构建企业到产品索引的映射
|
||||||
|
dct = {firm_code: mapped_indices}
|
||||||
list_dct.append(dct)
|
list_dct.append(dct)
|
||||||
|
|
||||||
# fill g_bom
|
# fill g_bom
|
||||||
|
|||||||
BIN
degree_distribution_firm.png
Normal file
|
After Width: | Height: | Size: 263 KiB |
BIN
degree_distribution_with_labels.png
Normal file
|
After Width: | Height: | Size: 267 KiB |
73
firm.py
@@ -2,7 +2,7 @@ from mesa import Agent
|
|||||||
|
|
||||||
|
|
||||||
class FirmAgent(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):
|
production_output, demand_quantity, R, P, C):
|
||||||
# 调用超类的 __init__ 方法
|
# 调用超类的 __init__ 方法
|
||||||
super().__init__(unique_id, model)
|
super().__init__(unique_id, model)
|
||||||
@@ -32,20 +32,20 @@ class FirmAgent(Agent):
|
|||||||
# 包括 产品时间
|
# 包括 产品时间
|
||||||
self.P1 = {0: P}
|
self.P1 = {0: P}
|
||||||
# 企业i的供应商
|
# 企业i的供应商
|
||||||
self.upper_i = [agent for u, v in self.firm_network.in_edges(self.unique_id)
|
self.upper_i = [self.model.agent_map[u] for u, v in self.firm_network.in_edges(self.unique_id)
|
||||||
for agent in self.model.company_agents if agent.unique_id == u]
|
if u in self.model.agent_map]
|
||||||
# 企业i的客户
|
# 企业i的客户
|
||||||
self.downer_i = [agent for u, v in self.firm_network.out_edges(self.unique_id)
|
self.downer_i = [self.model.agent_map[v] for u, v in self.firm_network.out_edges(self.unique_id)
|
||||||
for agent in self.model.company_agents if agent.unique_id == u]
|
if v in self.model.agent_map]
|
||||||
# 设备c的数量 (总量) 使用这个来判断设备数量
|
# 设备c的数量 (总量) 使用这个来判断设备数量
|
||||||
self.n_equip_c = n_equip_c
|
# self.n_equip_c = n_equip_c
|
||||||
# 设备c产量 根据设备量进行估算
|
# 设备c产量 根据设备量进行估算
|
||||||
self.c_yield = production_output
|
self.c_yield = production_output
|
||||||
# 消耗材料量 根据设备量进行估算 { }
|
# 消耗材料量 根据设备量进行估算 { }
|
||||||
self.c_consumption = demand_quantity
|
self.c_consumption = demand_quantity
|
||||||
# 设备c购买价格(初始值)
|
# 设备c购买价格(初始值)
|
||||||
# self.c_price = c_price
|
# self.c_price = c_price
|
||||||
# 资源r补货库存阈值
|
# 资源r补货库存阈值 很重要设置
|
||||||
self.s_r = 40
|
self.s_r = 40
|
||||||
self.S_r = 120
|
self.S_r = 120
|
||||||
# 设备补货阙值 可选
|
# 设备补货阙值 可选
|
||||||
@@ -143,41 +143,68 @@ class FirmAgent(Agent):
|
|||||||
# f"disrupted supplier of {disrupted_up_prod.code}")
|
# f"disrupted supplier of {disrupted_up_prod.code}")
|
||||||
|
|
||||||
def seek_alt_supply(self, product):
|
def seek_alt_supply(self, product):
|
||||||
|
# 检查当前产品的尝试次数是否达到最大值
|
||||||
if self.dct_n_trial_up_prod_disrupted[product] <= self.model.int_n_max_trial:
|
if self.dct_n_trial_up_prod_disrupted[product] <= self.model.int_n_max_trial:
|
||||||
|
# 初始化候选供应商列表
|
||||||
if self.dct_n_trial_up_prod_disrupted[product] == 0:
|
if self.dct_n_trial_up_prod_disrupted[product] == 0:
|
||||||
self.dct_cand_alt_supp_up_prod_disrupted[product] = [
|
self.dct_cand_alt_supp_up_prod_disrupted[product] = [
|
||||||
firm for firm in self.model.company_agents
|
firm for firm in self.model.company_agents if firm.is_prod_in_current_normal(product)
|
||||||
if firm.is_prod_in_current_normal(product)]
|
]
|
||||||
if self.dct_cand_alt_supp_up_prod_disrupted[product]:
|
|
||||||
|
# 如果没有候选供应商,直接退出
|
||||||
|
if not self.dct_cand_alt_supp_up_prod_disrupted[product]:
|
||||||
|
# print(f"No valid candidates found for product {product.unique_id}")
|
||||||
|
return
|
||||||
|
|
||||||
|
# 查找与当前企业已连接的候选供应商
|
||||||
lst_firm_connect = []
|
lst_firm_connect = []
|
||||||
if self.is_prf_conn:
|
if self.is_prf_conn:
|
||||||
for firm in self.dct_cand_alt_supp_up_prod_disrupted[product]:
|
lst_firm_connect = [
|
||||||
if self.firm_network.has_edge(self.unique_id, firm.unique_id) or \
|
firm for firm in self.dct_cand_alt_supp_up_prod_disrupted[product]
|
||||||
self.firm_network.has_edge(firm.unique_id, self.unique_id):
|
if self.firm_network.has_edge(self.unique_id, firm.unique_id) or
|
||||||
lst_firm_connect.append(firm)
|
self.firm_network.has_edge(firm.unique_id, self.unique_id)
|
||||||
if len(lst_firm_connect) == 0:
|
]
|
||||||
if self.is_prf_size:
|
|
||||||
|
# 如果没有连接的供应商
|
||||||
|
if not lst_firm_connect:
|
||||||
|
if self.is_prf_size: # 根据规模加权选择
|
||||||
lst_size = [firm.size_stat[-1][0] for firm in self.dct_cand_alt_supp_up_prod_disrupted[product]]
|
lst_size = [firm.size_stat[-1][0] for firm in self.dct_cand_alt_supp_up_prod_disrupted[product]]
|
||||||
lst_prob = [size / sum(lst_size) for size in lst_size]
|
lst_prob = [size / sum(lst_size) for size in lst_size]
|
||||||
select_alt_supply = \
|
select_alt_supply = self.random.choices(
|
||||||
self.random.choices(self.dct_cand_alt_supp_up_prod_disrupted[product], weights=lst_prob)[0]
|
self.dct_cand_alt_supp_up_prod_disrupted[product], weights=lst_prob
|
||||||
else:
|
)[0]
|
||||||
|
else: # 随机选择
|
||||||
select_alt_supply = self.random.choice(self.dct_cand_alt_supp_up_prod_disrupted[product])
|
select_alt_supply = self.random.choice(self.dct_cand_alt_supp_up_prod_disrupted[product])
|
||||||
elif len(lst_firm_connect) > 0:
|
else: # 如果存在连接的供应商
|
||||||
if self.is_prf_size:
|
if self.is_prf_size: # 根据规模加权选择
|
||||||
lst_firm_size = [firm.size_stat[-1][0] for firm in lst_firm_connect]
|
lst_firm_size = [firm.size_stat[-1][0] for firm in lst_firm_connect]
|
||||||
lst_prob = [size / sum(lst_firm_size) for size in lst_firm_size]
|
lst_prob = [size / sum(lst_firm_size) for size in lst_firm_size]
|
||||||
select_alt_supply = self.random.choices(lst_firm_connect, weights=lst_prob)[0]
|
select_alt_supply = self.random.choices(lst_firm_connect, weights=lst_prob)[0]
|
||||||
else:
|
else: # 随机选择
|
||||||
select_alt_supply = self.random.choice(lst_firm_connect)
|
select_alt_supply = self.random.choice(lst_firm_connect)
|
||||||
|
|
||||||
assert select_alt_supply.is_prod_in_current_normal(product)
|
# 检查选中的供应商是否能够生产产品
|
||||||
|
if not select_alt_supply.is_prod_in_current_normal(product):
|
||||||
|
# print(f"Selected supplier {select_alt_supply.unique_id} cannot produce product {product.unique_id}")
|
||||||
|
|
||||||
|
# 打印供应商的生产状态字典
|
||||||
|
#print(f"Supplier production state: {select_alt_supply.dct_prod_up_prod_stat}")
|
||||||
|
|
||||||
|
# 检查产品是否存在于生产状态字典中
|
||||||
|
if product in select_alt_supply.dct_prod_up_prod_stat:
|
||||||
|
print(
|
||||||
|
f"Product {product.unique_id} production state: {select_alt_supply.dct_prod_up_prod_stat[product]['p_stat']}")
|
||||||
|
else:
|
||||||
|
print(f"Product {product.unique_id} not found in supplier production state.")
|
||||||
|
return
|
||||||
|
|
||||||
|
# 添加到供应商的请求字典
|
||||||
if product in select_alt_supply.dct_request_prod_from_firm:
|
if product in select_alt_supply.dct_request_prod_from_firm:
|
||||||
select_alt_supply.dct_request_prod_from_firm[product].append(self)
|
select_alt_supply.dct_request_prod_from_firm[product].append(self)
|
||||||
else:
|
else:
|
||||||
select_alt_supply.dct_request_prod_from_firm[product] = [self]
|
select_alt_supply.dct_request_prod_from_firm[product] = [self]
|
||||||
|
|
||||||
|
# 更新尝试次数
|
||||||
self.dct_n_trial_up_prod_disrupted[product] += 1
|
self.dct_n_trial_up_prod_disrupted[product] += 1
|
||||||
|
|
||||||
def handle_request(self):
|
def handle_request(self):
|
||||||
|
|||||||
BIN
firm_network.pkl
Normal file
BIN
iiabmdb_basic_info.sql
Normal file
238
input_data/产品消耗制造比例.csv
Normal file
@@ -0,0 +1,238 @@
|
|||||||
|
IndustryID,MaterialID,Quantity
|
||||||
|
38,47,1.0
|
||||||
|
39,49,1.0
|
||||||
|
40,44,1.0
|
||||||
|
41,15,0.02
|
||||||
|
41,18,0.1
|
||||||
|
41,20,0.4
|
||||||
|
41,22,0.15
|
||||||
|
41,23,0.04
|
||||||
|
41,25,0.02
|
||||||
|
41,31,0.25
|
||||||
|
41,36,1.0
|
||||||
|
42,15,0.02
|
||||||
|
42,18,0.1
|
||||||
|
42,20,0.4
|
||||||
|
42,22,0.15
|
||||||
|
42,23,0.04
|
||||||
|
42,25,0.02
|
||||||
|
42,31,0.25
|
||||||
|
43,46,1.0
|
||||||
|
44,7,1.4
|
||||||
|
44,15,0.02
|
||||||
|
44,18,0.1
|
||||||
|
44,20,0.4
|
||||||
|
44,22,0.15
|
||||||
|
44,23,0.04
|
||||||
|
44,25,0.02
|
||||||
|
44,27,0.25
|
||||||
|
45,7,1.4
|
||||||
|
45,15,0.02
|
||||||
|
45,18,0.1
|
||||||
|
45,20,0.4
|
||||||
|
45,22,0.15
|
||||||
|
45,23,0.04
|
||||||
|
45,25,0.02
|
||||||
|
45,27,0.25
|
||||||
|
46,15,0.02
|
||||||
|
46,18,0.1
|
||||||
|
46,20,0.4
|
||||||
|
46,22,0.15
|
||||||
|
46,23,0.04
|
||||||
|
46,25,0.02
|
||||||
|
46,27,0.25
|
||||||
|
46,32,1.3
|
||||||
|
47,15,0.02
|
||||||
|
47,18,0.1
|
||||||
|
47,20,0.4
|
||||||
|
47,22,0.15
|
||||||
|
47,23,0.04
|
||||||
|
47,25,0.02
|
||||||
|
47,27,0.25
|
||||||
|
47,33,1.0
|
||||||
|
48,15,0.02
|
||||||
|
48,18,0.1
|
||||||
|
48,20,0.4
|
||||||
|
48,22,0.15
|
||||||
|
48,23,0.04
|
||||||
|
48,25,0.02
|
||||||
|
48,27,0.25
|
||||||
|
48,34,1.3
|
||||||
|
49,15,0.02
|
||||||
|
49,18,0.1
|
||||||
|
49,20,0.4
|
||||||
|
49,22,0.15
|
||||||
|
49,23,0.04
|
||||||
|
49,25,0.02
|
||||||
|
49,27,0.25
|
||||||
|
49,35,1.3
|
||||||
|
50,19,0.005
|
||||||
|
50,20,0.4
|
||||||
|
50,22,0.15
|
||||||
|
50,23,0.04
|
||||||
|
50,25,0.02
|
||||||
|
50,28,0.25
|
||||||
|
50,29,0.03
|
||||||
|
50,27,0.01
|
||||||
|
50,40,1.0
|
||||||
|
51,19,0.005
|
||||||
|
51,20,0.4
|
||||||
|
51,22,0.15
|
||||||
|
51,23,0.04
|
||||||
|
51,25,0.02
|
||||||
|
51,28,0.25
|
||||||
|
51,29,0.03
|
||||||
|
51,27,0.01
|
||||||
|
51,38,1.0
|
||||||
|
52,19,0.005
|
||||||
|
52,20,0.4
|
||||||
|
52,22,0.15
|
||||||
|
52,23,0.04
|
||||||
|
52,25,0.02
|
||||||
|
52,28,0.25
|
||||||
|
52,29,0.03
|
||||||
|
52,27,0.01
|
||||||
|
52,41,1.0
|
||||||
|
53,19,0.005
|
||||||
|
53,20,0.4
|
||||||
|
53,22,0.15
|
||||||
|
53,23,0.04
|
||||||
|
53,25,0.02
|
||||||
|
53,28,0.25
|
||||||
|
53,29,0.03
|
||||||
|
53,27,0.01
|
||||||
|
53,39,1.0
|
||||||
|
54,19,0.005
|
||||||
|
54,20,0.4
|
||||||
|
54,22,0.15
|
||||||
|
54,23,0.04
|
||||||
|
54,25,0.02
|
||||||
|
54,28,0.25
|
||||||
|
54,29,0.03
|
||||||
|
54,27,0.01
|
||||||
|
54,43,1.0
|
||||||
|
55,19,0.005
|
||||||
|
55,20,0.4
|
||||||
|
55,22,0.15
|
||||||
|
55,23,0.04
|
||||||
|
55,25,0.02
|
||||||
|
55,28,0.25
|
||||||
|
55,29,0.03
|
||||||
|
55,27,0.01
|
||||||
|
55,42,1.0
|
||||||
|
90,7,1.7
|
||||||
|
90,8,0.07
|
||||||
|
90,9,0.07
|
||||||
|
90,10,0.02
|
||||||
|
90,11,0.04
|
||||||
|
90,17,0.1
|
||||||
|
90,19,0.005
|
||||||
|
90,20,0.4
|
||||||
|
90,21,0.04
|
||||||
|
90,23,0.04
|
||||||
|
90,24,0.07
|
||||||
|
90,25,0.02
|
||||||
|
90,28,0.03
|
||||||
|
90,31,0.25
|
||||||
|
90,44,0.2
|
||||||
|
90,45,0.1
|
||||||
|
91,8,0.07
|
||||||
|
91,9,0.07
|
||||||
|
91,10,0.02
|
||||||
|
91,11,0.04
|
||||||
|
91,17,0.1
|
||||||
|
91,18,0.1
|
||||||
|
91,19,0.005
|
||||||
|
91,20,0.4
|
||||||
|
91,23,0.04
|
||||||
|
91,24,0.07
|
||||||
|
91,28,0.03
|
||||||
|
91,31,0.25
|
||||||
|
92,8,0.07
|
||||||
|
92,9,0.07
|
||||||
|
92,10,0.02
|
||||||
|
92,11,0.04
|
||||||
|
92,17,0.1
|
||||||
|
92,18,0.1
|
||||||
|
92,19,0.005
|
||||||
|
92,20,0.4
|
||||||
|
92,23,0.04
|
||||||
|
92,24,0.07
|
||||||
|
92,28,0.03
|
||||||
|
92,31,0.26
|
||||||
|
93,8,0.07
|
||||||
|
93,9,0.07
|
||||||
|
93,10,0.02
|
||||||
|
93,11,0.04
|
||||||
|
93,17,0.1
|
||||||
|
93,18,0.1
|
||||||
|
93,19,0.005
|
||||||
|
93,20,0.4
|
||||||
|
93,23,0.04
|
||||||
|
93,24,0.07
|
||||||
|
93,28,0.03
|
||||||
|
93,31,0.27
|
||||||
|
94,8,0.07
|
||||||
|
94,9,0.07
|
||||||
|
94,10,0.02
|
||||||
|
94,11,0.04
|
||||||
|
94,17,0.1
|
||||||
|
94,18,0.1
|
||||||
|
94,19,0.005
|
||||||
|
94,20,0.4
|
||||||
|
94,23,0.04
|
||||||
|
94,24,0.07
|
||||||
|
94,28,0.03
|
||||||
|
94,31,0.28
|
||||||
|
95,8,0.1
|
||||||
|
95,9,0.0
|
||||||
|
95,10,7.0
|
||||||
|
95,11,0.02
|
||||||
|
95,12,0.03
|
||||||
|
95,13,0.01
|
||||||
|
95,14,0.01
|
||||||
|
95,15,0.07
|
||||||
|
95,16,0.05
|
||||||
|
95,17,0.003
|
||||||
|
95,18,0.1
|
||||||
|
95,19,0.04
|
||||||
|
95,20,0.01
|
||||||
|
95,21,0.04
|
||||||
|
95,22,0.03
|
||||||
|
95,23,0.02
|
||||||
|
95,24,0.01
|
||||||
|
95,25,0.05
|
||||||
|
95,26,0.01
|
||||||
|
95,27,0.003
|
||||||
|
95,28,0.1
|
||||||
|
95,29,0.05
|
||||||
|
95,30,0.04
|
||||||
|
95,31,0.01
|
||||||
|
95,37,0.1
|
||||||
|
95,44,0.04
|
||||||
|
95,45,0.7
|
||||||
|
95,46,0.07
|
||||||
|
95,47,0.01
|
||||||
|
95,48,0.03
|
||||||
|
95,49,0.01
|
||||||
|
95,50,0.01
|
||||||
|
95,51,0.01
|
||||||
|
95,52,0.2
|
||||||
|
95,53,0.03
|
||||||
|
95,54,0.01
|
||||||
|
95,55,0.01
|
||||||
|
95,90,0.01
|
||||||
|
95,91,0.01
|
||||||
|
95,92,1.0
|
||||||
|
95,93,1.0
|
||||||
|
95,94,1.0
|
||||||
|
96,95,1.0
|
||||||
|
96,101,0.01
|
||||||
|
96,102,0.01
|
||||||
|
96,103,0.02
|
||||||
|
96,104,0.01
|
||||||
|
96,105,0.2
|
||||||
|
96,106,0.1
|
||||||
|
96,107,0.01
|
||||||
|
96,108,0.03
|
||||||
|
96,109,0.02
|
||||||
|
14
main.py
@@ -3,6 +3,9 @@ import random
|
|||||||
import time
|
import time
|
||||||
from multiprocessing import Process
|
from multiprocessing import Process
|
||||||
import argparse
|
import argparse
|
||||||
|
|
||||||
|
from matplotlib import pyplot as plt
|
||||||
|
|
||||||
from computation import Computation
|
from computation import Computation
|
||||||
from sqlalchemy.orm import close_all_sessions
|
from sqlalchemy.orm import close_all_sessions
|
||||||
import yaml
|
import yaml
|
||||||
@@ -30,11 +33,16 @@ def do_process(target: object, controller_db: ControllerDB, ):
|
|||||||
|
|
||||||
for i in process_list:
|
for i in process_list:
|
||||||
i.join()
|
i.join()
|
||||||
|
|
||||||
|
# 所有子进程完成后刷新最终进度
|
||||||
|
|
||||||
|
# 显示最终进度后关闭图表
|
||||||
|
|
||||||
def do_computation(c_db):
|
def do_computation(c_db):
|
||||||
exp = Computation(c_db)
|
exp = Computation(c_db)
|
||||||
|
|
||||||
while 1:
|
while 1:
|
||||||
time.sleep(random.uniform(0, 1))
|
# time.sleep(random.uniform(0, 1))
|
||||||
is_all_done = exp.run()
|
is_all_done = exp.run()
|
||||||
if is_all_done:
|
if is_all_done:
|
||||||
break
|
break
|
||||||
@@ -44,9 +52,9 @@ if __name__ == '__main__':
|
|||||||
# 输入参数
|
# 输入参数
|
||||||
parser = argparse.ArgumentParser(description='setting')
|
parser = argparse.ArgumentParser(description='setting')
|
||||||
parser.add_argument('--exp', type=str, default='without_exp')
|
parser.add_argument('--exp', type=str, default='without_exp')
|
||||||
parser.add_argument('--job', type=int, default='1')
|
parser.add_argument('--job', type=int, default='4')
|
||||||
parser.add_argument('--reset_sample', type=int, default='0')
|
parser.add_argument('--reset_sample', type=int, default='0')
|
||||||
parser.add_argument('--reset_db', type=bool, default=False)
|
parser.add_argument('--reset_db', type=bool, default=True)
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
# 几核参与进程
|
# 几核参与进程
|
||||||
|
|||||||
1071
my_model.py
4
orm.py
@@ -98,8 +98,8 @@ class Result(Base):
|
|||||||
s_id = Column(Integer, ForeignKey('{}.id'.format(
|
s_id = Column(Integer, ForeignKey('{}.id'.format(
|
||||||
f"{db_name_prefix}_sample")), nullable=False)
|
f"{db_name_prefix}_sample")), nullable=False)
|
||||||
|
|
||||||
id_firm = Column(String(10), nullable=False)
|
id_firm = Column(String(20), nullable=False)
|
||||||
id_product = Column(String(10), nullable=False)
|
id_product = Column(String(20), nullable=False)
|
||||||
ts = Column(Integer, nullable=False)
|
ts = Column(Integer, nullable=False)
|
||||||
status = Column(String(5), nullable=False)
|
status = Column(String(5), nullable=False)
|
||||||
|
|
||||||
|
|||||||
9
output_result/resilience/anova.csv
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
Unnamed: 0.1,Unnamed: 0,mean_end_ts,mean_n_remove_firm_prod,mean_max_ts_firm_prod,mean_count_firm_prod
|
||||||
|
p1,n_sourcing,0.319,0.145,0.043,0.186
|
||||||
|
p2,is_prf_size,0.607,0.608,0.005,0.111
|
||||||
|
p3,n_max_trial,0.003,0.135,0.0,0.0
|
||||||
|
p4,is_prf_conn,0.504,0.567,0.001,0.0
|
||||||
|
p5,ex_cap_type,0.403,0.667,0.329,0.444
|
||||||
|
p6,ex_cap_para,0.0,0.0,0.0,0.0
|
||||||
|
p7,prob_new_conn,0.017,0.334,0.01,0.007
|
||||||
|
p8,t_max_trial,0.0,0.014,0.939,0.1
|
||||||
|
22
output_result/resilience/anova_visualization.csv
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
自变量,level,系统恢复用时R1,产业-企业边累计扰乱次数R2,产业-企业边最大传导深度R3,产业-企业边断裂总数R4
|
||||||
|
采购策略P1,三供应商,3.549,62.11,1.715,22.14
|
||||||
|
采购策略P1,双供应商,3.743,62.43,1.759,21.71
|
||||||
|
采购策略P1,单供应商,3.668,62.21,1.736,22.17
|
||||||
|
是否规模偏好P2,倾向,3.681,62.13,1.715,22.06
|
||||||
|
是否规模偏好P2,不倾向,3.627,62.37,1.758,21.96
|
||||||
|
最大尝试次数P3,高,3.47,61.08,1.636,21.85
|
||||||
|
最大尝试次数P3,中,3.552,62.08,1.742,21.86
|
||||||
|
最大尝试次数P3,低,3.939,63.58,1.832,22.31
|
||||||
|
是否已有连接偏好P4,倾向,3.619,61.95,1.711,21.95
|
||||||
|
是否已有连接偏好P4,不倾向,3.689,62.55,1.762,22.07
|
||||||
|
额外产能分布P5,均匀分布,3.698,62.19,1.73,21.96
|
||||||
|
额外产能分布P5,正态分布,3.61,62.3,1.743,22.05
|
||||||
|
额外产能分布参数P6,高,2.949,61.48,1.808,12.41
|
||||||
|
额外产能分布参数P6,中,3.787,62.2,1.661,22.87
|
||||||
|
额外产能分布参数P6,低,4.224,63.06,1.741,30.75
|
||||||
|
新供应关系构成概率P7,低,3.882,62.41,1.749,22.2
|
||||||
|
新供应关系构成概率P7,中,3.543,62.44,1.756,22.01
|
||||||
|
新供应关系构成概率P7,高,3.535,61.9,1.705,21.82
|
||||||
|
最大尝试时间步P8,低,2.601,62.03,1.738,22.47
|
||||||
|
最大尝试时间步P8,中,3.656,62.31,1.733,21.78
|
||||||
|
最大尝试时间步P8,高,4.704,62.4,1.738,21.78
|
||||||
|
37
output_result/resilience/experiment_result.csv
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
idx_scenario,n_max_trial,prf_size,prf_conn,cap_limit_prob_type,cap_limit_level,diff_new_conn,remove_t,netw_prf_n,mean_count_firm_prod,mean_count_firm,mean_count_prod,mean_max_ts_firm_prod,mean_max_ts_firm,mean_max_ts_prod,mean_n_remove_firm_prod,mean_n_all_prod_remove_firm,mean_end_ts,
|
||||||
|
0,7,1,1,uniform,5.0000,0.3000,3,3,59.6916,15.7589,13.3347,1.5063,1.5032,1.3842,12.3074,1.5379,2.0400
|
||||||
|
1,5,1,1,uniform,10.0000,0.5000,5,2,61.8937,17.1126,13.8095,1.7284,1.7263,1.6042,22.7779,2.9611,3.7432
|
||||||
|
2,3,1,1,uniform,15.0000,0.7000,7,1,63.9568,18.2253,14.2779,1.8263,1.8221,1.7347,30.9263,3.7842,5.6253
|
||||||
|
3,7,1,1,uniform,5.0000,0.3000,3,2,59.5811,15.7474,13.3168,1.4958,1.4937,1.3884,12.8358,1.4621,2.0221
|
||||||
|
4,5,1,1,uniform,10.0000,0.5000,5,1,61.8200,17.0116,13.8053,1.7095,1.7084,1.6032,22.5474,2.9579,3.6811
|
||||||
|
5,3,1,1,uniform,15.0000,0.7000,7,3,63.8821,18.2547,14.2432,1.8421,1.8305,1.7295,30.9474,3.7411,5.6632
|
||||||
|
6,7,1,1,normal,5.0000,0.5000,7,3,59.9116,15.7516,13.3316,1.4905,1.4884,1.3674,12.2463,1.3326,3.1600
|
||||||
|
7,5,1,1,normal,10.0000,0.7000,3,2,61.3095,16.8326,13.7716,1.7011,1.7011,1.6011,22.4779,2.9642,2.4916
|
||||||
|
8,3,1,1,normal,15.0000,0.3000,5,1,63.6568,18.1316,14.2358,1.8253,1.8232,1.7242,31.1253,3.7400,4.3474
|
||||||
|
9,7,1,0,uniform,5.0000,0.7000,5,3,59.7158,15.6811,13.3000,1.4600,1.4568,1.3537,12.4063,1.3400,2.5316
|
||||||
|
10,5,1,0,uniform,10.0000,0.3000,7,2,63.0063,17.6695,14.0432,1.8063,1.8053,1.6747,22.6916,3.0042,5.1126
|
||||||
|
11,3,1,0,uniform,15.0000,0.5000,3,1,63.6779,18.3842,14.3547,1.8621,1.8600,1.7621,31.3663,4.0253,2.9632
|
||||||
|
12,7,1,0,normal,10.0000,0.7000,3,1,60.6295,16.3884,13.5811,1.6179,1.6147,1.5147,22.5221,2.7800,2.3495
|
||||||
|
13,5,1,0,normal,15.0000,0.3000,5,3,63.3484,18.0042,14.2074,1.8316,1.8263,1.7232,30.6379,3.7747,4.2979
|
||||||
|
14,3,1,0,normal,5.0000,0.5000,7,2,64.0737,18.3684,14.3000,1.8505,1.8484,1.7589,11.4789,1.1663,4.1400
|
||||||
|
15,7,1,0,normal,10.0000,0.7000,5,3,61.0337,16.5684,13.6053,1.6358,1.6347,1.5074,22.7474,2.8937,3.5147
|
||||||
|
16,5,1,0,normal,15.0000,0.3000,7,2,63.4747,18.0568,14.1989,1.8347,1.8305,1.7263,30.4063,3.7989,5.7295
|
||||||
|
17,3,1,0,normal,5.0000,0.5000,3,1,63.7158,18.2863,14.2958,1.8547,1.8537,1.7579,14.6568,2.1432,2.8368
|
||||||
|
18,7,0,1,normal,10.0000,0.3000,7,1,61.2326,16.6442,13.6789,1.6705,1.6684,1.5495,22.5453,2.8379,4.7474
|
||||||
|
19,5,0,1,normal,15.0000,0.5000,3,3,62.3863,17.4684,13.9905,1.7874,1.7853,1.6705,31.1558,3.8189,2.7926
|
||||||
|
20,3,0,1,normal,5.0000,0.7000,5,2,62.8305,17.6074,14.0811,1.7705,1.7695,1.6768,11.7621,1.2474,3.2684
|
||||||
|
21,7,0,1,normal,10.0000,0.5000,7,1,61.1832,16.5389,13.6874,1.6505,1.6484,1.5337,22.8484,2.8147,4.7326
|
||||||
|
22,5,0,1,normal,15.0000,0.7000,3,3,62.3305,17.5337,14.0011,1.7768,1.7747,1.6495,30.6705,3.7832,2.7316
|
||||||
|
23,3,0,1,normal,5.0000,0.3000,5,2,62.8821,17.6916,14.0905,1.7821,1.7821,1.6895,12.2158,1.3442,3.3484
|
||||||
|
24,7,0,1,uniform,15.0000,0.5000,3,2,62.2463,17.4084,13.9789,1.7979,1.7958,1.6674,30.6842,3.7126,2.7589
|
||||||
|
25,5,0,1,uniform,5.0000,0.7000,5,1,60.9453,16.4442,13.6316,1.6274,1.6263,1.5032,12.2347,1.2663,2.7368
|
||||||
|
26,3,0,1,uniform,10.0000,0.3000,7,3,63.3400,17.8968,14.1147,1.8084,1.8074,1.6937,22.7768,3.0442,5.2442
|
||||||
|
27,7,0,0,normal,15.0000,0.5000,5,2,62.6505,17.5074,14.0032,1.7811,1.7800,1.6758,30.0211,3.6116,4.1263
|
||||||
|
28,5,0,0,normal,5.0000,0.7000,7,1,60.9200,16.5126,13.6168,1.6368,1.6358,1.5168,11.9432,1.2495,3.3305
|
||||||
|
29,3,0,0,normal,10.0000,0.3000,3,3,63.9074,18.4432,14.3916,1.8811,1.8779,1.7789,25.4905,3.4789,3.0295
|
||||||
|
30,7,0,0,uniform,15.0000,0.7000,7,2,62.2442,17.2747,13.9400,1.7400,1.7358,1.6253,30.5084,3.6589,5.4421
|
||||||
|
31,5,0,0,uniform,5.0000,0.3000,3,1,61.9147,17.2211,13.9347,1.7558,1.7526,1.6453,12.8168,1.6895,2.4516
|
||||||
|
32,3,0,0,uniform,10.0000,0.5000,5,3,64.1074,18.3579,14.3558,1.8579,1.8568,1.7505,22.2800,3.0684,4.0642
|
||||||
|
33,7,0,0,uniform,15.0000,0.3000,5,1,62.8737,17.5600,14.0642,1.7895,1.7874,1.6684,30.5453,3.6695,4.2147
|
||||||
|
34,5,0,0,uniform,5.0000,0.5000,7,3,61.6337,16.9042,13.7632,1.7032,1.7011,1.5716,12.0011,1.2263,3.5221
|
||||||
|
35,3,0,0,uniform,10.0000,0.7000,3,2,62.9663,17.9737,14.2221,1.8221,1.8211,1.7211,22.6979,3.1600,2.7389
|
||||||
|
BIN
output_result/risk/count_dcp_network.png
Normal file
|
After Width: | Height: | Size: 1.1 MiB |
@@ -1,23 +1,710 @@
|
|||||||
up_id_product,down_id_product,count
|
up_id_product,down_id_product,count
|
||||||
2.1.3.7,2.1.3,7
|
46,52,8413
|
||||||
1.3.1.3,1.3.1,5
|
48,52,8375
|
||||||
2.1.3.4,2.1.3,4
|
48,55,8345
|
||||||
2.1.3.2,2.1.3,3
|
46,55,8328
|
||||||
1.3.3.3,1.3.3,3
|
45,52,8274
|
||||||
1.1.1,1.1,2
|
44,52,8248
|
||||||
1.3.4.2,1.3.4,2
|
49,52,8246
|
||||||
2.1.1.5,2.1.1,2
|
49,55,8197
|
||||||
1.3.4.3,1.3.4,2
|
44,55,8172
|
||||||
2.3.1,2.3,2
|
45,55,8151
|
||||||
1.3.1.5,1.3.1,2
|
47,52,8077
|
||||||
1.3.3.4,1.3.3,1
|
47,55,8016
|
||||||
1.1.3,1.1,1
|
55,99,7248
|
||||||
1.4.5.6,1.4.5,1
|
52,99,7163
|
||||||
2.1.1.4,2.1.1,1
|
50,99,7085
|
||||||
1.3.1.7,1.3.1,1
|
54,99,7066
|
||||||
2.1.2.2,2.1.2,1
|
51,99,7031
|
||||||
1.3.1.4,1.3.1,1
|
53,99,7010
|
||||||
1.3.1.1,1.3.1,1
|
54,55,5570
|
||||||
2.1.4.1.1,2.1.4.1,1
|
54,52,5539
|
||||||
2.2,2,1
|
53,55,5524
|
||||||
1.4.3.4,1.4.3,1
|
52,55,5462
|
||||||
|
51,55,5441
|
||||||
|
50,55,5440
|
||||||
|
53,52,5438
|
||||||
|
55,52,5379
|
||||||
|
51,52,5312
|
||||||
|
50,52,5296
|
||||||
|
55,55,5254
|
||||||
|
52,52,5177
|
||||||
|
45,99,5036
|
||||||
|
46,99,4997
|
||||||
|
48,99,4976
|
||||||
|
44,99,4960
|
||||||
|
49,99,4941
|
||||||
|
55,95,4906
|
||||||
|
52,95,4895
|
||||||
|
47,99,4812
|
||||||
|
53,95,4643
|
||||||
|
51,95,4628
|
||||||
|
50,95,4578
|
||||||
|
54,95,4539
|
||||||
|
95,99,3147
|
||||||
|
47,95,3060
|
||||||
|
44,95,3028
|
||||||
|
46,95,3026
|
||||||
|
48,95,3021
|
||||||
|
49,95,3013
|
||||||
|
45,95,2937
|
||||||
|
46,43,2771
|
||||||
|
48,43,2748
|
||||||
|
45,43,2740
|
||||||
|
49,43,2738
|
||||||
|
44,43,2721
|
||||||
|
47,43,2720
|
||||||
|
49,39,2461
|
||||||
|
45,39,2460
|
||||||
|
48,39,2452
|
||||||
|
44,39,2427
|
||||||
|
46,39,2409
|
||||||
|
47,39,2378
|
||||||
|
54,43,2375
|
||||||
|
53,43,2366
|
||||||
|
55,43,2364
|
||||||
|
50,43,2338
|
||||||
|
52,43,2328
|
||||||
|
51,43,2327
|
||||||
|
44,40,2305
|
||||||
|
45,40,2296
|
||||||
|
48,40,2289
|
||||||
|
46,40,2287
|
||||||
|
49,40,2265
|
||||||
|
47,40,2257
|
||||||
|
47,38,2240
|
||||||
|
49,38,2224
|
||||||
|
45,38,2214
|
||||||
|
46,38,2200
|
||||||
|
54,39,2195
|
||||||
|
53,39,2184
|
||||||
|
48,38,2183
|
||||||
|
55,39,2177
|
||||||
|
51,39,2162
|
||||||
|
50,39,2156
|
||||||
|
44,38,2154
|
||||||
|
52,39,2147
|
||||||
|
48,90,2100
|
||||||
|
49,90,2092
|
||||||
|
45,90,2088
|
||||||
|
46,90,2077
|
||||||
|
47,90,2062
|
||||||
|
44,90,2054
|
||||||
|
94,99,2051
|
||||||
|
93,99,2019
|
||||||
|
91,99,1996
|
||||||
|
54,40,1977
|
||||||
|
50,40,1976
|
||||||
|
53,40,1973
|
||||||
|
55,40,1966
|
||||||
|
51,40,1964
|
||||||
|
52,40,1937
|
||||||
|
54,38,1928
|
||||||
|
50,38,1910
|
||||||
|
51,38,1900
|
||||||
|
53,38,1893
|
||||||
|
55,38,1888
|
||||||
|
52,38,1883
|
||||||
|
42,55,1788
|
||||||
|
41,52,1779
|
||||||
|
95,55,1734
|
||||||
|
95,52,1729
|
||||||
|
42,52,1717
|
||||||
|
41,55,1699
|
||||||
|
53,90,1629
|
||||||
|
55,90,1628
|
||||||
|
54,90,1623
|
||||||
|
51,90,1619
|
||||||
|
52,90,1606
|
||||||
|
50,90,1597
|
||||||
|
94,52,1207
|
||||||
|
92,99,1179
|
||||||
|
94,55,1143
|
||||||
|
94,95,1124
|
||||||
|
91,52,1084
|
||||||
|
93,55,1073
|
||||||
|
93,52,1065
|
||||||
|
91,55,1057
|
||||||
|
93,95,1005
|
||||||
|
91,95,1005
|
||||||
|
90,99,997
|
||||||
|
95,95,798
|
||||||
|
41,99,778
|
||||||
|
42,99,765
|
||||||
|
92,95,670
|
||||||
|
92,55,644
|
||||||
|
92,52,625
|
||||||
|
95,43,563
|
||||||
|
95,39,543
|
||||||
|
90,95,523
|
||||||
|
95,40,495
|
||||||
|
42,95,464
|
||||||
|
95,38,453
|
||||||
|
41,95,441
|
||||||
|
90,52,419
|
||||||
|
95,90,407
|
||||||
|
41,43,403
|
||||||
|
20,55,402
|
||||||
|
42,43,394
|
||||||
|
90,55,390
|
||||||
|
20,52,384
|
||||||
|
41,39,381
|
||||||
|
42,39,376
|
||||||
|
41,40,345
|
||||||
|
41,38,341
|
||||||
|
7,95,340
|
||||||
|
42,40,334
|
||||||
|
42,38,332
|
||||||
|
60,55,318
|
||||||
|
60,52,316
|
||||||
|
64,55,308
|
||||||
|
67,55,300
|
||||||
|
42,90,299
|
||||||
|
23,52,299
|
||||||
|
25,52,297
|
||||||
|
65,55,296
|
||||||
|
23,55,296
|
||||||
|
71,55,296
|
||||||
|
65,52,295
|
||||||
|
25,55,294
|
||||||
|
64,52,292
|
||||||
|
67,52,290
|
||||||
|
22,52,288
|
||||||
|
22,55,287
|
||||||
|
41,90,284
|
||||||
|
71,52,282
|
||||||
|
18,52,259
|
||||||
|
15,48,258
|
||||||
|
27,49,255
|
||||||
|
18,46,252
|
||||||
|
28,51,250
|
||||||
|
27,47,250
|
||||||
|
68,55,250
|
||||||
|
29,55,250
|
||||||
|
63,55,250
|
||||||
|
72,51,249
|
||||||
|
41,53,249
|
||||||
|
43,53,249
|
||||||
|
38,53,249
|
||||||
|
69,55,249
|
||||||
|
23,49,249
|
||||||
|
42,53,249
|
||||||
|
39,53,249
|
||||||
|
23,45,248
|
||||||
|
69,52,248
|
||||||
|
68,52,248
|
||||||
|
94,43,248
|
||||||
|
20,44,248
|
||||||
|
65,45,248
|
||||||
|
40,51,247
|
||||||
|
41,51,247
|
||||||
|
38,51,247
|
||||||
|
39,51,247
|
||||||
|
71,54,247
|
||||||
|
15,46,247
|
||||||
|
63,50,247
|
||||||
|
43,51,247
|
||||||
|
42,51,247
|
||||||
|
71,51,246
|
||||||
|
62,53,246
|
||||||
|
25,44,246
|
||||||
|
39,55,246
|
||||||
|
72,50,246
|
||||||
|
67,48,246
|
||||||
|
40,53,246
|
||||||
|
43,55,246
|
||||||
|
68,51,246
|
||||||
|
40,55,246
|
||||||
|
38,55,246
|
||||||
|
18,44,246
|
||||||
|
69,51,246
|
||||||
|
23,50,246
|
||||||
|
65,46,246
|
||||||
|
20,48,246
|
||||||
|
67,49,245
|
||||||
|
72,54,245
|
||||||
|
22,50,245
|
||||||
|
33,47,245
|
||||||
|
62,51,244
|
||||||
|
68,54,244
|
||||||
|
64,46,244
|
||||||
|
23,44,244
|
||||||
|
67,51,244
|
||||||
|
18,48,244
|
||||||
|
23,47,244
|
||||||
|
69,53,244
|
||||||
|
19,52,243
|
||||||
|
65,47,243
|
||||||
|
60,45,243
|
||||||
|
65,54,243
|
||||||
|
67,44,243
|
||||||
|
28,52,243
|
||||||
|
67,54,243
|
||||||
|
60,54,243
|
||||||
|
71,49,243
|
||||||
|
20,46,243
|
||||||
|
19,51,242
|
||||||
|
20,54,242
|
||||||
|
63,53,242
|
||||||
|
65,48,242
|
||||||
|
62,52,242
|
||||||
|
64,54,242
|
||||||
|
25,49,242
|
||||||
|
71,45,242
|
||||||
|
27,46,242
|
||||||
|
69,50,241
|
||||||
|
27,55,241
|
||||||
|
67,46,241
|
||||||
|
64,50,241
|
||||||
|
64,45,241
|
||||||
|
18,45,241
|
||||||
|
60,44,241
|
||||||
|
20,49,241
|
||||||
|
19,55,241
|
||||||
|
19,54,241
|
||||||
|
63,52,241
|
||||||
|
60,48,240
|
||||||
|
25,53,240
|
||||||
|
25,50,240
|
||||||
|
15,49,240
|
||||||
|
28,54,240
|
||||||
|
72,55,240
|
||||||
|
60,49,240
|
||||||
|
27,48,240
|
||||||
|
20,53,240
|
||||||
|
19,50,240
|
||||||
|
23,46,240
|
||||||
|
40,52,239
|
||||||
|
60,53,239
|
||||||
|
38,52,239
|
||||||
|
67,47,239
|
||||||
|
39,52,239
|
||||||
|
35,49,239
|
||||||
|
68,50,239
|
||||||
|
64,53,239
|
||||||
|
43,52,239
|
||||||
|
22,53,239
|
||||||
|
20,47,238
|
||||||
|
25,51,238
|
||||||
|
65,53,238
|
||||||
|
15,44,238
|
||||||
|
18,49,238
|
||||||
|
60,47,238
|
||||||
|
28,53,238
|
||||||
|
27,51,238
|
||||||
|
29,50,238
|
||||||
|
27,53,238
|
||||||
|
29,53,238
|
||||||
|
68,53,237
|
||||||
|
67,53,237
|
||||||
|
23,48,237
|
||||||
|
67,50,237
|
||||||
|
34,48,237
|
||||||
|
72,52,237
|
||||||
|
32,46,237
|
||||||
|
27,50,237
|
||||||
|
63,51,236
|
||||||
|
19,53,236
|
||||||
|
23,54,236
|
||||||
|
71,48,236
|
||||||
|
25,45,236
|
||||||
|
15,47,236
|
||||||
|
22,48,236
|
||||||
|
20,50,236
|
||||||
|
27,44,236
|
||||||
|
22,46,235
|
||||||
|
20,51,235
|
||||||
|
38,50,235
|
||||||
|
41,50,235
|
||||||
|
39,50,235
|
||||||
|
64,51,235
|
||||||
|
22,44,235
|
||||||
|
67,45,235
|
||||||
|
40,50,235
|
||||||
|
42,50,235
|
||||||
|
28,50,235
|
||||||
|
27,54,235
|
||||||
|
27,52,235
|
||||||
|
43,50,235
|
||||||
|
60,50,234
|
||||||
|
18,55,234
|
||||||
|
25,47,234
|
||||||
|
25,48,234
|
||||||
|
65,49,234
|
||||||
|
62,54,233
|
||||||
|
64,49,233
|
||||||
|
62,55,233
|
||||||
|
71,46,233
|
||||||
|
65,50,233
|
||||||
|
72,53,233
|
||||||
|
22,47,233
|
||||||
|
22,45,233
|
||||||
|
29,51,233
|
||||||
|
15,45,232
|
||||||
|
65,44,232
|
||||||
|
22,49,232
|
||||||
|
18,47,232
|
||||||
|
64,48,232
|
||||||
|
71,53,232
|
||||||
|
23,53,231
|
||||||
|
27,45,231
|
||||||
|
20,45,231
|
||||||
|
63,54,231
|
||||||
|
28,55,231
|
||||||
|
22,54,231
|
||||||
|
22,51,230
|
||||||
|
71,47,230
|
||||||
|
60,51,230
|
||||||
|
60,46,230
|
||||||
|
62,50,230
|
||||||
|
25,46,229
|
||||||
|
25,54,229
|
||||||
|
29,54,228
|
||||||
|
50,45,227
|
||||||
|
23,51,227
|
||||||
|
48,45,227
|
||||||
|
49,45,227
|
||||||
|
55,45,227
|
||||||
|
51,45,227
|
||||||
|
54,45,227
|
||||||
|
52,45,227
|
||||||
|
7,45,227
|
||||||
|
53,45,227
|
||||||
|
47,45,227
|
||||||
|
65,51,227
|
||||||
|
71,44,227
|
||||||
|
64,44,227
|
||||||
|
45,45,227
|
||||||
|
46,45,227
|
||||||
|
44,45,227
|
||||||
|
46,44,226
|
||||||
|
7,44,226
|
||||||
|
51,44,226
|
||||||
|
45,44,226
|
||||||
|
50,44,226
|
||||||
|
55,44,226
|
||||||
|
47,44,226
|
||||||
|
48,44,226
|
||||||
|
44,44,226
|
||||||
|
49,44,226
|
||||||
|
53,44,226
|
||||||
|
54,44,226
|
||||||
|
52,44,226
|
||||||
|
69,54,225
|
||||||
|
29,52,224
|
||||||
|
64,47,224
|
||||||
|
39,54,222
|
||||||
|
41,54,222
|
||||||
|
38,54,222
|
||||||
|
42,54,222
|
||||||
|
43,54,222
|
||||||
|
40,54,222
|
||||||
|
71,50,221
|
||||||
|
91,40,208
|
||||||
|
93,43,208
|
||||||
|
91,43,204
|
||||||
|
93,39,199
|
||||||
|
93,40,198
|
||||||
|
94,40,190
|
||||||
|
91,39,189
|
||||||
|
94,38,184
|
||||||
|
93,38,182
|
||||||
|
91,38,182
|
||||||
|
94,39,181
|
||||||
|
90,43,158
|
||||||
|
90,39,130
|
||||||
|
90,38,130
|
||||||
|
92,43,130
|
||||||
|
90,40,127
|
||||||
|
91,90,124
|
||||||
|
94,90,120
|
||||||
|
93,90,120
|
||||||
|
20,95,118
|
||||||
|
23,95,113
|
||||||
|
92,40,109
|
||||||
|
92,39,107
|
||||||
|
92,38,107
|
||||||
|
15,95,97
|
||||||
|
19,95,90
|
||||||
|
62,95,90
|
||||||
|
28,95,90
|
||||||
|
9,95,88
|
||||||
|
18,95,88
|
||||||
|
7,90,86
|
||||||
|
64,95,86
|
||||||
|
66,95,83
|
||||||
|
60,95,79
|
||||||
|
24,95,79
|
||||||
|
72,95,78
|
||||||
|
22,99,74
|
||||||
|
31,95,73
|
||||||
|
8,95,73
|
||||||
|
17,94,72
|
||||||
|
28,94,71
|
||||||
|
67,95,71
|
||||||
|
27,95,70
|
||||||
|
17,99,70
|
||||||
|
66,91,69
|
||||||
|
63,95,69
|
||||||
|
9,94,69
|
||||||
|
18,94,69
|
||||||
|
28,99,69
|
||||||
|
59,94,69
|
||||||
|
24,94,68
|
||||||
|
31,93,68
|
||||||
|
65,99,68
|
||||||
|
11,94,68
|
||||||
|
29,99,68
|
||||||
|
23,94,68
|
||||||
|
66,93,67
|
||||||
|
70,91,67
|
||||||
|
28,93,67
|
||||||
|
10,93,67
|
||||||
|
8,91,67
|
||||||
|
70,93,67
|
||||||
|
15,55,66
|
||||||
|
10,94,66
|
||||||
|
66,94,66
|
||||||
|
64,99,66
|
||||||
|
59,93,66
|
||||||
|
31,94,66
|
||||||
|
18,93,65
|
||||||
|
62,94,65
|
||||||
|
11,93,65
|
||||||
|
8,94,65
|
||||||
|
59,99,65
|
||||||
|
9,93,65
|
||||||
|
62,91,64
|
||||||
|
24,91,64
|
||||||
|
25,99,64
|
||||||
|
19,94,64
|
||||||
|
18,91,64
|
||||||
|
10,91,64
|
||||||
|
61,93,64
|
||||||
|
61,91,64
|
||||||
|
8,93,64
|
||||||
|
9,91,64
|
||||||
|
24,93,64
|
||||||
|
31,91,63
|
||||||
|
43,95,63
|
||||||
|
39,95,63
|
||||||
|
19,93,63
|
||||||
|
61,94,62
|
||||||
|
59,91,62
|
||||||
|
11,91,62
|
||||||
|
38,95,62
|
||||||
|
71,99,62
|
||||||
|
40,95,62
|
||||||
|
23,93,62
|
||||||
|
65,94,61
|
||||||
|
20,93,61
|
||||||
|
23,91,61
|
||||||
|
79,99,61
|
||||||
|
10,99,61
|
||||||
|
20,94,61
|
||||||
|
29,95,60
|
||||||
|
71,95,60
|
||||||
|
19,91,60
|
||||||
|
70,95,60
|
||||||
|
17,95,60
|
||||||
|
65,95,60
|
||||||
|
25,95,60
|
||||||
|
61,95,60
|
||||||
|
22,95,60
|
||||||
|
10,95,60
|
||||||
|
59,95,60
|
||||||
|
62,93,59
|
||||||
|
17,93,59
|
||||||
|
92,90,59
|
||||||
|
70,94,58
|
||||||
|
20,91,58
|
||||||
|
15,52,58
|
||||||
|
28,91,58
|
||||||
|
65,91,57
|
||||||
|
17,91,57
|
||||||
|
62,99,57
|
||||||
|
18,99,57
|
||||||
|
65,93,55
|
||||||
|
70,99,55
|
||||||
|
69,95,55
|
||||||
|
11,95,53
|
||||||
|
8,99,52
|
||||||
|
68,95,52
|
||||||
|
97,95,50
|
||||||
|
9,99,49
|
||||||
|
30,95,49
|
||||||
|
74,95,49
|
||||||
|
26,95,49
|
||||||
|
19,99,49
|
||||||
|
73,95,49
|
||||||
|
37,95,48
|
||||||
|
16,95,48
|
||||||
|
13,95,48
|
||||||
|
12,95,48
|
||||||
|
49,53,45
|
||||||
|
23,90,45
|
||||||
|
52,53,45
|
||||||
|
65,90,40
|
||||||
|
18,92,40
|
||||||
|
25,41,40
|
||||||
|
28,92,39
|
||||||
|
46,53,39
|
||||||
|
44,53,39
|
||||||
|
48,53,39
|
||||||
|
11,92,39
|
||||||
|
59,92,39
|
||||||
|
60,90,39
|
||||||
|
71,42,39
|
||||||
|
31,92,39
|
||||||
|
62,92,38
|
||||||
|
66,99,38
|
||||||
|
70,92,38
|
||||||
|
18,41,38
|
||||||
|
17,92,38
|
||||||
|
23,42,38
|
||||||
|
64,42,38
|
||||||
|
15,42,38
|
||||||
|
31,42,38
|
||||||
|
9,92,38
|
||||||
|
24,99,38
|
||||||
|
65,92,38
|
||||||
|
25,90,37
|
||||||
|
65,43,37
|
||||||
|
67,90,37
|
||||||
|
71,90,37
|
||||||
|
23,92,37
|
||||||
|
65,41,37
|
||||||
|
67,42,37
|
||||||
|
20,92,37
|
||||||
|
20,42,37
|
||||||
|
24,92,37
|
||||||
|
45,53,36
|
||||||
|
71,43,36
|
||||||
|
20,90,36
|
||||||
|
50,53,36
|
||||||
|
31,41,36
|
||||||
|
60,41,36
|
||||||
|
53,53,36
|
||||||
|
10,92,36
|
||||||
|
61,92,36
|
||||||
|
25,40,36
|
||||||
|
19,92,36
|
||||||
|
67,41,36
|
||||||
|
8,92,36
|
||||||
|
22,43,35
|
||||||
|
25,43,35
|
||||||
|
9,90,35
|
||||||
|
7,39,35
|
||||||
|
22,90,35
|
||||||
|
20,41,35
|
||||||
|
18,42,35
|
||||||
|
61,90,35
|
||||||
|
71,39,34
|
||||||
|
71,41,34
|
||||||
|
7,40,34
|
||||||
|
23,41,34
|
||||||
|
66,92,34
|
||||||
|
22,42,34
|
||||||
|
60,42,34
|
||||||
|
25,38,33
|
||||||
|
55,53,33
|
||||||
|
25,42,33
|
||||||
|
65,39,33
|
||||||
|
54,53,33
|
||||||
|
65,38,33
|
||||||
|
22,41,33
|
||||||
|
66,90,33
|
||||||
|
47,53,33
|
||||||
|
51,53,33
|
||||||
|
65,42,33
|
||||||
|
7,43,33
|
||||||
|
22,39,33
|
||||||
|
64,41,33
|
||||||
|
7,38,32
|
||||||
|
36,41,32
|
||||||
|
15,99,32
|
||||||
|
18,90,32
|
||||||
|
15,41,32
|
||||||
|
65,40,32
|
||||||
|
59,90,31
|
||||||
|
18,43,31
|
||||||
|
18,40,31
|
||||||
|
17,90,31
|
||||||
|
71,40,31
|
||||||
|
8,90,31
|
||||||
|
19,90,30
|
||||||
|
11,90,30
|
||||||
|
28,90,30
|
||||||
|
24,90,30
|
||||||
|
90,90,30
|
||||||
|
62,90,30
|
||||||
|
22,38,30
|
||||||
|
71,38,29
|
||||||
|
10,90,29
|
||||||
|
22,40,28
|
||||||
|
63,99,28
|
||||||
|
68,90,28
|
||||||
|
25,39,27
|
||||||
|
18,38,26
|
||||||
|
67,99,25
|
||||||
|
64,39,24
|
||||||
|
18,39,24
|
||||||
|
31,90,24
|
||||||
|
15,90,23
|
||||||
|
72,99,22
|
||||||
|
60,43,21
|
||||||
|
99,99,20
|
||||||
|
20,99,18
|
||||||
|
23,99,18
|
||||||
|
64,38,17
|
||||||
|
38,99,17
|
||||||
|
60,39,17
|
||||||
|
23,43,17
|
||||||
|
60,99,16
|
||||||
|
64,43,15
|
||||||
|
20,39,15
|
||||||
|
31,52,14
|
||||||
|
67,39,14
|
||||||
|
43,99,13
|
||||||
|
60,40,13
|
||||||
|
99,53,12
|
||||||
|
64,90,12
|
||||||
|
23,40,12
|
||||||
|
20,43,12
|
||||||
|
27,90,12
|
||||||
|
64,40,11
|
||||||
|
60,38,11
|
||||||
|
27,43,11
|
||||||
|
40,99,10
|
||||||
|
31,55,10
|
||||||
|
39,99,10
|
||||||
|
15,43,10
|
||||||
|
27,40,10
|
||||||
|
23,38,9
|
||||||
|
20,40,9
|
||||||
|
20,38,9
|
||||||
|
95,53,9
|
||||||
|
23,39,8
|
||||||
|
33,95,7
|
||||||
|
69,99,7
|
||||||
|
90,53,6
|
||||||
|
15,40,6
|
||||||
|
61,99,6
|
||||||
|
67,43,6
|
||||||
|
31,99,5
|
||||||
|
15,38,5
|
||||||
|
15,39,4
|
||||||
|
99,95,4
|
||||||
|
27,39,4
|
||||||
|
67,40,4
|
||||||
|
67,38,4
|
||||||
|
33,38,3
|
||||||
|
13,99,2
|
||||||
|
27,99,2
|
||||||
|
35,95,2
|
||||||
|
32,95,1
|
||||||
|
11,99,1
|
||||||
|
32,43,1
|
||||||
|
68,99,1
|
||||||
|
34,95,1
|
||||||
|
73,99,1
|
||||||
|
|||||||
|
BIN
output_result/risk/count_dcp_prod_network.png
Normal file
|
After Width: | Height: | Size: 2.6 MiB |
@@ -1,46 +1,175 @@
|
|||||||
id_firm,count
|
id_firm,count
|
||||||
126,6
|
653528340,4007
|
||||||
85,5
|
2348941764,3957
|
||||||
100,3
|
3215814536,3831
|
||||||
80,3
|
888395016,3750
|
||||||
79,3
|
2354145351,3619
|
||||||
99,3
|
3147511625,3346
|
||||||
57,2
|
3048263744,3326
|
||||||
74,2
|
2317245827,3230
|
||||||
13,2
|
631449822,3149
|
||||||
97,2
|
3103797386,3123
|
||||||
94,2
|
194210021,3077
|
||||||
93,2
|
2327031723,3004
|
||||||
108,2
|
301209792,2997
|
||||||
45,2
|
191912252,2804
|
||||||
68,2
|
70634828,2464
|
||||||
53,2
|
2321109759,1165
|
||||||
106,2
|
3299144127,1130
|
||||||
73,2
|
3445928818,1120
|
||||||
75,2
|
2312490120,1077
|
||||||
58,1
|
503176785,1003
|
||||||
124,1
|
930767828,467
|
||||||
77,1
|
3407754893,451
|
||||||
117,1
|
2944892892,355
|
||||||
81,1
|
3269039233,354
|
||||||
84,1
|
750610681,353
|
||||||
98,1
|
25685135,351
|
||||||
115,1
|
343012684,342
|
||||||
49,1
|
3069206426,339
|
||||||
50,1
|
448033045,329
|
||||||
159,1
|
2624175,328
|
||||||
131,1
|
2320475044,321
|
||||||
135,1
|
413274977,314
|
||||||
14,1
|
3111033905,310
|
||||||
142,1
|
2317841563,310
|
||||||
148,1
|
43407343,304
|
||||||
149,1
|
571058167,302
|
||||||
21,1
|
607512171,286
|
||||||
119,1
|
152008168,272
|
||||||
22,1
|
888356483,250
|
||||||
23,1
|
25945288,222
|
||||||
25,1
|
1452048,20
|
||||||
26,1
|
2311838590,20
|
||||||
31,1
|
3373311444,20
|
||||||
41,1
|
11807506,20
|
||||||
36,1
|
2424229017,18
|
||||||
|
4208851809,10
|
||||||
|
3271705843,10
|
||||||
|
3269940677,10
|
||||||
|
420984285,10
|
||||||
|
400488703,10
|
||||||
|
400692942,10
|
||||||
|
354897041,10
|
||||||
|
3462551351,10
|
||||||
|
3288105727,10
|
||||||
|
3312358902,10
|
||||||
|
3344297292,10
|
||||||
|
3372913783,10
|
||||||
|
3384021594,10
|
||||||
|
3445244192,10
|
||||||
|
3433628561,10
|
||||||
|
3395900897,10
|
||||||
|
453289520,10
|
||||||
|
1033972427,10
|
||||||
|
581407487,10
|
||||||
|
474279224,10
|
||||||
|
857978527,10
|
||||||
|
7299120,10
|
||||||
|
737770776,10
|
||||||
|
762985858,10
|
||||||
|
771821595,10
|
||||||
|
80158773,10
|
||||||
|
829768,10
|
||||||
|
863079,10
|
||||||
|
495782506,10
|
||||||
|
868012326,10
|
||||||
|
872394725,10
|
||||||
|
887840774,10
|
||||||
|
888478182,10
|
||||||
|
9,10
|
||||||
|
9746245,10
|
||||||
|
71271700,10
|
||||||
|
7,10
|
||||||
|
695995052,10
|
||||||
|
688155470,10
|
||||||
|
654825436,10
|
||||||
|
644292599,10
|
||||||
|
620220747,10
|
||||||
|
615763365,10
|
||||||
|
594378026,10
|
||||||
|
593312758,10
|
||||||
|
591452402,10
|
||||||
|
5849940,10
|
||||||
|
3226664625,10
|
||||||
|
561545339,10
|
||||||
|
560866402,10
|
||||||
|
549184982,10
|
||||||
|
5278074,10
|
||||||
|
3267688490,10
|
||||||
|
996174506,10
|
||||||
|
3221190269,10
|
||||||
|
2311581270,10
|
||||||
|
2316990095,10
|
||||||
|
2320102626,10
|
||||||
|
2324787028,10
|
||||||
|
2324844174,10
|
||||||
|
2326478786,10
|
||||||
|
2327979389,10
|
||||||
|
2329375731,10
|
||||||
|
2333843479,10
|
||||||
|
2337952436,10
|
||||||
|
2339684065,10
|
||||||
|
2341555098,10
|
||||||
|
2343704209,10
|
||||||
|
2347013470,10
|
||||||
|
2350418059,10
|
||||||
|
2352036411,10
|
||||||
|
2313209417,10
|
||||||
|
2310825263,10
|
||||||
|
3211956484,10
|
||||||
|
218633337,10
|
||||||
|
1128343125,10
|
||||||
|
118882692,10
|
||||||
|
1217957486,10
|
||||||
|
1307012237,10
|
||||||
|
1375606900,10
|
||||||
|
145511905,10
|
||||||
|
151606446,10
|
||||||
|
1549474227,10
|
||||||
|
15613202,10
|
||||||
|
159511306,10
|
||||||
|
1606833003,10
|
||||||
|
1679596339,10
|
||||||
|
2010673,10
|
||||||
|
203314437,10
|
||||||
|
213386023,10
|
||||||
|
24284343,10
|
||||||
|
24673506,10
|
||||||
|
25036634,10
|
||||||
|
3120341363,10
|
||||||
|
3047163873,10
|
||||||
|
3070859372,10
|
||||||
|
3072715478,10
|
||||||
|
3089095447,10
|
||||||
|
3100891962,10
|
||||||
|
3113895788,10
|
||||||
|
3122923980,10
|
||||||
|
251189644,10
|
||||||
|
11164476478,10
|
||||||
|
3133307899,10
|
||||||
|
3177507356,10
|
||||||
|
3188352290,10
|
||||||
|
3188903709,10
|
||||||
|
3195502499,10
|
||||||
|
3045721313,10
|
||||||
|
3031009366,10
|
||||||
|
3026382513,10
|
||||||
|
271860868,10
|
||||||
|
2545430247,10
|
||||||
|
26162741,10
|
||||||
|
26516263,10
|
||||||
|
3025036704,10
|
||||||
|
27075840,10
|
||||||
|
2728939,10
|
||||||
|
27731896,10
|
||||||
|
278221281,10
|
||||||
|
2820140348,10
|
||||||
|
29954548,10
|
||||||
|
3398677646,9
|
||||||
|
3127420424,9
|
||||||
|
5007015990,8
|
||||||
|
3203777710,8
|
||||||
|
2339188563,7
|
||||||
|
483081978,6
|
||||||
|
517717050,6
|
||||||
|
|||||||
|
@@ -1,58 +1,370 @@
|
|||||||
id_firm,id_product,count
|
id_firm,id_product,count
|
||||||
126,2.1.3,4
|
2321109759,95,1155
|
||||||
100,1.3.1,3
|
3299144127,95,1138
|
||||||
85,1.3.1,3
|
3445928818,95,1123
|
||||||
106,2.1.3,2
|
930767828,90,468
|
||||||
68,1.3.1.3,2
|
3407754893,90,443
|
||||||
73,2.1.3,2
|
653528340,55,434
|
||||||
74,2.1.3,2
|
653528340,52,430
|
||||||
75,1.3.3,2
|
2348941764,55,427
|
||||||
85,2.1.1,2
|
2348941764,52,425
|
||||||
80,1.3.4,2
|
2354145351,52,421
|
||||||
93,1.3.1,2
|
3215814536,52,421
|
||||||
94,1.1,2
|
888395016,55,420
|
||||||
108,2.1.3,2
|
2354145351,55,419
|
||||||
99,1.3.1,2
|
888395016,52,411
|
||||||
53,1.4.5.6,1
|
3215814536,55,409
|
||||||
57,1.3.3.3,1
|
653528340,54,397
|
||||||
57,2.3.1,1
|
653528340,53,396
|
||||||
58,1.3.4.3,1
|
653528340,50,395
|
||||||
98,2,1
|
653528340,51,395
|
||||||
97,2.1.3,1
|
750610681,92,389
|
||||||
97,1.3.3,1
|
343012684,92,379
|
||||||
77,1.3.4,1
|
2348941764,51,379
|
||||||
79,2.1.3.2,1
|
3048263744,55,379
|
||||||
79,2.1.3.7,1
|
2354145351,53,377
|
||||||
79,2.1.4.1,1
|
3147511625,52,374
|
||||||
50,1.3.1.5,1
|
2354145351,51,372
|
||||||
80,2.1.1,1
|
888395016,50,371
|
||||||
81,1.3.4,1
|
888395016,53,371
|
||||||
84,2.3,1
|
3048263744,52,370
|
||||||
53,1.4.3.4,1
|
888395016,51,369
|
||||||
45,2.1.4.1.1,1
|
2348941764,53,369
|
||||||
49,1.3.1.4,1
|
2348941764,54,367
|
||||||
45,1.3.4.2,1
|
3147511625,55,367
|
||||||
115,1.1.3,1
|
2354145351,54,365
|
||||||
117,2.1.1.4,1
|
448033045,94,364
|
||||||
119,1.3.1.1,1
|
2354145351,50,364
|
||||||
124,2.3,1
|
2348941764,50,361
|
||||||
126,1.1,1
|
3269039233,99,361
|
||||||
126,2.1.1.5,1
|
888395016,54,358
|
||||||
13,2.1.3.4,1
|
3215814536,51,355
|
||||||
13,2.1.3.7,1
|
2944892892,99,354
|
||||||
131,2.1.1.5,1
|
2317245827,55,353
|
||||||
135,2.2,1
|
25685135,99,351
|
||||||
14,1.3.3.4,1
|
2317245827,52,350
|
||||||
142,1.4.3,1
|
3215814536,54,349
|
||||||
148,2.1.3,1
|
631449822,55,349
|
||||||
149,2.1.2.2,1
|
3069206426,93,348
|
||||||
159,2.1.2,1
|
3215814536,50,347
|
||||||
21,1.3.1.3,1
|
194210021,52,346
|
||||||
22,2.1.3.7,1
|
631449822,52,345
|
||||||
23,2.3.1,1
|
3215814536,53,344
|
||||||
25,1.3.1.7,1
|
3111033905,93,343
|
||||||
26,2.1.3.4,1
|
2327031723,52,341
|
||||||
31,1.3.3.3,1
|
191912252,55,341
|
||||||
36,1.1.1,1
|
70634828,52,340
|
||||||
41,1.4.5,1
|
3103797386,55,339
|
||||||
99,1.3.3,1
|
194210021,55,336
|
||||||
|
301209792,52,335
|
||||||
|
301209792,55,333
|
||||||
|
3103797386,52,332
|
||||||
|
191912252,52,330
|
||||||
|
2320475044,94,327
|
||||||
|
3147511625,53,322
|
||||||
|
3048263744,53,319
|
||||||
|
2327031723,55,318
|
||||||
|
2624175,99,318
|
||||||
|
3147511625,51,316
|
||||||
|
3048263744,51,312
|
||||||
|
3147511625,54,310
|
||||||
|
2317245827,50,308
|
||||||
|
3147511625,50,307
|
||||||
|
3048263744,50,307
|
||||||
|
571058167,94,306
|
||||||
|
2317245827,53,303
|
||||||
|
2317841563,91,303
|
||||||
|
3048263744,54,302
|
||||||
|
2317245827,54,298
|
||||||
|
631449822,51,297
|
||||||
|
194210021,53,297
|
||||||
|
413274977,91,295
|
||||||
|
3103797386,50,291
|
||||||
|
2317245827,51,291
|
||||||
|
3103797386,51,290
|
||||||
|
43407343,93,289
|
||||||
|
70634828,55,289
|
||||||
|
607512171,91,288
|
||||||
|
194210021,51,288
|
||||||
|
3103797386,53,287
|
||||||
|
194210021,50,287
|
||||||
|
194210021,54,286
|
||||||
|
631449822,53,285
|
||||||
|
653528340,48,285
|
||||||
|
152008168,94,283
|
||||||
|
653528340,49,283
|
||||||
|
653528340,46,282
|
||||||
|
631449822,50,281
|
||||||
|
3103797386,54,281
|
||||||
|
653528340,45,278
|
||||||
|
2327031723,53,277
|
||||||
|
653528340,44,276
|
||||||
|
653528340,47,276
|
||||||
|
2327031723,50,275
|
||||||
|
631449822,54,273
|
||||||
|
191912252,54,272
|
||||||
|
2327031723,51,270
|
||||||
|
301209792,54,266
|
||||||
|
2312490120,41,266
|
||||||
|
888395016,45,266
|
||||||
|
2348941764,49,266
|
||||||
|
191912252,51,264
|
||||||
|
301209792,53,263
|
||||||
|
2348941764,48,262
|
||||||
|
2348941764,46,262
|
||||||
|
2348941764,45,261
|
||||||
|
301209792,51,261
|
||||||
|
301209792,50,260
|
||||||
|
2327031723,54,259
|
||||||
|
888395016,49,259
|
||||||
|
2348941764,47,257
|
||||||
|
191912252,50,256
|
||||||
|
888395016,48,256
|
||||||
|
2348941764,44,253
|
||||||
|
888395016,46,253
|
||||||
|
2354145351,46,252
|
||||||
|
70634828,51,252
|
||||||
|
888395016,47,251
|
||||||
|
2312490120,42,250
|
||||||
|
191912252,53,248
|
||||||
|
888395016,44,248
|
||||||
|
2354145351,47,247
|
||||||
|
2354145351,49,246
|
||||||
|
2354145351,48,245
|
||||||
|
3215814536,49,241
|
||||||
|
70634828,54,239
|
||||||
|
3215814536,48,238
|
||||||
|
888356483,91,236
|
||||||
|
3215814536,46,236
|
||||||
|
70634828,50,232
|
||||||
|
3215814536,47,232
|
||||||
|
2354145351,45,231
|
||||||
|
2354145351,44,231
|
||||||
|
3215814536,44,230
|
||||||
|
3215814536,45,230
|
||||||
|
3048263744,48,230
|
||||||
|
70634828,53,229
|
||||||
|
3048263744,47,227
|
||||||
|
3048263744,46,221
|
||||||
|
3048263744,45,220
|
||||||
|
3048263744,44,217
|
||||||
|
194210021,46,217
|
||||||
|
2317245827,44,217
|
||||||
|
3048263744,49,216
|
||||||
|
3147511625,48,212
|
||||||
|
3147511625,49,212
|
||||||
|
3147511625,45,210
|
||||||
|
3147511625,44,210
|
||||||
|
2317245827,46,209
|
||||||
|
503176785,42,208
|
||||||
|
503176785,41,208
|
||||||
|
3147511625,47,206
|
||||||
|
194210021,48,206
|
||||||
|
3103797386,44,205
|
||||||
|
2317245827,47,204
|
||||||
|
194210021,44,203
|
||||||
|
2317245827,49,203
|
||||||
|
3147511625,46,202
|
||||||
|
2317245827,45,201
|
||||||
|
194210021,45,200
|
||||||
|
3103797386,49,200
|
||||||
|
631449822,45,199
|
||||||
|
194210021,49,197
|
||||||
|
191912252,49,196
|
||||||
|
3103797386,46,196
|
||||||
|
2317245827,48,196
|
||||||
|
2327031723,49,195
|
||||||
|
194210021,47,194
|
||||||
|
25945288,93,194
|
||||||
|
631449822,49,193
|
||||||
|
2327031723,48,192
|
||||||
|
301209792,46,192
|
||||||
|
70634828,49,191
|
||||||
|
191912252,46,190
|
||||||
|
191912252,44,190
|
||||||
|
2327031723,45,190
|
||||||
|
3103797386,47,190
|
||||||
|
631449822,48,189
|
||||||
|
3103797386,48,189
|
||||||
|
301209792,44,188
|
||||||
|
631449822,47,185
|
||||||
|
301209792,45,185
|
||||||
|
191912252,48,183
|
||||||
|
191912252,45,183
|
||||||
|
631449822,44,183
|
||||||
|
2327031723,46,182
|
||||||
|
503176785,43,182
|
||||||
|
3103797386,45,181
|
||||||
|
70634828,46,180
|
||||||
|
631449822,46,180
|
||||||
|
2327031723,44,180
|
||||||
|
301209792,48,177
|
||||||
|
2327031723,47,176
|
||||||
|
191912252,47,174
|
||||||
|
301209792,49,174
|
||||||
|
301209792,47,173
|
||||||
|
70634828,48,173
|
||||||
|
70634828,47,172
|
||||||
|
70634828,44,165
|
||||||
|
70634828,45,160
|
||||||
|
2312490120,40,140
|
||||||
|
2312490120,39,139
|
||||||
|
2312490120,38,135
|
||||||
|
503176785,39,128
|
||||||
|
503176785,38,122
|
||||||
|
2312490120,43,119
|
||||||
|
503176785,40,110
|
||||||
|
3133307899,23,20
|
||||||
|
3395900897,73,18
|
||||||
|
3221190269,20,17
|
||||||
|
3384021594,64,15
|
||||||
|
2820140348,62,15
|
||||||
|
1375606900,67,15
|
||||||
|
3445244192,24,15
|
||||||
|
887840774,8,15
|
||||||
|
3312358902,59,14
|
||||||
|
26516263,8,14
|
||||||
|
24284343,35,14
|
||||||
|
251189644,23,14
|
||||||
|
7,10,14
|
||||||
|
26162741,11,14
|
||||||
|
400692942,68,13
|
||||||
|
354897041,72,13
|
||||||
|
996174506,15,13
|
||||||
|
3211956484,34,13
|
||||||
|
203314437,22,13
|
||||||
|
11807506,23,13
|
||||||
|
1307012237,68,13
|
||||||
|
194210021,7,13
|
||||||
|
2010673,64,13
|
||||||
|
3373311444,20,13
|
||||||
|
688155470,30,13
|
||||||
|
2347013470,61,13
|
||||||
|
271860868,12,13
|
||||||
|
71271700,27,12
|
||||||
|
863079,11,12
|
||||||
|
420984285,16,12
|
||||||
|
644292599,11,12
|
||||||
|
9,37,12
|
||||||
|
5849940,26,12
|
||||||
|
9746245,97,12
|
||||||
|
868012326,29,12
|
||||||
|
1033972427,61,12
|
||||||
|
3373311444,71,12
|
||||||
|
3120341363,79,12
|
||||||
|
1128343125,63,12
|
||||||
|
1217957486,31,12
|
||||||
|
1452048,63,12
|
||||||
|
191912252,7,12
|
||||||
|
2311838590,97,12
|
||||||
|
2327979389,13,12
|
||||||
|
2341555098,11,12
|
||||||
|
2354145351,7,12
|
||||||
|
2728939,63,12
|
||||||
|
25036634,31,12
|
||||||
|
3271705843,62,12
|
||||||
|
3344297292,12,12
|
||||||
|
2350418059,79,11
|
||||||
|
15613202,32,11
|
||||||
|
2352036411,17,11
|
||||||
|
653528340,7,11
|
||||||
|
3269940677,28,11
|
||||||
|
278221281,66,11
|
||||||
|
2324844174,67,11
|
||||||
|
2317245827,7,11
|
||||||
|
3045721313,25,11
|
||||||
|
3070859372,62,11
|
||||||
|
771821595,10,11
|
||||||
|
615763365,68,11
|
||||||
|
1679596339,74,11
|
||||||
|
561545339,33,11
|
||||||
|
2311581270,19,11
|
||||||
|
888478182,9,11
|
||||||
|
3398677646,79,11
|
||||||
|
888395016,7,11
|
||||||
|
3195502499,18,11
|
||||||
|
1549474227,67,11
|
||||||
|
474279224,71,11
|
||||||
|
453289520,37,10
|
||||||
|
2313209417,32,10
|
||||||
|
11807506,60,10
|
||||||
|
2324787028,18,10
|
||||||
|
5278074,36,10
|
||||||
|
2327031723,7,10
|
||||||
|
3188903709,65,10
|
||||||
|
3372913783,20,10
|
||||||
|
695995052,8,10
|
||||||
|
2343704209,69,10
|
||||||
|
400488703,28,10
|
||||||
|
118882692,35,10
|
||||||
|
3047163873,27,10
|
||||||
|
3127420424,32,10
|
||||||
|
151606446,61,10
|
||||||
|
3122923980,34,10
|
||||||
|
593312758,31,10
|
||||||
|
80158773,69,10
|
||||||
|
145511905,68,10
|
||||||
|
4208851809,16,10
|
||||||
|
2311838590,34,9
|
||||||
|
2348941764,7,9
|
||||||
|
2326478786,60,9
|
||||||
|
872394725,70,9
|
||||||
|
737770776,34,9
|
||||||
|
218633337,33,9
|
||||||
|
2333843479,70,9
|
||||||
|
213386023,19,9
|
||||||
|
2337952436,24,9
|
||||||
|
1606833003,9,9
|
||||||
|
159511306,69,9
|
||||||
|
3072715478,33,9
|
||||||
|
3267688490,73,9
|
||||||
|
3026382513,15,9
|
||||||
|
3203777710,74,9
|
||||||
|
5007015990,74,9
|
||||||
|
3188352290,64,9
|
||||||
|
3177507356,24,9
|
||||||
|
620220747,15,9
|
||||||
|
3031009366,59,9
|
||||||
|
631449822,7,9
|
||||||
|
581407487,72,8
|
||||||
|
591452402,66,8
|
||||||
|
594378026,27,8
|
||||||
|
3100891962,26,8
|
||||||
|
3215814536,7,8
|
||||||
|
24673506,67,8
|
||||||
|
2339188563,37,8
|
||||||
|
29954548,27,8
|
||||||
|
2339684065,74,8
|
||||||
|
3462551351,13,8
|
||||||
|
560866402,9,7
|
||||||
|
3103797386,7,7
|
||||||
|
2320102626,18,7
|
||||||
|
3288105727,36,7
|
||||||
|
829768,23,7
|
||||||
|
2424229017,30,7
|
||||||
|
11164476478,60,7
|
||||||
|
762985858,72,7
|
||||||
|
7299120,32,7
|
||||||
|
70634828,7,7
|
||||||
|
2316990095,66,7
|
||||||
|
3025036704,17,7
|
||||||
|
3113895788,35,7
|
||||||
|
654825436,61,6
|
||||||
|
1452048,30,6
|
||||||
|
3147511625,7,6
|
||||||
|
3226664625,28,6
|
||||||
|
549184982,69,6
|
||||||
|
301209792,7,6
|
||||||
|
2545430247,25,6
|
||||||
|
2329375731,31,6
|
||||||
|
27075840,65,6
|
||||||
|
857978527,60,6
|
||||||
|
2424229017,26,6
|
||||||
|
3048263744,7,6
|
||||||
|
3433628561,29,5
|
||||||
|
517717050,36,5
|
||||||
|
495782506,19,5
|
||||||
|
483081978,36,5
|
||||||
|
27731896,20,5
|
||||||
|
3089095447,22,5
|
||||||
|
2310825263,15,4
|
||||||
|
|||||||
|
@@ -1,35 +1,73 @@
|
|||||||
id_product,count
|
id_product,count
|
||||||
2.1.3,14
|
52,5571
|
||||||
1.3.1,10
|
55,5513
|
||||||
1.3.4,4
|
51,4711
|
||||||
1.3.3,4
|
53,4687
|
||||||
1.1,3
|
50,4642
|
||||||
2.1.3.7,3
|
54,4622
|
||||||
1.3.1.3,3
|
95,3416
|
||||||
2.1.1,3
|
49,3272
|
||||||
2.3,2
|
46,3254
|
||||||
2.1.3.4,2
|
48,3233
|
||||||
2.1.1.5,2
|
44,3196
|
||||||
2.3.1,2
|
45,3195
|
||||||
1.3.3.3,2
|
47,3164
|
||||||
1.3.3.4,1
|
99,1384
|
||||||
2.1.2.2,1
|
94,1280
|
||||||
1.1.3,1
|
93,1174
|
||||||
2.2,1
|
91,1122
|
||||||
2.1.4.1.1,1
|
90,911
|
||||||
2.1.4.1,1
|
92,768
|
||||||
1.3.1.1,1
|
41,474
|
||||||
1.3.1.4,1
|
42,458
|
||||||
2.1.3.2,1
|
43,301
|
||||||
1.3.1.5,1
|
39,267
|
||||||
2.1.2,1
|
38,257
|
||||||
1.3.4.2,1
|
40,250
|
||||||
1.3.1.7,1
|
7,138
|
||||||
2.1.1.4,1
|
23,54
|
||||||
2,1
|
11,50
|
||||||
1.4.5.6,1
|
68,47
|
||||||
1.1.1,1
|
20,45
|
||||||
1.4.3.4,1
|
67,45
|
||||||
1.4.3,1
|
34,41
|
||||||
1.3.4.3,1
|
61,41
|
||||||
1.4.5,1
|
31,40
|
||||||
|
8,39
|
||||||
|
62,38
|
||||||
|
32,38
|
||||||
|
27,38
|
||||||
|
74,37
|
||||||
|
64,37
|
||||||
|
63,36
|
||||||
|
15,35
|
||||||
|
69,35
|
||||||
|
79,34
|
||||||
|
24,33
|
||||||
|
60,32
|
||||||
|
35,31
|
||||||
|
37,30
|
||||||
|
33,29
|
||||||
|
72,28
|
||||||
|
18,28
|
||||||
|
9,27
|
||||||
|
73,27
|
||||||
|
36,27
|
||||||
|
28,27
|
||||||
|
66,26
|
||||||
|
30,26
|
||||||
|
26,26
|
||||||
|
12,25
|
||||||
|
10,25
|
||||||
|
19,25
|
||||||
|
97,24
|
||||||
|
71,23
|
||||||
|
59,23
|
||||||
|
16,22
|
||||||
|
13,20
|
||||||
|
70,18
|
||||||
|
17,18
|
||||||
|
22,18
|
||||||
|
25,17
|
||||||
|
29,17
|
||||||
|
65,16
|
||||||
|
|||||||
|
|
Before Width: | Height: | Size: 1.1 MiB After Width: | Height: | Size: 5.7 MiB |
|
Before Width: | Height: | Size: 1.1 MiB After Width: | Height: | Size: 5.9 MiB |
|
Before Width: | Height: | Size: 3.1 MiB After Width: | Height: | Size: 13 MiB |
@@ -2,13 +2,14 @@ from mesa import Agent
|
|||||||
|
|
||||||
|
|
||||||
class ProductAgent(Agent):
|
class ProductAgent(Agent):
|
||||||
def __init__(self, unique_id, model, name, type2):
|
def __init__(self, unique_id, model, name, type2, production_ratio):
|
||||||
# 调用超类的 __init__ 方法
|
# 调用超类的 __init__ 方法
|
||||||
super().__init__(unique_id, model)
|
super().__init__(unique_id, model)
|
||||||
|
|
||||||
# 初始化代理属性
|
# 初始化代理属性
|
||||||
self.name = name
|
self.name = name
|
||||||
self.product_network = self.model.product_network
|
self.product_network = self.model.product_network
|
||||||
|
self.production_ratio = production_ratio
|
||||||
if type2 == 0:
|
if type2 == 0:
|
||||||
self.is_equip = True
|
self.is_equip = True
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
agentpy==0.1.5
|
agentpy==0.1.5
|
||||||
matplotlib==3.3.4
|
matplotlib==3.7.5
|
||||||
matplotlib-inline==0.1.6
|
matplotlib-inline==0.1.6
|
||||||
networkx==2.5
|
networkx==2.5
|
||||||
numpy==1.20.3
|
numpy==1.20.3
|
||||||
|
|||||||
@@ -13,8 +13,7 @@ count_dcp = pd.read_csv("output_result/risk/count_dcp.csv",
|
|||||||
'up_id_firm': str,
|
'up_id_firm': str,
|
||||||
'down_id_firm': str
|
'down_id_firm': str
|
||||||
})
|
})
|
||||||
# print(count_dcp)
|
count_dcp = count_dcp[count_dcp['count'] > 130]
|
||||||
count_dcp = count_dcp[count_dcp['count'] > 35]
|
|
||||||
|
|
||||||
list_firm = count_dcp['up_id_firm'].tolist(
|
list_firm = count_dcp['up_id_firm'].tolist(
|
||||||
) + count_dcp['down_id_firm'].tolist()
|
) + count_dcp['down_id_firm'].tolist()
|
||||||
@@ -24,7 +23,7 @@ list_firm = list(set(list_firm))
|
|||||||
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('string')
|
Firm['Code'] = Firm['Code'].astype('string')
|
||||||
Firm.fillna(0, inplace=True)
|
Firm.fillna(0, inplace=True)
|
||||||
Firm_attr = Firm.loc[:, ["Code", "Type_Region", "Revenue_Log"]]
|
Firm_attr = Firm.loc[:, ["Code", "企业名称", "Type_Region", "Revenue_Log"]]
|
||||||
firm_industry_relation = pd.read_csv("input_data/firm_industry_relation.csv")
|
firm_industry_relation = pd.read_csv("input_data/firm_industry_relation.csv")
|
||||||
firm_industry_relation['Firm_Code'] = firm_industry_relation['Firm_Code'].astype('string')
|
firm_industry_relation['Firm_Code'] = firm_industry_relation['Firm_Code'].astype('string')
|
||||||
firm_product = []
|
firm_product = []
|
||||||
@@ -43,7 +42,7 @@ nx.set_node_attributes(G_firm, firm_labels_dict)
|
|||||||
|
|
||||||
count_max = count_dcp['count'].max()
|
count_max = count_dcp['count'].max()
|
||||||
count_min = count_dcp['count'].min()
|
count_min = count_dcp['count'].min()
|
||||||
k = 5 / (count_max - count_min)
|
k = 15 / (count_max - count_min)
|
||||||
for _, row in count_dcp.iterrows():
|
for _, row in count_dcp.iterrows():
|
||||||
# print(row)
|
# print(row)
|
||||||
lst_add_edge = [(
|
lst_add_edge = [(
|
||||||
@@ -54,20 +53,43 @@ for _, row in count_dcp.iterrows():
|
|||||||
'down_id_product': row['down_id_product'],
|
'down_id_product': row['down_id_product'],
|
||||||
'edge_label': f"{row['up_id_product']} - {row['down_id_product']}",
|
'edge_label': f"{row['up_id_product']} - {row['down_id_product']}",
|
||||||
'edge_width': k * (row['count'] - count_min),
|
'edge_width': k * (row['count'] - count_min),
|
||||||
'count': row['count']
|
'count': (row['count'])*18
|
||||||
})]
|
})]
|
||||||
G_firm.add_edges_from(lst_add_edge)
|
G_firm.add_edges_from(lst_add_edge)
|
||||||
|
|
||||||
# dcp_networkx
|
# dcp_networkx
|
||||||
pos = nx.nx_agraph.graphviz_layout(G_firm, prog="dot", args="")
|
pos = nx.nx_agraph.graphviz_layout(G_firm, prog="twopi", args="")
|
||||||
node_label = nx.get_node_attributes(G_firm, 'Revenue_Log')
|
node_label = nx.get_node_attributes(G_firm, '企业名称')
|
||||||
# desensitize
|
# desensitize
|
||||||
|
node_label = {key: f"{key} " for key, value in node_label.items()}
|
||||||
node_label = {
|
node_label = {
|
||||||
key: key
|
'343012684': '59',
|
||||||
for key in node_label.keys()
|
'2944892892': '165',
|
||||||
|
'3269039233': '194',
|
||||||
|
'503176785': '73',
|
||||||
|
'3111033905': '178',
|
||||||
|
'3215814536': '190',
|
||||||
|
'413274977': '64',
|
||||||
|
'2317841563': '131',
|
||||||
|
'2354145351': '157',
|
||||||
|
'653528340': '88',
|
||||||
|
'888395016': '104',
|
||||||
|
'3069206426': '174',
|
||||||
|
'3299144127': '197',
|
||||||
|
'2624175': '8',
|
||||||
|
'25685135': '24',
|
||||||
|
'2348941764': '151',
|
||||||
|
'750610681': '95',
|
||||||
|
'2320475044': '133',
|
||||||
|
'571058167': '78',
|
||||||
|
'152008168': '44',
|
||||||
|
'448033045': '66',
|
||||||
|
'2321109759': '134',
|
||||||
|
'3445928818': '213'
|
||||||
}
|
}
|
||||||
|
|
||||||
node_size = list(nx.get_node_attributes(G_firm, 'Revenue_Log').values())
|
node_size = list(nx.get_node_attributes(G_firm, 'Revenue_Log').values())
|
||||||
node_size = list(map(lambda x: x**2, node_size))
|
node_size = list(map(lambda x: x * 10, node_size))
|
||||||
edge_label = nx.get_edge_attributes(G_firm, "edge_label")
|
edge_label = nx.get_edge_attributes(G_firm, "edge_label")
|
||||||
edge_label = {(n1, n2): label for (n1, n2, _), label in edge_label.items()}
|
edge_label = {(n1, n2): label for (n1, n2, _), label in edge_label.items()}
|
||||||
edge_width = nx.get_edge_attributes(G_firm, "edge_width")
|
edge_width = nx.get_edge_attributes(G_firm, "edge_width")
|
||||||
@@ -77,23 +99,30 @@ colors = [w for (n1, n2, _), w in colors.items()]
|
|||||||
vmin = min(colors)
|
vmin = min(colors)
|
||||||
vmax = max(colors)
|
vmax = max(colors)
|
||||||
cmap = plt.cm.Blues
|
cmap = plt.cm.Blues
|
||||||
fig = plt.figure(figsize=(10, 8), dpi=300)
|
fig = plt.figure(figsize=(10, 8), dpi=500)
|
||||||
nx.draw(G_firm,
|
nx.draw(G_firm,
|
||||||
pos,
|
pos,
|
||||||
node_size=node_size,
|
node_size=node_size,
|
||||||
labels=node_label,
|
labels=node_label,
|
||||||
font_size=8,
|
font_size=8,
|
||||||
width=3,
|
width=2,
|
||||||
edge_color=colors,
|
edge_color=colors,
|
||||||
edge_cmap=cmap,
|
edge_cmap=cmap,
|
||||||
edge_vmin=vmin,
|
edge_vmin=vmin,
|
||||||
edge_vmax=vmax)
|
edge_vmax=vmax)
|
||||||
nx.draw_networkx_edge_labels(G_firm, pos, edge_label, font_size=6)
|
# nx.draw_networkx_edge_labels(G_firm, pos, font_size=6)
|
||||||
|
nx.draw_networkx_edge_labels(
|
||||||
|
G_firm,
|
||||||
|
pos,
|
||||||
|
edge_labels=edge_label,
|
||||||
|
font_size=5
|
||||||
|
)
|
||||||
|
|
||||||
sm = plt.cm.ScalarMappable(cmap=cmap, norm=plt.Normalize(vmin=vmin, vmax=vmax))
|
sm = plt.cm.ScalarMappable(cmap=cmap, norm=plt.Normalize(vmin=vmin, vmax=vmax))
|
||||||
sm._A = []
|
sm._A = []
|
||||||
position = fig.add_axes([0.95, 0.05, 0.01, 0.3])
|
position = fig.add_axes([0.95, 0.05, 0.01, 0.3])
|
||||||
cb = plt.colorbar(sm, fraction=0.01, cax=position)
|
cb = plt.colorbar(sm, fraction=0.01, cax=position)
|
||||||
cb.ax.tick_params(labelsize=10)
|
cb.ax.tick_params(labelsize=4)
|
||||||
cb.outline.set_visible(False)
|
cb.outline.set_visible(False)
|
||||||
plt.savefig("output_result\\risk\\count_dcp_network")
|
plt.savefig("output_result\\risk\\count_dcp_network")
|
||||||
plt.close()
|
plt.close()
|
||||||
|
|||||||
@@ -11,53 +11,82 @@ print(count_prod)
|
|||||||
print(count_prod.describe())
|
print(count_prod.describe())
|
||||||
|
|
||||||
# prod_networkx
|
# prod_networkx
|
||||||
BomNodes = pd.read_csv('input_data/input_product_data/BomNodes.csv', index_col=0)
|
# BomNodes = pd.read_csv('input_data/input_product_data/BomNodes.csv', index_col=0)
|
||||||
BomNodes.set_index('Code', inplace=True)
|
# BomNodes.set_index('Code', inplace=True)
|
||||||
BomCateNet = pd.read_csv('input_data/input_product_data/BomCateNet.csv', index_col=0)
|
# BomCateNet = pd.read_csv('input_data/input_product_data/BomCateNet.csv', index_col=0)
|
||||||
BomCateNet.fillna(0, inplace=True)
|
# BomCateNet.fillna(0, inplace=True)
|
||||||
|
|
||||||
G = nx.from_pandas_adjacency(BomCateNet.T, create_using=nx.MultiDiGraph())
|
bom_nodes = pd.read_csv('input_data/input_product_data/BomNodes.csv')
|
||||||
|
bom_nodes['Code'] = bom_nodes['Code'].astype(str)
|
||||||
|
bom_nodes.set_index('Index', inplace=True)
|
||||||
|
|
||||||
|
bom_cate_net = pd.read_csv('input_data/input_product_data/合成结点.csv')
|
||||||
|
g_bom = nx.from_pandas_edgelist(bom_cate_net, source='UPID', target='ID', create_using=nx.MultiDiGraph())
|
||||||
|
|
||||||
labels_dict = {}
|
labels_dict = {}
|
||||||
for code in G.nodes:
|
for code in g_bom.nodes:
|
||||||
node_attr = BomNodes.loc[code].to_dict()
|
node_attr = bom_nodes.loc[code].to_dict()
|
||||||
index_list = count_prod[count_prod['id_product'] == code].index.tolist()
|
index_list = count_prod[count_prod['id_product'] == code].index.tolist()
|
||||||
index = index_list[0] if len(index_list) == 1 else -1
|
index = index_list[0] if len(index_list) == 1 else -1
|
||||||
node_attr['count'] = count_prod['count'].get(index, 0)
|
node_attr['count'] = count_prod['count'].get(index, 0)
|
||||||
node_attr['node_size'] = count_prod['count'].get(index, 0)
|
node_attr['node_size'] = (count_prod['count'].get(index, 0))/10
|
||||||
node_attr['node_color'] = count_prod['count'].get(index, 0)
|
node_attr['node_color'] = count_prod['count'].get(index, 0)
|
||||||
labels_dict[code] = node_attr
|
labels_dict[code] = node_attr
|
||||||
nx.set_node_attributes(G, labels_dict)
|
nx.set_node_attributes(g_bom, labels_dict)
|
||||||
# print(labels_dict)
|
# print(labels_dict)
|
||||||
|
|
||||||
pos = nx.nx_agraph.graphviz_layout(G, prog="twopi", args="")
|
pos = nx.nx_agraph.graphviz_layout(g_bom, prog="twopi", args="")
|
||||||
dict_node_name = nx.get_node_attributes(G, 'Name')
|
dict_node_name = nx.get_node_attributes(g_bom, 'Name')
|
||||||
node_labels = {}
|
node_labels = {}
|
||||||
for node in nx.nodes(G):
|
for node in nx.nodes(g_bom):
|
||||||
node_labels[node] = f"{node} {str(dict_node_name[node])}"
|
node_labels[node] = f"{node} {str(dict_node_name[node])}"
|
||||||
# node_labels[node] = f"{str(dict_node_name[node])}"
|
# node_labels[node] = f"{str(dict_node_name[node])}"
|
||||||
colors = list(nx.get_node_attributes(G, 'node_color').values())
|
colors = list(nx.get_node_attributes(g_bom, 'node_color').values())
|
||||||
vmin = min(colors)
|
vmin = min(colors)
|
||||||
vmax = max(colors)
|
vmax = max(colors)
|
||||||
cmap = plt.cm.Blues
|
cmap = plt.cm.Blues
|
||||||
|
# 创建绘图对象
|
||||||
fig = plt.figure(figsize=(10, 10), dpi=300)
|
fig = plt.figure(figsize=(10, 10), dpi=300)
|
||||||
nx.draw(G,
|
ax = fig.add_subplot(111)
|
||||||
pos,
|
|
||||||
node_size=list(nx.get_node_attributes(G, 'node_size').values()),
|
# 绘制网络图(优化样式参数)
|
||||||
|
nx.draw(g_bom, pos,
|
||||||
|
node_size=list(nx.get_node_attributes(g_bom, 'node_size').values()),
|
||||||
labels=node_labels,
|
labels=node_labels,
|
||||||
font_size=6,
|
font_size=3,
|
||||||
node_color=colors,
|
node_color=colors,
|
||||||
cmap=cmap,
|
cmap=cmap,
|
||||||
vmin=vmin,
|
vmin=vmin,
|
||||||
vmax=vmax,
|
vmax=vmax,
|
||||||
edge_color='grey')
|
edge_color='#808080', # 中性灰
|
||||||
|
width=0.3,
|
||||||
|
edgecolors='#404040',
|
||||||
|
linewidths=0.2)
|
||||||
|
|
||||||
|
# 创建颜色条(修正实现方式)
|
||||||
sm = plt.cm.ScalarMappable(cmap=cmap, norm=plt.Normalize(vmin=vmin, vmax=vmax))
|
sm = plt.cm.ScalarMappable(cmap=cmap, norm=plt.Normalize(vmin=vmin, vmax=vmax))
|
||||||
sm._A = []
|
sm.set_array([])
|
||||||
position = fig.add_axes([0.01, 0.05, 0.01, 0.3])
|
|
||||||
cb = plt.colorbar(sm, fraction=0.01, cax=position)
|
# 设置颜色条位置和样式
|
||||||
cb.ax.tick_params(labelsize=8)
|
cax = fig.add_axes([0.88, 0.3, 0.015, 0.4]) # 右侧垂直对齐
|
||||||
cb.outline.set_visible(False)
|
cb = plt.colorbar(sm, cax=cax)
|
||||||
plt.savefig("output_result\\risk\\count_prod_network")
|
cb.ax.tick_params(labelsize=4, width=0.5, colors='#333333')
|
||||||
|
cb.outline.set_linewidth(0.5)
|
||||||
|
cb.set_label('Risk Level', fontsize=5, labelpad=2)
|
||||||
|
|
||||||
|
# 添加图元信息
|
||||||
|
ax.set_title("Production Risk Network", fontsize=6, pad=8, color='#2F2F2F')
|
||||||
|
plt.text(0.5, 0.02, 'Data: USTB Production System | Viz: DeepSeek-R1',
|
||||||
|
ha='center', fontsize=3, color='#666666',
|
||||||
|
transform=fig.transFigure)
|
||||||
|
|
||||||
|
# 调整边界和保存
|
||||||
|
plt.subplots_adjust(left=0.05, right=0.85, top=0.95, bottom=0.1) # 适应颜色条
|
||||||
|
plt.savefig(r"output_result/risk/count_prod_network.png", # 规范路径格式
|
||||||
|
dpi=600,
|
||||||
|
bbox_inches='tight',
|
||||||
|
pad_inches=0.05,
|
||||||
|
transparent=False)
|
||||||
plt.close()
|
plt.close()
|
||||||
|
|
||||||
# dcp_prod
|
# dcp_prod
|
||||||
@@ -74,7 +103,7 @@ count_dcp_prod.sort_values('count', inplace=True, ascending=False)
|
|||||||
count_dcp_prod.to_csv('output_result\\risk\\count_dcp_prod.csv',
|
count_dcp_prod.to_csv('output_result\\risk\\count_dcp_prod.csv',
|
||||||
index=False,
|
index=False,
|
||||||
encoding='utf-8-sig')
|
encoding='utf-8-sig')
|
||||||
count_dcp_prod = count_dcp_prod[count_dcp_prod['count'] > 50]
|
count_dcp_prod = count_dcp_prod[count_dcp_prod['count'] > 1000]
|
||||||
# print(count_dcp_prod)
|
# print(count_dcp_prod)
|
||||||
|
|
||||||
list_prod = count_dcp_prod['up_id_product'].tolist(
|
list_prod = count_dcp_prod['up_id_product'].tolist(
|
||||||
@@ -83,8 +112,8 @@ list_prod = list(set(list_prod))
|
|||||||
|
|
||||||
# init graph bom
|
# init graph bom
|
||||||
|
|
||||||
BomNodes = pd.read_csv('input_data/input_product_data/BomNodes.csv', index_col=0)
|
BomNodes = pd.read_csv('input_data/input_product_data/BomNodes.csv')
|
||||||
BomNodes.set_index('Code', inplace=True)
|
BomNodes.set_index('Index', inplace=True)
|
||||||
|
|
||||||
g_bom = nx.MultiDiGraph()
|
g_bom = nx.MultiDiGraph()
|
||||||
g_bom.add_nodes_from(list_prod)
|
g_bom.add_nodes_from(list_prod)
|
||||||
@@ -95,7 +124,6 @@ for code in list_prod:
|
|||||||
bom_labels_dict[code] = dct_attr
|
bom_labels_dict[code] = dct_attr
|
||||||
nx.set_node_attributes(g_bom, bom_labels_dict)
|
nx.set_node_attributes(g_bom, bom_labels_dict)
|
||||||
|
|
||||||
|
|
||||||
count_max = count_dcp_prod['count'].max()
|
count_max = count_dcp_prod['count'].max()
|
||||||
count_min = count_dcp_prod['count'].min()
|
count_min = count_dcp_prod['count'].min()
|
||||||
k = 5 / (count_max - count_min)
|
k = 5 / (count_max - count_min)
|
||||||
@@ -110,28 +138,55 @@ for _, row in count_dcp_prod.iterrows():
|
|||||||
g_bom.add_edges_from(lst_add_edge)
|
g_bom.add_edges_from(lst_add_edge)
|
||||||
|
|
||||||
# dcp_networkx
|
# dcp_networkx
|
||||||
pos = nx.nx_agraph.graphviz_layout(g_bom, prog="dot", args="")
|
pos = nx.nx_agraph.graphviz_layout(g_bom, prog="twopi", args="")
|
||||||
node_labels = nx.get_node_attributes(g_bom, 'Name')
|
node_labels = nx.get_node_attributes(g_bom, 'Name')
|
||||||
# rename node 1
|
|
||||||
# node_labels['1'] = '解决方案'
|
|
||||||
temp = {}
|
temp = {}
|
||||||
for key, value in node_labels.items():
|
for key, value in node_labels.items():
|
||||||
temp[key] = key + " " + value
|
temp[key] = str(key) + " " + value
|
||||||
node_labels = temp
|
node_labels = temp
|
||||||
|
node_labels ={
|
||||||
|
38: 'SiC Substrate',
|
||||||
|
39: 'GaN Substrate',
|
||||||
|
40: 'Si Substrate',
|
||||||
|
41: 'AlN Substrate',
|
||||||
|
42: 'DUV LED Substrate',
|
||||||
|
43: 'InP Substrate',
|
||||||
|
44: 'Mono-Si Wafer',
|
||||||
|
45: 'Poly-Si Wafer',
|
||||||
|
46: 'InP Cryst./Wafer',
|
||||||
|
47: 'SiC Cryst./Wafer',
|
||||||
|
48: 'GaAs Wafer',
|
||||||
|
49: 'GaN Cryst./Wafer',
|
||||||
|
50: 'Si Epi Wafer',
|
||||||
|
51: 'SiC Epi Wafer',
|
||||||
|
52: 'AlN Epi',
|
||||||
|
53: 'GaN Epi',
|
||||||
|
54: 'InP Epi',
|
||||||
|
55: 'LED Epi Wafer',
|
||||||
|
90: 'Power Devices',
|
||||||
|
91: 'Diode',
|
||||||
|
92: 'Transistor',
|
||||||
|
93: 'Thyristor',
|
||||||
|
94: 'Rectifier',
|
||||||
|
95: 'IC Fab',
|
||||||
|
99: 'Wafer Test'
|
||||||
|
}
|
||||||
colors = nx.get_edge_attributes(g_bom, "count")
|
colors = nx.get_edge_attributes(g_bom, "count")
|
||||||
colors = [w for (n1, n2, _), w in colors.items()]
|
colors = [w for (n1, n2, _), w in colors.items()]
|
||||||
vmin = min(colors)
|
vmin = min(colors)
|
||||||
vmax = max(colors)
|
vmax = max(colors)
|
||||||
cmap = plt.cm.Blues
|
cmap = plt.cm.Blues
|
||||||
|
|
||||||
pos_new = {}
|
pos_new = {node: (p[1], p[0]) for node, p in pos.items()} # 字典推导式优化
|
||||||
for node, p in pos.items():
|
|
||||||
pos_new[node] = (p[1], p[0])
|
|
||||||
|
|
||||||
fig = plt.figure(figsize=(6, 10), dpi=300)
|
fig = plt.figure(figsize=(8, 8), dpi=300)
|
||||||
# plt.subplots_adjust(right=0.7)
|
plt.subplots_adjust(right=0.85) # 关键调整:右侧保留15%空白
|
||||||
nx.draw(g_bom,
|
|
||||||
pos_new,
|
# 使用Axes对象精准控制
|
||||||
|
main_ax = fig.add_axes([0.1, 0.1, 0.75, 0.8]) # 主图占左75%宽,上下各留10%边距
|
||||||
|
nx.draw(g_bom, pos_new,
|
||||||
|
ax=main_ax,
|
||||||
node_size=50,
|
node_size=50,
|
||||||
labels=node_labels,
|
labels=node_labels,
|
||||||
font_size=5,
|
font_size=5,
|
||||||
@@ -139,17 +194,30 @@ nx.draw(g_bom,
|
|||||||
edge_color=colors,
|
edge_color=colors,
|
||||||
edge_cmap=cmap,
|
edge_cmap=cmap,
|
||||||
edge_vmin=vmin,
|
edge_vmin=vmin,
|
||||||
edge_vmax=vmax)
|
edge_vmax=vmax,
|
||||||
plt.axis('off')
|
)
|
||||||
axis = plt.gca()
|
main_ax.axis('off')
|
||||||
axis.set_xlim([1.2*x for x in axis.get_xlim()])
|
|
||||||
axis.set_ylim([1.2*y for y in axis.get_ylim()])
|
|
||||||
|
|
||||||
|
# 颜色条定位系统
|
||||||
|
cbar_ax = fig.add_axes([0.86, 0.15, 0.015, 0.3]) # 右边缘86%位置,底部15%起,占30%高度
|
||||||
sm = plt.cm.ScalarMappable(cmap=cmap, norm=plt.Normalize(vmin=vmin, vmax=vmax))
|
sm = plt.cm.ScalarMappable(cmap=cmap, norm=plt.Normalize(vmin=vmin, vmax=vmax))
|
||||||
sm._A = []
|
sm._A = [] # 必需的空数组
|
||||||
position = fig.add_axes([0.75, 0.1, 0.01, 0.2])
|
|
||||||
cb = plt.colorbar(sm, fraction=0.01, cax=position)
|
# 微调颜色条样式
|
||||||
cb.ax.tick_params(labelsize=8)
|
cbar = fig.colorbar(sm, cax=cbar_ax, orientation='vertical')
|
||||||
cb.outline.set_visible(False)
|
cbar.ax.tick_params(labelsize=4,
|
||||||
plt.savefig("output_result\\risk\\count_dcp_prod_network")
|
width=0.3, # 刻度线粗细
|
||||||
|
length=1.5, # 刻度线长度
|
||||||
|
pad=0.8) # 标签与条间距
|
||||||
|
cbar.outline.set_linewidth(0.5) # 边框线宽
|
||||||
|
|
||||||
|
# 输出前验证边界
|
||||||
|
print(f"Colorbar position: {cbar_ax.get_position().bounds}") # 应输出(0.86,0.15,0.015,0.3)
|
||||||
|
|
||||||
|
# 专业级保存参数
|
||||||
|
plt.savefig("output_result/risk/count_dcp_prod_network.png",
|
||||||
|
dpi=900,
|
||||||
|
bbox_inches='tight', # 自动裁剪白边
|
||||||
|
pad_inches=0.05, # 保留0.05英寸边距
|
||||||
|
metadata={'CreationDate': None}) # 避免时间戳污染元数据
|
||||||
plt.close()
|
plt.close()
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
import pickle
|
||||||
|
|
||||||
from sqlalchemy import text
|
from sqlalchemy import text
|
||||||
from orm import engine, connection
|
from orm import engine, connection
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
@@ -5,107 +7,450 @@ import networkx as nx
|
|||||||
import json
|
import json
|
||||||
import matplotlib.pyplot as plt
|
import matplotlib.pyplot as plt
|
||||||
|
|
||||||
# prep data
|
# Prepare 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('string')
|
Firm['Code'] = Firm['Code'].astype('string')
|
||||||
Firm.fillna(0, inplace=True)
|
Firm.fillna(0, inplace=True)
|
||||||
BomNodes = pd.read_csv('input_data/input_product_data/BomNodes.csv', index_col=0)
|
BomNodes = pd.read_csv('input_data/input_product_data/BomNodes.csv', index_col=0)
|
||||||
|
|
||||||
|
# SQL query
|
||||||
with open('SQL_analysis_risk.sql', 'r') as f:
|
with open('SQL_analysis_risk.sql', 'r') as f:
|
||||||
str_sql = text(f.read())
|
str_sql = text(f.read())
|
||||||
|
|
||||||
result = pd.read_sql(sql=str_sql,
|
result = pd.read_sql(sql=str_sql, con=connection)
|
||||||
con=connection)
|
result.to_csv('output_result/risk/count.csv', index=False, encoding='utf-8-sig')
|
||||||
result.to_csv('output_result\\risk\\count.csv',
|
|
||||||
index=False,
|
|
||||||
encoding='utf-8-sig')
|
|
||||||
print(result)
|
print(result)
|
||||||
|
|
||||||
# G bom
|
# G_bom
|
||||||
plt.rcParams['font.sans-serif'] = 'SimHei'
|
plt.rcParams['font.sans-serif'] = 'SimHei'
|
||||||
|
|
||||||
exp_id = 1
|
exp_id = 1
|
||||||
G_bom_str = pd.read_sql(
|
G_bom_df = pd.read_sql(
|
||||||
sql=text(f'select g_bom from iiabmdb.without_exp_experiment '
|
sql=text(f'select g_bom from iiabmdb.without_exp_experiment where id = {exp_id};'),
|
||||||
f'where id = {exp_id};'),
|
con=connection
|
||||||
con=connection)['g_bom'].tolist()[0]
|
)
|
||||||
|
|
||||||
|
if G_bom_df.empty:
|
||||||
|
raise ValueError(f"No g_bom found for exp_id = {exp_id}")
|
||||||
|
|
||||||
|
G_bom_str = G_bom_df['g_bom'].tolist()[0]
|
||||||
|
if G_bom_str is None:
|
||||||
|
raise ValueError(f"g_bom data is None for exp_id = {exp_id}")
|
||||||
|
|
||||||
G_bom = nx.adjacency_graph(json.loads(G_bom_str))
|
G_bom = nx.adjacency_graph(json.loads(G_bom_str))
|
||||||
pos = nx.nx_agraph.graphviz_layout(G_bom, prog="twopi", args="")
|
pos = nx.nx_agraph.graphviz_layout(G_bom, prog="twopi", args="")
|
||||||
node_labels = nx.get_node_attributes(G_bom, 'Name')
|
node_labels = nx.get_node_attributes(G_bom, 'Name')
|
||||||
# rename node 1
|
node_labels = {
|
||||||
# node_labels['1'] = '工业互联网'
|
7: 'Si Raw Mtl.',
|
||||||
# node_labels['1.1'] = '工业自动化硬件'
|
8: 'Photoresist & Reagents',
|
||||||
# node_labels['1.4'] = '工业互联网安全管理'
|
9: 'Etch Solution',
|
||||||
# node_labels['1.2.1'] = '网络互联服务'
|
10: 'SiF4',
|
||||||
# node_labels['1.2.2'] = '标识解析服务'
|
11: 'Developer',
|
||||||
# node_labels['1.2.3'] = '数据互通服务'
|
12: 'PCE Superplasticizer',
|
||||||
# node_labels['1.3.1'] = '设计研发软件'
|
13: 'Metal Protectant',
|
||||||
# node_labels['1.3.2'] = '采购供应软件'
|
14: 'Deep Hole Cu Plating',
|
||||||
# node_labels['1.3.3'] = '生产制造软件'
|
15: 'Thinner',
|
||||||
# node_labels['1.3.4'] = '企业运营软件'
|
16: 'HP Boric Acid (Nuc.)',
|
||||||
# node_labels['1.3.5'] = '仓储物流软件'
|
17: 'E-Grade Epoxy',
|
||||||
plt.figure(figsize=(12, 12), dpi=300)
|
18: 'Stripper',
|
||||||
nx.draw_networkx_nodes(G_bom, pos)
|
19: 'HP-MOC',
|
||||||
nx.draw_networkx_edges(G_bom, pos)
|
20: 'CMP Slurry & Consumables',
|
||||||
nx.draw_networkx_labels(G_bom, pos, labels=node_labels, font_size=6)
|
21: 'PR Remover',
|
||||||
# plt.show()
|
22: 'Poly-Si Cutting Fluid',
|
||||||
plt.savefig(f"output_result\\risk\\g_bom_exp_id_{exp_id}.png")
|
23: 'Passivation',
|
||||||
|
24: 'E-Grade Phenolic',
|
||||||
|
25: 'Surfactant',
|
||||||
|
26: 'Mag. Carrier',
|
||||||
|
27: 'Wet Chems.',
|
||||||
|
28: 'Plating Chems.',
|
||||||
|
29: 'E-FR Materials',
|
||||||
|
30: 'LC Alignment Agent',
|
||||||
|
31: 'Func. Wet Chems.',
|
||||||
|
32: 'InP',
|
||||||
|
33: 'SiC',
|
||||||
|
34: 'GaAs',
|
||||||
|
35: 'GaN',
|
||||||
|
36: 'AlN',
|
||||||
|
37: 'Si3N4',
|
||||||
|
38: 'SiC Substrate',
|
||||||
|
39: 'GaN Substrate',
|
||||||
|
40: 'Si Wafer',
|
||||||
|
41: 'AlN Substrate',
|
||||||
|
42: 'DUV LED Substrate',
|
||||||
|
43: 'InP Substrate',
|
||||||
|
44: 'Mono-Si Wafer',
|
||||||
|
45: 'Poly-Si Wafer',
|
||||||
|
46: 'InP Cryst./Wafer',
|
||||||
|
47: 'SiC Cryst./Wafer',
|
||||||
|
48: 'GaAs Wafer',
|
||||||
|
49: 'GaN Cryst./Wafer',
|
||||||
|
50: 'Si Epi Wafer',
|
||||||
|
51: 'SiC Epi Wafer',
|
||||||
|
52: 'AlN Epi',
|
||||||
|
53: 'GaN Epi',
|
||||||
|
54: 'InP Epi',
|
||||||
|
55: 'LED Epi',
|
||||||
|
56: 'EDA/IP',
|
||||||
|
57: 'MPW Service',
|
||||||
|
58: 'IC Design',
|
||||||
|
59: 'Track System',
|
||||||
|
60: 'Wafer Grinder',
|
||||||
|
61: 'Etcher',
|
||||||
|
62: 'Ox/Diff Furnace',
|
||||||
|
63: 'Wafer Metrology',
|
||||||
|
64: 'Crystal Grower',
|
||||||
|
65: 'CMP Tool',
|
||||||
|
66: 'Stepper',
|
||||||
|
67: 'Wafer Dicer',
|
||||||
|
68: 'Deposition System',
|
||||||
|
69: 'Edge Profiler',
|
||||||
|
70: 'Descum Tool',
|
||||||
|
71: 'Clean System',
|
||||||
|
72: 'SAF',
|
||||||
|
73: 'Plating Eqpt.',
|
||||||
|
74: 'Implanter',
|
||||||
|
75: 'Trim/Form',
|
||||||
|
76: 'Probe Card',
|
||||||
|
77: 'ATE',
|
||||||
|
78: 'PCM Eqpt.',
|
||||||
|
79: 'Inspection Sys.',
|
||||||
|
80: 'Prober',
|
||||||
|
81: 'Dicing Saw',
|
||||||
|
82: 'Handler',
|
||||||
|
83: 'Backgrinder',
|
||||||
|
84: 'Die Bonder',
|
||||||
|
85: 'Reflow Oven',
|
||||||
|
86: 'FT Tester',
|
||||||
|
87: 'Wire Bonder',
|
||||||
|
88: 'BGA Mounter',
|
||||||
|
89: 'Molding Press',
|
||||||
|
90: 'Power Devices',
|
||||||
|
91: 'Diode',
|
||||||
|
92: 'Transistor',
|
||||||
|
93: 'Thyristor',
|
||||||
|
94: 'Rectifier',
|
||||||
|
95: 'IC Fab',
|
||||||
|
96: 'IC PKG',
|
||||||
|
97: 'DV',
|
||||||
|
98: 'IPM',
|
||||||
|
99: 'CP Test',
|
||||||
|
100: 'FT Test',
|
||||||
|
101: 'Bumping',
|
||||||
|
102: 'DA Materials',
|
||||||
|
103: 'Leadframe',
|
||||||
|
104: 'Solder Ball',
|
||||||
|
105: 'Substrate',
|
||||||
|
106: 'EMC',
|
||||||
|
107: 'Bond Wire',
|
||||||
|
108: 'Underfill',
|
||||||
|
109: 'Dicing Tape'
|
||||||
|
}
|
||||||
|
plt.figure(figsize=(12, 12), dpi=500)
|
||||||
|
plt.axis('off') # 关闭坐标轴边框
|
||||||
|
|
||||||
|
# 优化节点绘制参数
|
||||||
|
nx.draw_networkx_nodes(
|
||||||
|
G_bom, pos,
|
||||||
|
node_size=100, # 优化节点尺寸
|
||||||
|
linewidths=0.0 # 去除节点边框
|
||||||
|
)
|
||||||
|
# 优化边绘制参数
|
||||||
|
nx.draw_networkx_edges(
|
||||||
|
G_bom, pos,
|
||||||
|
width=0.3, # 更细的边宽
|
||||||
|
alpha=0.5 # 半透明边
|
||||||
|
)
|
||||||
|
# 优化标签参数
|
||||||
|
nx.draw_networkx_labels(
|
||||||
|
G_bom, pos,
|
||||||
|
labels=node_labels,
|
||||||
|
font_size=3, # 适当增大字号
|
||||||
|
font_family='sans-serif', # 使用无衬线字体
|
||||||
|
font_weight='bold', # 增强可读性
|
||||||
|
)
|
||||||
|
|
||||||
|
# 专业级保存参数设置
|
||||||
|
plt.savefig(
|
||||||
|
f"output_result/risk/g_bom_exp_id_{exp_id}.png",
|
||||||
|
bbox_inches='tight', # 去除图像白边
|
||||||
|
pad_inches=0.1, # 适当内边距
|
||||||
|
facecolor='white' # 保证背景纯白
|
||||||
|
)
|
||||||
plt.close()
|
plt.close()
|
||||||
|
|
||||||
# G firm
|
# G_firm
|
||||||
plt.rcParams['font.sans-serif'] = 'SimHei'
|
plt.rcParams['font.sans-serif'] = 'SimHei'
|
||||||
|
|
||||||
sample_id = 1
|
sample_id = 1
|
||||||
|
# G_firm_df = pd.read_sql(
|
||||||
|
# sql=text(f'select g_firm from iiabmdb.without_exp_sample where id = {sample_id};'),
|
||||||
|
# con=connection
|
||||||
|
# )
|
||||||
|
#
|
||||||
|
# if G_firm_df.empty:
|
||||||
|
# raise ValueError(f"No g_firm found for sample_id = {sample_id}")
|
||||||
|
#
|
||||||
|
# G_firm_str = G_firm_df['g_firm'].tolist()[0]
|
||||||
|
# if G_firm_str is None:
|
||||||
|
# raise ValueError(f"g_firm data is None for sample_id = {sample_id}")
|
||||||
|
#
|
||||||
|
# G_firm = nx.adjacency_graph(json.loads(G_firm_str))
|
||||||
|
|
||||||
G_firm_str = pd.read_sql(
|
with open("firm_network.pkl", 'rb') as f:
|
||||||
sql=text(f'select g_firm from iiabmdb.without_exp_sample '
|
G_firm = pickle.load(f)
|
||||||
f'where id = {exp_id};'),
|
print(f"Successfully loaded cached data from firm_network.pkl")
|
||||||
con=connection)['g_firm'].tolist()[0]
|
|
||||||
|
|
||||||
G_firm = nx.adjacency_graph(json.loads(G_firm_str))
|
# 1. 移除孤立节点
|
||||||
|
isolated_nodes = list(nx.isolates(G_firm)) # 找出所有没有连接的孤立节点
|
||||||
|
G_firm.remove_nodes_from(isolated_nodes) # 从图中移除这些节点
|
||||||
|
|
||||||
|
# 2. 重新布局和绘图
|
||||||
pos = nx.nx_agraph.graphviz_layout(G_firm, prog="twopi", args="")
|
pos = nx.nx_agraph.graphviz_layout(G_firm, prog="twopi", args="")
|
||||||
# desensitize
|
node_label = {key: key for key in nx.get_node_attributes(G_firm, 'Revenue_Log').keys()}
|
||||||
node_label = nx.get_node_attributes(G_firm, 'Revenue_Log')
|
|
||||||
node_label = {
|
node_label = {
|
||||||
key: key
|
"7": "1",
|
||||||
for key in node_label.keys()
|
"9": "2",
|
||||||
|
"829768": "4",
|
||||||
|
"863079": "5",
|
||||||
|
"1452048": "6",
|
||||||
|
"2010673": "7",
|
||||||
|
"2624175": "8",
|
||||||
|
"2728939": "9",
|
||||||
|
"5278074": "10",
|
||||||
|
"5849940": "11",
|
||||||
|
"7299120": "12",
|
||||||
|
"9746245": "13",
|
||||||
|
"11807506": "14",
|
||||||
|
"15613202": "15",
|
||||||
|
"24284343": "19",
|
||||||
|
"24673506": "20",
|
||||||
|
"25036634": "21",
|
||||||
|
"25685135": "24",
|
||||||
|
"25945288": "25",
|
||||||
|
"26162741": "26",
|
||||||
|
"26516263": "27",
|
||||||
|
"27075840": "28",
|
||||||
|
"27731896": "29",
|
||||||
|
"29954548": "30",
|
||||||
|
"43407343": "33",
|
||||||
|
"70634828": "36",
|
||||||
|
"71271700": "37",
|
||||||
|
"80158773": "39",
|
||||||
|
"118882692": "40",
|
||||||
|
"145511905": "42",
|
||||||
|
"151606446": "43",
|
||||||
|
"152008168": "44",
|
||||||
|
"159511306": "45",
|
||||||
|
"191912252": "46",
|
||||||
|
"194210021": "47",
|
||||||
|
"203314437": "48",
|
||||||
|
"213386023": "49",
|
||||||
|
"218633337": "50",
|
||||||
|
"251189644": "53",
|
||||||
|
"271860868": "55",
|
||||||
|
"278221281": "56",
|
||||||
|
"301209792": "57",
|
||||||
|
"343012684": "59",
|
||||||
|
"354897041": "60",
|
||||||
|
"400488703": "62",
|
||||||
|
"400692942": "63",
|
||||||
|
"413274977": "64",
|
||||||
|
"420984285": "65",
|
||||||
|
"448033045": "66",
|
||||||
|
"453289520": "67",
|
||||||
|
"474279224": "68",
|
||||||
|
"483081978": "69",
|
||||||
|
"495782506": "70",
|
||||||
|
"503176785": "73",
|
||||||
|
"549184982": "75",
|
||||||
|
"560866402": "76",
|
||||||
|
"561545339": "77",
|
||||||
|
"571058167": "78",
|
||||||
|
"581407487": "79",
|
||||||
|
"591452402": "80",
|
||||||
|
"593312758": "81",
|
||||||
|
"594378026": "82",
|
||||||
|
"607512171": "83",
|
||||||
|
"615763365": "84",
|
||||||
|
"620220747": "85",
|
||||||
|
"631449822": "86",
|
||||||
|
"644292599": "87",
|
||||||
|
"653528340": "88",
|
||||||
|
"654825436": "89",
|
||||||
|
"688155470": "92",
|
||||||
|
"695995052": "93",
|
||||||
|
"750610681": "95",
|
||||||
|
"762985858": "96",
|
||||||
|
"771821595": "97",
|
||||||
|
"857978527": "100",
|
||||||
|
"868012326": "101",
|
||||||
|
"887840774": "102",
|
||||||
|
"888356483": "103",
|
||||||
|
"888395016": "104",
|
||||||
|
"888478182": "105",
|
||||||
|
"930767828": "107",
|
||||||
|
"996174506": "108",
|
||||||
|
"1033972427": "110",
|
||||||
|
"1128343125": "111",
|
||||||
|
"1217957486": "113",
|
||||||
|
"1307012237": "115",
|
||||||
|
"1375606900": "116",
|
||||||
|
"1549474227": "118",
|
||||||
|
"1606833003": "120",
|
||||||
|
"1679596339": "121",
|
||||||
|
"2310825263": "122",
|
||||||
|
"2311838590": "124",
|
||||||
|
"2312490120": "125",
|
||||||
|
"2316990095": "128",
|
||||||
|
"2317245827": "129",
|
||||||
|
"2317841563": "131",
|
||||||
|
"2320102626": "132",
|
||||||
|
"2320475044": "133",
|
||||||
|
"2321109759": "134",
|
||||||
|
"2324787028": "137",
|
||||||
|
"2324844174": "138",
|
||||||
|
"2326478786": "139",
|
||||||
|
"2327031723": "140",
|
||||||
|
"2327979389": "141",
|
||||||
|
"2329375731": "142",
|
||||||
|
"2333843479": "143",
|
||||||
|
"2337952436": "146",
|
||||||
|
"2339188563": "147",
|
||||||
|
"2339684065": "148",
|
||||||
|
"2341555098": "149",
|
||||||
|
"2343704209": "150",
|
||||||
|
"2348941764": "151",
|
||||||
|
"2352036411": "155",
|
||||||
|
"2354145351": "157",
|
||||||
|
"2424229017": "159",
|
||||||
|
"2545430247": "161",
|
||||||
|
"2820140348": "163",
|
||||||
|
"2944892892": "165",
|
||||||
|
"3025036704": "168",
|
||||||
|
"3026382513": "169",
|
||||||
|
"3045721313": "171",
|
||||||
|
"3047163873": "172",
|
||||||
|
"3048263744": "173",
|
||||||
|
"3069206426": "174",
|
||||||
|
"3070859372": "175",
|
||||||
|
"3072715478": "176",
|
||||||
|
"3103797386": "177",
|
||||||
|
"3111033905": "178",
|
||||||
|
"3113895788": "179",
|
||||||
|
"3120341363": "180",
|
||||||
|
"3122923980": "181",
|
||||||
|
"3127420424": "182",
|
||||||
|
"3133307899": "183",
|
||||||
|
"3147511625": "184",
|
||||||
|
"3177507356": "185",
|
||||||
|
"3188903709": "186",
|
||||||
|
"3195502499": "187",
|
||||||
|
"3203777710": "188",
|
||||||
|
"3211956484": "189",
|
||||||
|
"3215814536": "190",
|
||||||
|
"3221190269": "191",
|
||||||
|
"3226664625": "192",
|
||||||
|
"3267688490": "193",
|
||||||
|
"3269039233": "194",
|
||||||
|
"3269940677": "195",
|
||||||
|
"3271705843": "196",
|
||||||
|
"3299144127": "197",
|
||||||
|
"3312358902": "198",
|
||||||
|
"3344297292": "200",
|
||||||
|
"3372913783": "201",
|
||||||
|
"3373311444": "202",
|
||||||
|
"3384021594": "203",
|
||||||
|
"3395900897": "205",
|
||||||
|
"3398677646": "206",
|
||||||
|
"3407754893": "207",
|
||||||
|
"3433628561": "209",
|
||||||
|
"3445244192": "212",
|
||||||
|
"3445928818": "213",
|
||||||
|
"4208851809": "216",
|
||||||
|
"5007015990": "218",
|
||||||
|
"11164476478": "219",
|
||||||
|
"517717050": "223",
|
||||||
|
"737770776": "224",
|
||||||
|
"872394725": "225",
|
||||||
|
"2311581270": "226",
|
||||||
|
"2313209417": "227",
|
||||||
|
"2347013470": "228",
|
||||||
|
"2350418059": "229",
|
||||||
|
"3031009366": "234",
|
||||||
|
"3089095447": "235",
|
||||||
|
"3100891962": "236",
|
||||||
|
"3188352290": "238",
|
||||||
|
"3288105727": "239",
|
||||||
|
"3462551351": "240"
|
||||||
}
|
}
|
||||||
node_size = list(nx.get_node_attributes(G_firm, 'Revenue_Log').values())
|
|
||||||
node_size = list(map(lambda x: x**2, node_size))
|
node_size = [value * 5 for value in nx.get_node_attributes(G_firm, 'Revenue_Log').values()]
|
||||||
edge_label = nx.get_edge_attributes(G_firm, "Product")
|
edge_label = {(n1, n2): label for (n1, n2, _), label in nx.get_edge_attributes(G_firm, "Product").items()}
|
||||||
edge_label = {(n1, n2): label for (n1, n2, _), label in edge_label.items()}
|
|
||||||
plt.figure(figsize=(12, 12), dpi=300)
|
plt.figure(figsize=(15, 15), dpi=500)
|
||||||
nx.draw(G_firm, pos, node_size=node_size, labels=node_label, font_size=6)
|
plt.axis('off') # 完全关闭坐标轴系统
|
||||||
nx.draw_networkx_edge_labels(G_firm, pos, edge_label, font_size=4)
|
|
||||||
# plt.show()
|
# 分层绘制网络组件
|
||||||
plt.savefig(f"output_result\\risk\\g_firm_sample_id_{exp_id}_de.png")
|
nodes = nx.draw_networkx_nodes(
|
||||||
|
G_firm, pos,
|
||||||
|
node_size=node_size, # 保持原始尺寸设置
|
||||||
|
)
|
||||||
|
|
||||||
|
edges = nx.draw_networkx_edges(
|
||||||
|
G_firm, pos,
|
||||||
|
width=0.3, # 保持原始线宽设置
|
||||||
|
)
|
||||||
|
|
||||||
|
# 优化节点标签
|
||||||
|
labels = nx.draw_networkx_labels(
|
||||||
|
G_firm, pos,
|
||||||
|
labels=node_label,
|
||||||
|
font_size=6, # 保持原始字号
|
||||||
|
)
|
||||||
|
|
||||||
|
# 增强边标签可读性
|
||||||
|
edge_labels = nx.draw_networkx_edge_labels(
|
||||||
|
G_firm, pos,
|
||||||
|
edge_labels=edge_label,
|
||||||
|
font_size=2,
|
||||||
|
label_pos=0.5, # 标签沿边偏移量
|
||||||
|
rotate=False, # 禁止自动旋转
|
||||||
|
)
|
||||||
|
|
||||||
|
# 专业级输出配置
|
||||||
|
plt.savefig(
|
||||||
|
f"output_result/risk/g_firm_sample_id_{sample_id}_de.png",
|
||||||
|
bbox_inches='tight',
|
||||||
|
pad_inches=0.05, # 更紧凑的边距
|
||||||
|
facecolor='white', # 强制白色背景
|
||||||
|
metadata={
|
||||||
|
'Title': f"Supply Chain Risk Map - Sample {sample_id}",
|
||||||
|
'Author': 'USTB Risk Analytics',
|
||||||
|
'Copyright': 'Confidential'
|
||||||
|
}
|
||||||
|
)
|
||||||
plt.close()
|
plt.close()
|
||||||
|
|
||||||
# count firm product
|
|
||||||
|
# Count firm product
|
||||||
count_firm_prod = result.value_counts(subset=['id_firm', 'id_product'])
|
count_firm_prod = result.value_counts(subset=['id_firm', 'id_product'])
|
||||||
count_firm_prod.name = 'count'
|
count_firm_prod.name = 'count'
|
||||||
count_firm_prod = count_firm_prod.to_frame().reset_index()
|
count_firm_prod = count_firm_prod.to_frame().reset_index()
|
||||||
count_firm_prod.to_csv('output_result\\risk\\count_firm_prod.csv',
|
count_firm_prod.to_csv('output_result/risk/count_firm_prod.csv', index=False, encoding='utf-8-sig')
|
||||||
index=False,
|
|
||||||
encoding='utf-8-sig')
|
|
||||||
print(count_firm_prod)
|
print(count_firm_prod)
|
||||||
|
|
||||||
# count firm
|
# Count firm
|
||||||
count_firm = count_firm_prod.groupby('id_firm')['count'].sum()
|
count_firm = count_firm_prod.groupby('id_firm')['count'].sum()
|
||||||
count_firm = count_firm.to_frame().reset_index()
|
count_firm = count_firm.to_frame().reset_index()
|
||||||
count_firm.sort_values('count', inplace=True, ascending=False)
|
count_firm.sort_values('count', inplace=True, ascending=False)
|
||||||
count_firm.to_csv('output_result\\risk\\count_firm.csv',
|
count_firm.to_csv('output_result/risk/count_firm.csv', index=False, encoding='utf-8-sig')
|
||||||
index=False,
|
|
||||||
encoding='utf-8-sig')
|
|
||||||
print(count_firm)
|
print(count_firm)
|
||||||
|
|
||||||
# count product
|
# Count product
|
||||||
count_prod = count_firm_prod.groupby('id_product')['count'].sum()
|
count_prod = count_firm_prod.groupby('id_product')['count'].sum()
|
||||||
count_prod = count_prod.to_frame().reset_index()
|
count_prod = count_prod.to_frame().reset_index()
|
||||||
count_prod.sort_values('count', inplace=True, ascending=False)
|
count_prod.sort_values('count', inplace=True, ascending=False)
|
||||||
count_prod.to_csv('output_result\\risk\\count_prod.csv',
|
count_prod.to_csv('output_result/risk/count_prod.csv', index=False, encoding='utf-8-sig')
|
||||||
index=False,
|
|
||||||
encoding='utf-8-sig')
|
|
||||||
print(count_prod)
|
print(count_prod)
|
||||||
|
|
||||||
# DCP disruption causing probability
|
# DCP disruption causing probability
|
||||||
@@ -114,26 +459,33 @@ print(result_disrupt_ts_above_0)
|
|||||||
result_dcp = pd.DataFrame(columns=[
|
result_dcp = pd.DataFrame(columns=[
|
||||||
's_id', 'up_id_firm', 'up_id_product', 'down_id_firm', 'down_id_product'
|
's_id', 'up_id_firm', 'up_id_product', 'down_id_firm', 'down_id_product'
|
||||||
])
|
])
|
||||||
|
|
||||||
|
result_dcp_list = [] # 用列表收集数据,避免DataFrame逐行增长的问题
|
||||||
for sid, group in result.groupby('s_id'):
|
for sid, group in result.groupby('s_id'):
|
||||||
ts_start = max(group['ts'])
|
ts_start = max(group['ts'])
|
||||||
while ts_start >= 1:
|
while ts_start >= 1:
|
||||||
ts_end = ts_start - 1
|
ts_end = ts_start - 1
|
||||||
while ts_end >= 0:
|
while ts_end >= 0:
|
||||||
up = group.loc[group['ts'] == ts_end, ['id_firm', 'id_product']]
|
up = group.loc[group['ts'] == ts_end, ['id_firm', 'id_product']]
|
||||||
down = group.loc[group['ts'] == ts_start,
|
down = group.loc[group['ts'] == ts_start, ['id_firm', 'id_product']]
|
||||||
['id_firm', 'id_product']]
|
|
||||||
for _, up_row in up.iterrows():
|
for _, up_row in up.iterrows():
|
||||||
for _, down_row in down.iterrows():
|
for _, down_row in down.iterrows():
|
||||||
row = [sid]
|
result_dcp_list.append([sid] + up_row.tolist() + down_row.tolist())
|
||||||
row += up_row.tolist()
|
|
||||||
row += down_row.tolist()
|
|
||||||
result_dcp.loc[len(result_dcp.index)] = row
|
|
||||||
ts_end -= 1
|
ts_end -= 1
|
||||||
ts_start -= 1
|
ts_start -= 1
|
||||||
|
|
||||||
|
# 转换为DataFrame
|
||||||
|
result_dcp = pd.DataFrame(result_dcp_list, columns=[
|
||||||
|
's_id', 'up_id_firm', 'up_id_product', 'down_id_firm', 'down_id_product'
|
||||||
|
])
|
||||||
|
|
||||||
|
# 统计
|
||||||
count_dcp = result_dcp.value_counts(
|
count_dcp = result_dcp.value_counts(
|
||||||
subset=['up_id_firm', 'up_id_product', 'down_id_firm', 'down_id_product'])
|
subset=['up_id_firm', 'up_id_product', 'down_id_firm', 'down_id_product']
|
||||||
count_dcp.name = 'count'
|
).reset_index(name='count')
|
||||||
count_dcp = count_dcp.to_frame().reset_index()
|
|
||||||
count_dcp.to_csv('output_result\\risk\\count_dcp.csv',
|
# 保存文件
|
||||||
index=False, encoding='utf-8-sig')
|
count_dcp.to_csv('output_result/risk/count_dcp.csv', index=False, encoding='utf-8-sig')
|
||||||
|
|
||||||
|
# 输出结果
|
||||||
print(count_dcp)
|
print(count_dcp)
|
||||||
|
|||||||
50
企业描述性数据分析.py
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
import pandas as pd
|
||||||
|
|
||||||
|
# 读取数据
|
||||||
|
df = pd.read_csv('input_data/input_firm_data/firm_amended.csv') # 替换为你的 CSV 文件路径
|
||||||
|
|
||||||
|
# 要分析的列
|
||||||
|
columns = [
|
||||||
|
"固定资产原值(万元人民币)",
|
||||||
|
"固定资产净值(万元人民币)",
|
||||||
|
"资产总和(万元人民币)",
|
||||||
|
"存货(万元人民币)"
|
||||||
|
]
|
||||||
|
|
||||||
|
# 字段类型定义(可人工定义,也可自动判断)
|
||||||
|
column_types = {
|
||||||
|
"固定资产原值(万元人民币)": "连续型",
|
||||||
|
"固定资产净值(万元人民币)": "连续型",
|
||||||
|
"资产总和(万元人民币)": "连续型",
|
||||||
|
"存货(万元人民币)": "连续型"
|
||||||
|
}
|
||||||
|
|
||||||
|
# 统计分析
|
||||||
|
summary = []
|
||||||
|
|
||||||
|
for col in columns:
|
||||||
|
data = df[col].dropna()
|
||||||
|
summary.append({
|
||||||
|
"字段名": col,
|
||||||
|
"类型": column_types[col],
|
||||||
|
"计数(非空)": data.count(),
|
||||||
|
"均值": data.mean(),
|
||||||
|
"标准差": data.std(),
|
||||||
|
"最小值": data.min(),
|
||||||
|
"中位数": data.median(),
|
||||||
|
"最大值": data.max()
|
||||||
|
})
|
||||||
|
|
||||||
|
# 转为 DataFrame 展示
|
||||||
|
summary_df = pd.DataFrame(summary)
|
||||||
|
|
||||||
|
# 设置列顺序
|
||||||
|
summary_df = summary_df[["字段名", "类型", "计数(非空)", "均值", "标准差", "最小值", "中位数", "最大值"]]
|
||||||
|
|
||||||
|
# 打印结果
|
||||||
|
print(summary_df)
|
||||||
|
# 保存为 Excel 文件
|
||||||
|
output_path = "企业规模数据描述性统计表.xlsx"
|
||||||
|
summary_df.to_excel(output_path, index=False)
|
||||||
|
|
||||||
|
print(f"统计结果已保存为 Excel 文件:{output_path}")
|
||||||
BIN
企业规模数据描述性统计表.xlsx
Normal file
0
执行sql语句.py
Normal file
53
查看进度.py
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
from matplotlib import rcParams, pyplot as plt
|
||||||
|
from sqlalchemy import func
|
||||||
|
from orm import db_session, Sample
|
||||||
|
|
||||||
|
# 创建全局绘图对象和轴
|
||||||
|
fig, ax = plt.subplots(figsize=(8, 5))
|
||||||
|
plt.ion() # 启用交互模式
|
||||||
|
|
||||||
|
def visualize_progress():
|
||||||
|
"""
|
||||||
|
可视化 `is_done_flag` 的分布,动态更新进度条。
|
||||||
|
"""
|
||||||
|
|
||||||
|
# 设置全局字体
|
||||||
|
rcParams['font.family'] = 'Microsoft YaHei' # 黑体,适用于中文
|
||||||
|
rcParams['font.size'] = 12
|
||||||
|
|
||||||
|
# 查询数据库中各 is_done_flag 的数量
|
||||||
|
result = db_session.query(
|
||||||
|
Sample.is_done_flag, func.count(Sample.id)
|
||||||
|
).group_by(Sample.is_done_flag).all()
|
||||||
|
|
||||||
|
# 转换为字典
|
||||||
|
data = {flag: count for flag, count in result}
|
||||||
|
|
||||||
|
# 填充缺失的标志为 0
|
||||||
|
for flag in [-1, 0, 1]:
|
||||||
|
data.setdefault(flag, 0)
|
||||||
|
|
||||||
|
# 准备数据
|
||||||
|
labels = ['未完成 (-1)', '计算中(0)', '完成 (1)']
|
||||||
|
values = [data[-1], data[0], data[1]]
|
||||||
|
|
||||||
|
# 清空之前的绘图内容
|
||||||
|
ax.clear()
|
||||||
|
|
||||||
|
# 创建柱状图
|
||||||
|
ax.bar(labels, values, color=['red', 'orange', 'green'])
|
||||||
|
ax.set_title('任务进度分布', fontsize=16)
|
||||||
|
ax.set_xlabel('任务状态', fontsize=14)
|
||||||
|
ax.set_ylabel('数量', fontsize=14)
|
||||||
|
ax.tick_params(axis='both', labelsize=12)
|
||||||
|
|
||||||
|
# 显示具体数量
|
||||||
|
for i, v in enumerate(values):
|
||||||
|
ax.text(i, v + 0.5, str(v), ha='center', fontsize=12)
|
||||||
|
|
||||||
|
# 刷新绘图
|
||||||
|
plt.pause(0) # 暂停一段时间以更新图表
|
||||||
|
|
||||||
|
# 关闭窗口时,停止交互模式
|
||||||
|
# plt.ioff()
|
||||||
|
visualize_progress()
|
||||||
115
绘制度.py
Normal file
@@ -0,0 +1,115 @@
|
|||||||
|
import pickle
|
||||||
|
|
||||||
|
import pandas as pd
|
||||||
|
import networkx as nx
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
|
||||||
|
# 1. 读取并处理数据
|
||||||
|
bom_nodes = pd.read_csv('input_data/input_product_data/BomNodes.csv')
|
||||||
|
bom_nodes['Code'] = bom_nodes['Code'].astype(str)
|
||||||
|
bom_nodes.set_index('Index', inplace=True)
|
||||||
|
|
||||||
|
bom_cate_net = pd.read_csv('input_data/input_product_data/合成结点.csv')
|
||||||
|
|
||||||
|
# 2. 构建图结构
|
||||||
|
g_bom = nx.from_pandas_edgelist(bom_cate_net, source='UPID', target='ID', create_using=nx.MultiDiGraph())
|
||||||
|
|
||||||
|
# 填充每一个结点的具体内容
|
||||||
|
bom_labels_dict = {}
|
||||||
|
for index in g_bom.nodes:
|
||||||
|
try:
|
||||||
|
bom_labels_dict[index] = bom_nodes.loc[index].to_dict()
|
||||||
|
except KeyError:
|
||||||
|
print(f"节点 {index} 不存在于 bom_nodes 中")
|
||||||
|
|
||||||
|
# 分配属性给每一个结点
|
||||||
|
nx.set_node_attributes(g_bom, bom_labels_dict)
|
||||||
|
|
||||||
|
# 3. 计算每个节点的度数
|
||||||
|
degrees = dict(g_bom.degree()) # 总度数(适用于有向图)
|
||||||
|
|
||||||
|
# 4. 统计每个度数的节点数量
|
||||||
|
degree_counts = {}
|
||||||
|
for degree in degrees.values():
|
||||||
|
if degree in degree_counts:
|
||||||
|
degree_counts[degree] += 1
|
||||||
|
else:
|
||||||
|
degree_counts[degree] = 1
|
||||||
|
|
||||||
|
# 转换为排序后的列表(横坐标:度数,纵坐标:节点数)
|
||||||
|
sorted_degrees = sorted(degree_counts.keys())
|
||||||
|
sorted_counts = [degree_counts[d] for d in sorted_degrees]
|
||||||
|
|
||||||
|
# 5. 绘制度分布图
|
||||||
|
plt.figure(figsize=(12, 8)) # 增大画布尺寸
|
||||||
|
bars = plt.bar(sorted_degrees, sorted_counts, width=0.8)
|
||||||
|
plt.title('Degree Distribution In Industrial Chain', fontsize=16)
|
||||||
|
plt.xlabel('Degree', fontsize=14)
|
||||||
|
plt.ylabel('Number of Nodes', fontsize=14)
|
||||||
|
plt.grid(True, linestyle='--', alpha=0.5)
|
||||||
|
plt.xticks(rotation=45) # 如果度数较多,可以旋转x轴标签
|
||||||
|
plt.tight_layout() # 防止标签重叠
|
||||||
|
|
||||||
|
# 6. 在每个柱子上方标注数值
|
||||||
|
for bar in bars:
|
||||||
|
height = bar.get_height()
|
||||||
|
plt.text(
|
||||||
|
bar.get_x() + bar.get_width() / 2, # x坐标:柱子中心
|
||||||
|
height + max(sorted_counts) * 0.02, # y坐标:柱子顶部上方(留出空间)
|
||||||
|
f'{int(height)}', # 显示数值(转换为整数)
|
||||||
|
ha='center', # 水平居中
|
||||||
|
va='bottom', # 垂直底部对齐
|
||||||
|
fontsize=10, # 字体大小
|
||||||
|
color='black' # 字体颜色
|
||||||
|
)
|
||||||
|
|
||||||
|
# 7. 保存超高清图片(300 DPI)
|
||||||
|
output_path = "degree_distribution_with_labels.png" # 输出文件名
|
||||||
|
plt.savefig(output_path, dpi=500, bbox_inches='tight') # dpi=300 确保高分辨率
|
||||||
|
print(f"图片已保存至: {output_path}")
|
||||||
|
|
||||||
|
# 1. 加载企业网络数据
|
||||||
|
with open("firm_network.pkl", 'rb') as f:
|
||||||
|
G_firm = pickle.load(f)
|
||||||
|
print(f"Successfully loaded cached data from firm_network.pkl")
|
||||||
|
|
||||||
|
# 2. 计算企业网络的度分布
|
||||||
|
degrees_firm = dict(G_firm.degree()) # 总度数
|
||||||
|
degree_counts_firm = {}
|
||||||
|
for degree in degrees_firm.values():
|
||||||
|
if degree in degree_counts_firm:
|
||||||
|
degree_counts_firm[degree] += 1
|
||||||
|
else:
|
||||||
|
degree_counts_firm[degree] = 1
|
||||||
|
|
||||||
|
# 转换为排序后的列表
|
||||||
|
sorted_degrees_firm = sorted(degree_counts_firm.keys())
|
||||||
|
sorted_counts_firm = [degree_counts_firm[d] for d in sorted_degrees_firm]
|
||||||
|
|
||||||
|
# 3. 绘制企业网络的度分布图
|
||||||
|
plt.figure(figsize=(12, 6)) # 单独画布尺寸
|
||||||
|
plt.bar(sorted_degrees_firm, sorted_counts_firm, width=0.8)
|
||||||
|
plt.title('Degree Distribution of Firm Network', fontsize=16)
|
||||||
|
plt.xlabel('Degree (Number of Connections)', fontsize=14)
|
||||||
|
plt.ylabel('Number of Firms', fontsize=14)
|
||||||
|
plt.grid(True, linestyle='--', alpha=0.5)
|
||||||
|
plt.xticks(rotation=45)
|
||||||
|
plt.tight_layout()
|
||||||
|
|
||||||
|
# 在柱子上方标注数值
|
||||||
|
for bar in plt.gca().containers[0]: # 获取当前图中的柱子对象
|
||||||
|
height = bar.get_height()
|
||||||
|
plt.text(
|
||||||
|
bar.get_x() + bar.get_width() / 2,
|
||||||
|
height + max(sorted_counts_firm) * 0.02,
|
||||||
|
f'{int(height)}',
|
||||||
|
ha='center',
|
||||||
|
va='bottom',
|
||||||
|
fontsize=10,
|
||||||
|
color='black'
|
||||||
|
)
|
||||||
|
|
||||||
|
# 保存图片
|
||||||
|
plt.savefig("degree_distribution_firm.png", dpi=500, bbox_inches='tight')
|
||||||
|
print("企业度分布图已保存至: degree_distribution_firm.png")
|
||||||
|
|
||||||