remove disrupt to removed, 3 status (Normal / Affected / Removed) + size_stat

This commit is contained in:
2023-07-02 13:00:13 +08:00
parent fe58a2cf9a
commit baf60ffd76
10 changed files with 40 additions and 73 deletions

30
firm.py
View File

@@ -11,8 +11,7 @@ class FirmAgent(ap.Agent):
self.code = code
self.name = name
self.type_region = type_region
self.ori_size = revenue_log
self.size = revenue_log
self.size_stat = []
self.dct_prod_up_prod_stat = {}
self.dct_prod_capacity = {}
@@ -29,11 +28,15 @@ 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 size_stat (self para)
# (size, time step), ts -1 denotes initialization
self.size_stat.append((revenue_log, -1))
# init dct_prod_up_prod_stat (self para)
for prod in a_lst_product:
self.dct_prod_up_prod_stat[prod] = {
# (Normal / Affected / Disrupted / Removed, time step)
'status': [('N', 0)],
# (Normal / Affected / Removed, time step)
'status': [('N', -1)], # ts -1 denotes initialization
# have or have no supply
'supply': dict.fromkeys(prod.a_predecessors(), True)
}
@@ -45,7 +48,7 @@ class FirmAgent(ap.Agent):
"cap_limit_prob_type other than uniform, normal"
if self.str_cap_limit_prob_type == 'uniform':
extra_cap_mean = \
self.size / self.flt_cap_limit_level
self.size_stat[0][0] / self.flt_cap_limit_level
extra_cap = self.model.nprandom.integers(extra_cap_mean-2,
extra_cap_mean+2)
extra_cap = 0 if round(extra_cap) < 0 else round(extra_cap)
@@ -53,7 +56,7 @@ class FirmAgent(ap.Agent):
self.dct_prod_capacity[product] = extra_cap
elif self.str_cap_limit_prob_type == 'normal':
extra_cap_mean = \
self.size / self.flt_cap_limit_level
self.size_stat[0][0] / self.flt_cap_limit_level
extra_cap = self.model.nprandom.normal(extra_cap_mean, 1)
extra_cap = 0 if round(extra_cap) < 0 else round(extra_cap)
# print(firm_agent.name, extra_cap)
@@ -133,7 +136,7 @@ class FirmAgent(ap.Agent):
lst_size = \
[size for size in
self.dct_cand_alt_supp_up_prod_disrupted[
product].size]
product].size_stat[-1][0]]
lst_prob = [size / sum(lst_size)
for size in lst_size]
select_alt_supply = self.model.nprandom.choice(
@@ -146,7 +149,8 @@ class FirmAgent(ap.Agent):
# select based on size of connected firm or not
if self.is_prf_size:
lst_firm_size = \
[firm.size for firm in lst_firm_connect]
[firm.size_stat[-1][0]
for firm in lst_firm_connect]
lst_prob = \
[size / sum(lst_firm_size)
for size in lst_firm_size]
@@ -215,7 +219,7 @@ class FirmAgent(ap.Agent):
# handling based on size or not
if self.is_prf_size:
lst_firm_size = \
[firm.size for firm in lst_firm]
[firm.size_stat[-1][0] for firm in lst_firm]
lst_prob = \
[size / sum(lst_firm_size)
for size in lst_firm_size]
@@ -230,7 +234,8 @@ class FirmAgent(ap.Agent):
# handling based on size of connected firm or not
if self.is_prf_size:
lst_firm_size = \
[firm.size for firm in lst_firm_connect]
[firm.size_stat[-1][0]
for firm in lst_firm_connect]
lst_prob = \
[size / sum(lst_firm_size)
for size in lst_firm_size]
@@ -273,6 +278,11 @@ class FirmAgent(ap.Agent):
else:
down_firm.dct_cand_alt_supp_up_prod_disrupted[product].remove(self)
print(
f"{self.name} denied {product.code} request "
f"from {down_firm.name}"
)
def clean_before_trial(self):
self.dct_request_prod_from_firm = {}