sample removal + seek connect first
This commit is contained in:
61
firm.py
61
firm.py
@@ -76,17 +76,44 @@ class FirmAgent(ap.Agent):
|
||||
])
|
||||
if not self.dct_cand_alt_supply_up_prod_removed[product]:
|
||||
continue
|
||||
# select based on size
|
||||
lst_size_damp = \
|
||||
[size ** self.flt_firm_pref_request for size in
|
||||
self.dct_cand_alt_supply_up_prod_removed[
|
||||
product].revenue_log]
|
||||
lst_prob = [size_damp / sum(lst_size_damp)
|
||||
for size_damp in lst_size_damp
|
||||
]
|
||||
select_alt_supply = self.model.nprandom.choice(
|
||||
self.dct_cand_alt_supply_up_prod_removed[product],
|
||||
p=lst_prob)
|
||||
# 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 len(lst_firm_connect) == 0:
|
||||
# select based on size
|
||||
lst_size_damp = \
|
||||
[size ** self.flt_firm_pref_request for size in
|
||||
self.dct_cand_alt_supply_up_prod_removed[
|
||||
product].revenue_log]
|
||||
lst_prob = [size_damp / sum(lst_size_damp)
|
||||
for size_damp in lst_size_damp]
|
||||
select_alt_supply = self.model.nprandom.choice(
|
||||
self.dct_cand_alt_supply_up_prod_removed[product],
|
||||
p=lst_prob)
|
||||
elif len(lst_firm_connect) > 0:
|
||||
# select based on size of firm that has connection
|
||||
lst_firm_size_damp = \
|
||||
[size ** self.flt_firm_pref_accept
|
||||
for size in lst_firm_connect.revenue_log]
|
||||
lst_prob = \
|
||||
[size_damp / sum(lst_firm_size_damp)
|
||||
for size_damp in lst_firm_size_damp]
|
||||
select_alt_supply = \
|
||||
self.model.nprandom.choice(lst_firm_connect,
|
||||
p=lst_prob)
|
||||
# print(
|
||||
# f"{self.name} selct alt supply for {product.code} "
|
||||
# f"from {select_alt_supply.name}"
|
||||
@@ -140,21 +167,19 @@ class FirmAgent(ap.Agent):
|
||||
if len(lst_firm_connect) == 0:
|
||||
# handling based on size
|
||||
lst_firm_size_damp = \
|
||||
[firm.revenue_log ** self.flt_firm_pref_accept
|
||||
for firm in lst_firm]
|
||||
[size ** self.flt_firm_pref_accept
|
||||
for size in lst_firm.revenue_log]
|
||||
lst_prob = \
|
||||
[size_damp / sum(lst_firm_size_damp)
|
||||
for size_damp in lst_firm_size_damp]
|
||||
select_customer = \
|
||||
self.model.nprandom.choice(lst_firm, p=lst_prob)
|
||||
self.accept_request(select_customer, product)
|
||||
elif len(lst_firm_connect) == 1:
|
||||
self.accept_request(lst_firm_connect[0], product)
|
||||
elif len(lst_firm_connect) > 1:
|
||||
elif len(lst_firm_connect) > 0:
|
||||
# handling based on size of firm that has connection
|
||||
lst_firm_size_damp = \
|
||||
[firm.revenue_log ** self.flt_firm_pref_accept
|
||||
for firm in lst_firm_connect]
|
||||
[size ** self.flt_firm_pref_accept
|
||||
for size in lst_firm_connect.revenue_log]
|
||||
lst_prob = \
|
||||
[size_damp / sum(lst_firm_size_damp)
|
||||
for size_damp in lst_firm_size_damp]
|
||||
|
||||
Reference in New Issue
Block a user