change the way to find connected firm

This commit is contained in:
HaoYizhi 2023-07-27 12:56:22 +08:00
parent 74d8798b1d
commit 921f03fc44
2 changed files with 12 additions and 28 deletions

Binary file not shown.

40
firm.py
View File

@ -120,18 +120,12 @@ class FirmAgent(ap.Agent):
if self.is_prf_conn:
for firm in \
self.dct_cand_alt_supp_up_prod_disrupted[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:
node_self = self.get_firm_network_node()
node_firm = firm.get_firm_network_node()
if self.model.firm_network.graph.\
has_edge(node_self, node_firm) or \
self.model.firm_network.graph.\
has_edge(node_firm, node_self):
lst_firm_connect.append(firm)
if len(lst_firm_connect) == 0:
# select based on size or not
@ -201,22 +195,12 @@ class FirmAgent(ap.Agent):
lst_firm_connect = []
if self.is_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:
node_self = self.get_firm_network_node()
node_firm = firm.get_firm_network_node()
if self.model.firm_network.graph.\
has_edge(node_self, node_firm) or \
self.model.firm_network.graph.\
has_edge(node_firm, node_self):
lst_firm_connect.append(firm)
if len(lst_firm_connect) == 0:
# handling based on size or not