exp connect first

This commit is contained in:
HaoYizhi 2023-06-10 20:56:34 +08:00
parent 313870bcc3
commit 7a08a52f3f
11 changed files with 62 additions and 47 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -75,7 +75,8 @@ class ControllerDB:
# list_dct = [{'133': ['1.4.4.1']}]
# list_dct = [{'2': ['1.1.3']}]
# list_dct = [{'135': ['1.3.2.1']}]
list_dct = [{'79': ['2.1.3.4']}]
# list_dct = [{'79': ['2.1.3.4']}]
list_dct = [{'99': ['1.3.3']}]
# fill g_bom
BomNodes = pd.read_csv('BomNodes.csv', index_col=0)
@ -94,7 +95,7 @@ class ControllerDB:
df_xv = pd.read_csv("xv_without_exp.csv", index_col=None)
# read the OA table
df_oa = pd.read_csv("oa_without_exp.csv", index_col=None)
df_oa = df_oa.iloc[:, 0:10]
df_oa = df_oa.iloc[:, 0:df_xv.shape[1]]
for idx_scenario, row in df_oa.iterrows():
dct_exp_para = {}
for idx_col, para_level in enumerate(row):
@ -112,10 +113,11 @@ class ControllerDB:
def add_experiment_1(self, idx_scenario, idx_init_removal,
dct_lst_init_remove_firm_prod, g_bom,
n_max_trial, crit_supplier, firm_req_prf_size,
firm_acc_prf_size, netw_sply_prf_n,
netw_sply_prf_size, cap_limit, diff_new_conn,
diff_remove, proactive_ratio):
n_max_trial, crit_supplier,
firm_req_prf_size, firm_req_prf_conn,
firm_acc_prf_size, firm_acc_prf_conn,
netw_sply_prf_n, netw_sply_prf_size, cap_limit,
diff_new_conn, diff_remove, proactive_ratio):
e = Experiment(
idx_scenario=idx_scenario,
idx_init_removal=idx_init_removal,
@ -126,7 +128,9 @@ class ControllerDB:
n_max_trial=n_max_trial,
crit_supplier=crit_supplier,
firm_req_prf_size=firm_req_prf_size,
firm_req_prf_conn=firm_req_prf_conn,
firm_acc_prf_size=firm_acc_prf_size,
firm_acc_prf_conn=firm_acc_prf_conn,
netw_sply_prf_n=netw_sply_prf_n,
netw_sply_prf_size=netw_sply_prf_size,
cap_limit=cap_limit,

77
firm.py
View File

@ -25,7 +25,9 @@ class FirmAgent(ap.Agent):
# para
self.flt_crit_supplier = float(self.p.crit_supplier)
self.flt_firm_req_prf_size = float(self.p.firm_req_prf_size)
self.is_firm_req_prf_conn = bool(self.p.firm_req_prf_conn)
self.flt_firm_acc_prf_size = float(self.p.firm_acc_prf_size)
self.is_firm_acc_prf_conn = bool(self.p.firm_acc_prf_conn)
self.flt_diff_new_conn = float(self.p.diff_new_conn)
def remove_edge_to_cus_remove_cus_up_prod(self, remove_product):
@ -78,20 +80,22 @@ class FirmAgent(ap.Agent):
continue
# select based on connection
lst_firm_connect = []
for firm in self.dct_cand_alt_supply_up_prod_removed[product]:
out_edges = self.model.firm_network.graph.out_edges(
self.model.firm_network.positions[firm], keys=True)
in_edges = self.model.firm_network.graph.in_edges(
self.model.firm_network.positions[firm], keys=True)
lst_adj_firm = []
lst_adj_firm += \
[ap.AgentIter(self.model, edge[1]).to_list()[
0].code for edge in out_edges]
lst_adj_firm += \
[ap.AgentIter(self.model, edge[0]).to_list()[
0].code for edge in in_edges]
if self.code in lst_adj_firm:
lst_firm_connect.append(firm)
if self.is_firm_req_prf_conn:
for firm in \
self.dct_cand_alt_supply_up_prod_removed[product]:
out_edges = self.model.firm_network.graph.out_edges(
self.model.firm_network.positions[firm], keys=True)
in_edges = self.model.firm_network.graph.in_edges(
self.model.firm_network.positions[firm], keys=True)
lst_adj_firm = []
lst_adj_firm += \
[ap.AgentIter(self.model, edge[1]).to_list()[
0].code for edge in out_edges]
lst_adj_firm += \
[ap.AgentIter(self.model, edge[0]).to_list()[
0].code for edge in in_edges]
if self.code in lst_adj_firm:
lst_firm_connect.append(firm)
if len(lst_firm_connect) == 0:
# select based on size
lst_size_damp = \
@ -106,8 +110,8 @@ class FirmAgent(ap.Agent):
elif len(lst_firm_connect) > 0:
# select based on size of firm that has connection
lst_firm_size_damp = \
[size ** self.flt_firm_acc_prf_size
for size in lst_firm_connect.revenue_log]
[firm.revenue_log ** self.flt_firm_acc_prf_size
for firm in lst_firm_connect]
lst_prob = \
[size_damp / sum(lst_firm_size_damp)
for size_damp in lst_firm_size_damp]
@ -150,25 +154,30 @@ class FirmAgent(ap.Agent):
elif len(lst_firm) > 1:
# handling based on connection
lst_firm_connect = []
for firm in lst_firm:
out_edges = self.model.firm_network.graph.out_edges(
self.model.firm_network.positions[firm], keys=True)
in_edges = self.model.firm_network.graph.in_edges(
self.model.firm_network.positions[firm], keys=True)
lst_adj_firm = []
lst_adj_firm += \
[ap.AgentIter(self.model, edge[1]).to_list()[
0].code for edge in out_edges]
lst_adj_firm += \
[ap.AgentIter(self.model, edge[0]).to_list()[
0].code for edge in in_edges]
if self.code in lst_adj_firm:
lst_firm_connect.append(firm)
if self.is_firm_acc_prf_conn:
for firm in lst_firm:
out_edges = \
self.model.firm_network.graph.out_edges(
self.model.firm_network.positions[firm],
keys=True)
in_edges = \
self.model.firm_network.graph.in_edges(
self.model.firm_network.positions[firm],
keys=True)
lst_adj_firm = []
lst_adj_firm += \
[ap.AgentIter(self.model, edge[1]).to_list()[
0].code for edge in out_edges]
lst_adj_firm += \
[ap.AgentIter(self.model, edge[0]).to_list()[
0].code for edge in in_edges]
if self.code in lst_adj_firm:
lst_firm_connect.append(firm)
if len(lst_firm_connect) == 0:
# handling based on size
lst_firm_size_damp = \
[size ** self.flt_firm_acc_prf_size
for size in lst_firm.revenue_log]
[firm.revenue_log ** self.flt_firm_acc_prf_size
for firm in lst_firm]
lst_prob = \
[size_damp / sum(lst_firm_size_damp)
for size_damp in lst_firm_size_damp]
@ -178,8 +187,8 @@ class FirmAgent(ap.Agent):
elif len(lst_firm_connect) > 0:
# handling based on size of firm that has connection
lst_firm_size_damp = \
[size ** self.flt_firm_acc_prf_size
for size in lst_firm_connect.revenue_log]
[firm.revenue_log ** self.flt_firm_acc_prf_size
for firm in lst_firm_connect]
lst_prob = \
[size_damp / sum(lst_firm_size_damp)
for size_damp in lst_firm_size_damp]

View File

@ -277,7 +277,7 @@ class Model(ap.Model):
break
# draw network
# self.draw_network()
self.draw_network()
def update(self):
self.a_lst_total_firms.clean_before_time_step()

2
orm.py
View File

@ -57,7 +57,9 @@ class Experiment(Base):
n_max_trial = Column(Integer, nullable=False)
crit_supplier = Column(DECIMAL(8, 4), nullable=False)
firm_req_prf_size = Column(DECIMAL(8, 4), nullable=False)
firm_req_prf_conn = Column(Boolean, nullable=False)
firm_acc_prf_size = Column(DECIMAL(8, 4), nullable=False)
firm_acc_prf_conn = Column(Boolean, nullable=False)
netw_sply_prf_n = Column(DECIMAL(8, 4), nullable=False)
netw_sply_prf_size = Column(DECIMAL(8, 4), nullable=False)
cap_limit = Column(Integer, nullable=False)

View File

@ -1,4 +1,4 @@
n_max_trial,crit_supplier,firm_req_prf_size,firm_acc_prf_size,netw_sply_prf_size,netw_pref_supp_size,cap_limit,diff_new_conn,diff_remove,proactive_ratio
15,2,2,2,0.5,2,4,0.5,0.5,0.4
10,1,1,1,1,1,2,1,1,0.6
5,0.5,0.5,0.5,2,0.5,1,2,2,0.8
n_max_trial,crit_supplier,firm_req_prf_size,firm_req_prf_conn,firm_acc_prf_size,firm_acc_prf_conn,netw_sply_prf_size,netw_pref_supp_size,cap_limit,diff_new_conn,diff_remove,proactive_ratio
15,2,2,True,2,True,0.5,2,4,0.5,0.5,0.4
10,1,1,False,1,False,1,1,2,1,1,0.6
5,0.5,0.5,,0.5,,2,0.5,1,2,2,0.8

1 n_max_trial crit_supplier firm_req_prf_size firm_req_prf_conn firm_acc_prf_size firm_acc_prf_conn netw_sply_prf_size netw_pref_supp_size cap_limit diff_new_conn diff_remove proactive_ratio
2 15 2 2 True 2 True 0.5 2 4 0.5 0.5 0.4
3 10 1 1 False 1 False 1 1 2 1 1 0.6
4 5 0.5 0.5 0.5 2 0.5 1 2 2 0.8

View File

@ -1,2 +1,2 @@
n_max_trial,crit_supplier,firm_req_prf_size,firm_acc_prf_size,netw_sply_prf_n,netw_sply_prf_size,cap_limit,diff_new_conn,diff_remove,proactive_ratio
10,1,1,1,1,1,2,1,1,0.8
n_max_trial,crit_supplier,firm_req_prf_size,firm_req_prf_conn,firm_acc_prf_size,firm_acc_prf_conn,netw_sply_prf_n,netw_sply_prf_size,cap_limit,diff_new_conn,diff_remove,proactive_ratio
10,1,1,True,1,True,1,1,2,1,1,0.2

1 n_max_trial crit_supplier firm_req_prf_size firm_req_prf_conn firm_acc_prf_size firm_acc_prf_conn netw_sply_prf_n netw_sply_prf_size cap_limit diff_new_conn diff_remove proactive_ratio
2 10 1 1 True 1 True 1 1 2 1 1 0.8 0.2