exp connect first
This commit is contained in:
77
firm.py
77
firm.py
@@ -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]
|
||||
|
||||
Reference in New Issue
Block a user