capacity init network

This commit is contained in:
2023-02-28 16:56:12 +08:00
parent c29a75177c
commit cf11c0c9bb
5 changed files with 71 additions and 26 deletions

21
firm.py
View File

@@ -29,12 +29,23 @@ class FirmAgent(ap.Agent):
# remove edge
# print(n1, n2, key, product_code)
self.firm_network.graph.remove_edge(n1, n2, key)
# remove customer up product
# remove customer up product if does not have alternative
customer = ap.AgentIter(self.model, n2).to_list()[0]
if remove_product not in customer.a_list_up_product_removed:
customer.a_list_up_product_removed.append(remove_product)
customer.dct_num_trial_up_product_removed[
remove_product] = 0
list_in_edges = list(
self.firm_network.graph.in_edges(n2,
keys=True,
data='Product'))
select_edges = [
edge for edge in list_in_edges
if edge[-1] == remove_product.code
]
if len(select_edges) == 0:
if remove_product not in \
customer.a_list_up_product_removed:
customer.a_list_up_product_removed.append(
remove_product)
customer.dct_num_trial_up_product_removed[
remove_product] = 0
# # disrupt customer
# customer = ap.AgentIter(self.model, n2).to_list()[0]