This commit is contained in:
2023-06-18 21:03:11 +08:00
parent 1d8f319adb
commit a19860bdb2
4 changed files with 26 additions and 110 deletions

46
firm.py
View File

@@ -7,33 +7,23 @@ class FirmAgent(ap.Agent):
self.firm_network = self.model.firm_network
self.product_network = self.model.product_network
# self para
self.code = code
self.name = name
self.type_region = type_region
self.ori_size = revenue_log
self.size = revenue_log
self.a_lst_product = a_lst_product
self.a_lst_product_removed = ap.AgentList(self.model, [])
self.dct_prod_up_prod_stat = {}
self.dct_prod_capacity = {}
# self.a_lst_up_product_removed = ap.AgentList(self.model, [])
# self.a_lst_product_disrupted = ap.AgentList(self.model, [])
self.a_lst_product_removed = ap.AgentList(self.model, [])
self.dct_prod_up_prod_stat = {}
for prod in a_lst_product:
self.dct_prod_up_prod_stat[prod] = {
# Normal / Disrupted / Removed + time step
'status': [('N', 0)],
# have or have no supply
'supply': dict.fromkeys(prod.a_predecessors(), True)
}
# print(self.dct_prod_up_prod_stat)
# para in trial
self.dct_n_trial_up_prod_removed = {}
self.dct_cand_alt_supply_up_prod_removed = {}
self.dct_request_prod_from_firm = {}
# para
# external variable
self.is_prf_size = self.model.is_prf_size
self.is_prf_conn = bool(self.p.prf_conn)
self.str_cap_limit_prob_type = str(self.p.cap_limit_prob_type)
@@ -41,7 +31,16 @@ class FirmAgent(ap.Agent):
self.flt_diff_new_conn = float(self.p.diff_new_conn)
self.flt_crit_supplier = float(self.p.crit_supplier)
# init extra capacity
# init dct_prod_up_prod_stat (self para)
for prod in a_lst_product:
self.dct_prod_up_prod_stat[prod] = {
# Normal / Disrupted / Removed + time step
'status': [('N', 0)],
# have or have no supply
'supply': dict.fromkeys(prod.a_predecessors(), True)
}
# init extra capacity (self para)
for product in self.a_lst_product:
# init extra capacity based on discrete uniform distribution
assert self.str_cap_limit_prob_type in ['uniform', 'normal'], \
@@ -86,13 +85,7 @@ class FirmAgent(ap.Agent):
if self.model.nprandom.choice([True, False],
p=[prod_remove,
1 - prod_remove]):
# if remove_product not in \
# customer.a_lst_up_product_removed:
# customer.a_lst_up_product_removed.append(
# remove_product)
# customer.dct_n_trial_up_prod_removed[
# remove_product] = 0
customer.dct_n_trial_up_prod_removed[remove_product] = 0
for prod in customer.dct_prod_up_prod_stat.keys():
if remove_product in \
customer.dct_prod_up_prod_stat[
@@ -101,12 +94,8 @@ class FirmAgent(ap.Agent):
prod]['supply'][remove_product] = False
customer.dct_prod_up_prod_stat[
prod]['status'].append(('D', self.model.t))
customer.dct_n_trial_up_prod_removed[
remove_product] = 0
print(self.name, remove_product.code, 'affect',
customer.name, prod.code)
# print(customer.dct_prod_up_prod_stat)
def seek_alt_supply(self, product):
# para product is the product that self is seeking
@@ -269,7 +258,6 @@ class FirmAgent(ap.Agent):
])
self.dct_prod_capacity[product] -= 1
self.dct_request_prod_from_firm[product].remove(down_firm)
# down_firm.a_lst_up_product_removed.remove(product)
for prod in down_firm.dct_prod_up_prod_stat.keys():
if product in down_firm.dct_prod_up_prod_stat[
@@ -278,7 +266,6 @@ class FirmAgent(ap.Agent):
prod]['supply'][product] = True
down_firm.dct_prod_up_prod_stat[
prod]['status'].append(('N', self.model.t))
# print(down_firm.dct_prod_up_prod_stat)
del down_firm.dct_n_trial_up_prod_removed[product]
del down_firm.dct_cand_alt_supply_up_prod_removed[product]
@@ -296,7 +283,6 @@ class FirmAgent(ap.Agent):
self.dct_n_trial_up_prod_removed = \
dict.fromkeys(self.dct_n_trial_up_prod_removed.keys(), 0)
self.dct_cand_alt_supply_up_prod_removed = {}
# self.a_lst_up_product_removed = ap.AgentList(self.model, [])
def get_firm_network_node(self):
return self.firm_network.positions[self]