exp connect first
This commit is contained in:
parent
313870bcc3
commit
7a08a52f3f
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -75,7 +75,8 @@ class ControllerDB:
|
||||||
# list_dct = [{'133': ['1.4.4.1']}]
|
# list_dct = [{'133': ['1.4.4.1']}]
|
||||||
# list_dct = [{'2': ['1.1.3']}]
|
# list_dct = [{'2': ['1.1.3']}]
|
||||||
# list_dct = [{'135': ['1.3.2.1']}]
|
# 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
|
# fill g_bom
|
||||||
BomNodes = pd.read_csv('BomNodes.csv', index_col=0)
|
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)
|
df_xv = pd.read_csv("xv_without_exp.csv", index_col=None)
|
||||||
# read the OA table
|
# read the OA table
|
||||||
df_oa = pd.read_csv("oa_without_exp.csv", index_col=None)
|
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():
|
for idx_scenario, row in df_oa.iterrows():
|
||||||
dct_exp_para = {}
|
dct_exp_para = {}
|
||||||
for idx_col, para_level in enumerate(row):
|
for idx_col, para_level in enumerate(row):
|
||||||
|
@ -112,10 +113,11 @@ class ControllerDB:
|
||||||
|
|
||||||
def add_experiment_1(self, idx_scenario, idx_init_removal,
|
def add_experiment_1(self, idx_scenario, idx_init_removal,
|
||||||
dct_lst_init_remove_firm_prod, g_bom,
|
dct_lst_init_remove_firm_prod, g_bom,
|
||||||
n_max_trial, crit_supplier, firm_req_prf_size,
|
n_max_trial, crit_supplier,
|
||||||
firm_acc_prf_size, netw_sply_prf_n,
|
firm_req_prf_size, firm_req_prf_conn,
|
||||||
netw_sply_prf_size, cap_limit, diff_new_conn,
|
firm_acc_prf_size, firm_acc_prf_conn,
|
||||||
diff_remove, proactive_ratio):
|
netw_sply_prf_n, netw_sply_prf_size, cap_limit,
|
||||||
|
diff_new_conn, diff_remove, proactive_ratio):
|
||||||
e = Experiment(
|
e = Experiment(
|
||||||
idx_scenario=idx_scenario,
|
idx_scenario=idx_scenario,
|
||||||
idx_init_removal=idx_init_removal,
|
idx_init_removal=idx_init_removal,
|
||||||
|
@ -126,7 +128,9 @@ class ControllerDB:
|
||||||
n_max_trial=n_max_trial,
|
n_max_trial=n_max_trial,
|
||||||
crit_supplier=crit_supplier,
|
crit_supplier=crit_supplier,
|
||||||
firm_req_prf_size=firm_req_prf_size,
|
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_size=firm_acc_prf_size,
|
||||||
|
firm_acc_prf_conn=firm_acc_prf_conn,
|
||||||
netw_sply_prf_n=netw_sply_prf_n,
|
netw_sply_prf_n=netw_sply_prf_n,
|
||||||
netw_sply_prf_size=netw_sply_prf_size,
|
netw_sply_prf_size=netw_sply_prf_size,
|
||||||
cap_limit=cap_limit,
|
cap_limit=cap_limit,
|
||||||
|
|
77
firm.py
77
firm.py
|
@ -25,7 +25,9 @@ class FirmAgent(ap.Agent):
|
||||||
# para
|
# para
|
||||||
self.flt_crit_supplier = float(self.p.crit_supplier)
|
self.flt_crit_supplier = float(self.p.crit_supplier)
|
||||||
self.flt_firm_req_prf_size = float(self.p.firm_req_prf_size)
|
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.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)
|
self.flt_diff_new_conn = float(self.p.diff_new_conn)
|
||||||
|
|
||||||
def remove_edge_to_cus_remove_cus_up_prod(self, remove_product):
|
def remove_edge_to_cus_remove_cus_up_prod(self, remove_product):
|
||||||
|
@ -78,20 +80,22 @@ class FirmAgent(ap.Agent):
|
||||||
continue
|
continue
|
||||||
# select based on connection
|
# select based on connection
|
||||||
lst_firm_connect = []
|
lst_firm_connect = []
|
||||||
for firm in self.dct_cand_alt_supply_up_prod_removed[product]:
|
if self.is_firm_req_prf_conn:
|
||||||
out_edges = self.model.firm_network.graph.out_edges(
|
for firm in \
|
||||||
self.model.firm_network.positions[firm], keys=True)
|
self.dct_cand_alt_supply_up_prod_removed[product]:
|
||||||
in_edges = self.model.firm_network.graph.in_edges(
|
out_edges = self.model.firm_network.graph.out_edges(
|
||||||
self.model.firm_network.positions[firm], keys=True)
|
self.model.firm_network.positions[firm], keys=True)
|
||||||
lst_adj_firm = []
|
in_edges = self.model.firm_network.graph.in_edges(
|
||||||
lst_adj_firm += \
|
self.model.firm_network.positions[firm], keys=True)
|
||||||
[ap.AgentIter(self.model, edge[1]).to_list()[
|
lst_adj_firm = []
|
||||||
0].code for edge in out_edges]
|
lst_adj_firm += \
|
||||||
lst_adj_firm += \
|
[ap.AgentIter(self.model, edge[1]).to_list()[
|
||||||
[ap.AgentIter(self.model, edge[0]).to_list()[
|
0].code for edge in out_edges]
|
||||||
0].code for edge in in_edges]
|
lst_adj_firm += \
|
||||||
if self.code in lst_adj_firm:
|
[ap.AgentIter(self.model, edge[0]).to_list()[
|
||||||
lst_firm_connect.append(firm)
|
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:
|
if len(lst_firm_connect) == 0:
|
||||||
# select based on size
|
# select based on size
|
||||||
lst_size_damp = \
|
lst_size_damp = \
|
||||||
|
@ -106,8 +110,8 @@ class FirmAgent(ap.Agent):
|
||||||
elif len(lst_firm_connect) > 0:
|
elif len(lst_firm_connect) > 0:
|
||||||
# select based on size of firm that has connection
|
# select based on size of firm that has connection
|
||||||
lst_firm_size_damp = \
|
lst_firm_size_damp = \
|
||||||
[size ** self.flt_firm_acc_prf_size
|
[firm.revenue_log ** self.flt_firm_acc_prf_size
|
||||||
for size in lst_firm_connect.revenue_log]
|
for firm in lst_firm_connect]
|
||||||
lst_prob = \
|
lst_prob = \
|
||||||
[size_damp / sum(lst_firm_size_damp)
|
[size_damp / sum(lst_firm_size_damp)
|
||||||
for size_damp in 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:
|
elif len(lst_firm) > 1:
|
||||||
# handling based on connection
|
# handling based on connection
|
||||||
lst_firm_connect = []
|
lst_firm_connect = []
|
||||||
for firm in lst_firm:
|
if self.is_firm_acc_prf_conn:
|
||||||
out_edges = self.model.firm_network.graph.out_edges(
|
for firm in lst_firm:
|
||||||
self.model.firm_network.positions[firm], keys=True)
|
out_edges = \
|
||||||
in_edges = self.model.firm_network.graph.in_edges(
|
self.model.firm_network.graph.out_edges(
|
||||||
self.model.firm_network.positions[firm], keys=True)
|
self.model.firm_network.positions[firm],
|
||||||
lst_adj_firm = []
|
keys=True)
|
||||||
lst_adj_firm += \
|
in_edges = \
|
||||||
[ap.AgentIter(self.model, edge[1]).to_list()[
|
self.model.firm_network.graph.in_edges(
|
||||||
0].code for edge in out_edges]
|
self.model.firm_network.positions[firm],
|
||||||
lst_adj_firm += \
|
keys=True)
|
||||||
[ap.AgentIter(self.model, edge[0]).to_list()[
|
lst_adj_firm = []
|
||||||
0].code for edge in in_edges]
|
lst_adj_firm += \
|
||||||
if self.code in lst_adj_firm:
|
[ap.AgentIter(self.model, edge[1]).to_list()[
|
||||||
lst_firm_connect.append(firm)
|
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:
|
if len(lst_firm_connect) == 0:
|
||||||
# handling based on size
|
# handling based on size
|
||||||
lst_firm_size_damp = \
|
lst_firm_size_damp = \
|
||||||
[size ** self.flt_firm_acc_prf_size
|
[firm.revenue_log ** self.flt_firm_acc_prf_size
|
||||||
for size in lst_firm.revenue_log]
|
for firm in lst_firm]
|
||||||
lst_prob = \
|
lst_prob = \
|
||||||
[size_damp / sum(lst_firm_size_damp)
|
[size_damp / sum(lst_firm_size_damp)
|
||||||
for size_damp in 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:
|
elif len(lst_firm_connect) > 0:
|
||||||
# handling based on size of firm that has connection
|
# handling based on size of firm that has connection
|
||||||
lst_firm_size_damp = \
|
lst_firm_size_damp = \
|
||||||
[size ** self.flt_firm_acc_prf_size
|
[firm.revenue_log ** self.flt_firm_acc_prf_size
|
||||||
for size in lst_firm_connect.revenue_log]
|
for firm in lst_firm_connect]
|
||||||
lst_prob = \
|
lst_prob = \
|
||||||
[size_damp / sum(lst_firm_size_damp)
|
[size_damp / sum(lst_firm_size_damp)
|
||||||
for size_damp in lst_firm_size_damp]
|
for size_damp in lst_firm_size_damp]
|
||||||
|
|
2
model.py
2
model.py
|
@ -277,7 +277,7 @@ class Model(ap.Model):
|
||||||
break
|
break
|
||||||
|
|
||||||
# draw network
|
# draw network
|
||||||
# self.draw_network()
|
self.draw_network()
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
self.a_lst_total_firms.clean_before_time_step()
|
self.a_lst_total_firms.clean_before_time_step()
|
||||||
|
|
2
orm.py
2
orm.py
|
@ -57,7 +57,9 @@ class Experiment(Base):
|
||||||
n_max_trial = Column(Integer, nullable=False)
|
n_max_trial = Column(Integer, nullable=False)
|
||||||
crit_supplier = Column(DECIMAL(8, 4), nullable=False)
|
crit_supplier = Column(DECIMAL(8, 4), nullable=False)
|
||||||
firm_req_prf_size = 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_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_n = Column(DECIMAL(8, 4), nullable=False)
|
||||||
netw_sply_prf_size = Column(DECIMAL(8, 4), nullable=False)
|
netw_sply_prf_size = Column(DECIMAL(8, 4), nullable=False)
|
||||||
cap_limit = Column(Integer, nullable=False)
|
cap_limit = Column(Integer, nullable=False)
|
||||||
|
|
|
@ -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
|
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,2,0.5,2,4,0.5,0.5,0.4
|
15,2,2,True,2,True,0.5,2,4,0.5,0.5,0.4
|
||||||
10,1,1,1,1,1,2,1,1,0.6
|
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
|
5,0.5,0.5,,0.5,,2,0.5,1,2,2,0.8
|
||||||
|
|
|
|
@ -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
|
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,1,1,1,2,1,1,0.8
|
10,1,1,True,1,True,1,1,2,1,1,0.2
|
||||||
|
|
|
Loading…
Reference in New Issue