add comments

This commit is contained in:
2023-08-22 23:22:30 -04:00
parent 1d66d8bb4e
commit b84ab810d0
3 changed files with 31 additions and 28 deletions

28
firm.py
View File

@@ -6,7 +6,7 @@ class FirmAgent(ap.Agent):
self.firm_network = self.model.firm_network
self.product_network = self.model.product_network
# self para
# self parameter
self.code = code
self.name = name
self.type_region = type_region
@@ -14,7 +14,7 @@ class FirmAgent(ap.Agent):
self.dct_prod_up_prod_stat = {}
self.dct_prod_capacity = {}
# para in trial
# parameter in trial
self.dct_n_trial_up_prod_disrupted = {}
self.dct_cand_alt_supp_up_prod_disrupted = {}
self.dct_request_prod_from_firm = {}
@@ -26,14 +26,14 @@ class FirmAgent(ap.Agent):
self.flt_cap_limit_level = float(self.p.cap_limit_level)
self.flt_diff_new_conn = float(self.p.diff_new_conn)
# init size_stat (self para)
# initialize size_stat (self parameter)
# (size, time step)
self.size_stat.append((revenue_log, 0))
# init dct_prod_up_prod_stat (self para)
# init dct_prod_up_prod_stat (self parameter)
for prod in a_lst_product:
self.dct_prod_up_prod_stat[prod] = {
# (Normal / Disrupted / Removed, time step)
# status: (Normal / Disrupted / Removed, time step)
'p_stat': [('N', 0)],
# supply for each component and respective disrupted supplier
# set_disrupt_firm is refreshed to empty at each update
@@ -43,9 +43,9 @@ class FirmAgent(ap.Agent):
# Note: do not use fromkeys as it's a shallow copy
}
# init extra capacity (self para)
# initialize extra capacity (self parameter)
for product in a_lst_product:
# init extra capacity based on discrete uniform distribution
# initialize extra capacity based on discrete uniform distribution
assert self.str_cap_limit_prob_type in ['uniform', 'normal'], \
"cap_limit_prob_type other than uniform, normal"
if self.str_cap_limit_prob_type == 'uniform':
@@ -63,7 +63,7 @@ class FirmAgent(ap.Agent):
self.dct_prod_capacity[product] = extra_cap
def remove_edge_to_cus(self, disrupted_prod):
# para disrupted_prod is the product that self got disrupted
# parameter disrupted_prod is the product that self got disrupted
lst_out_edge = list(
self.firm_network.graph.out_edges(
self.firm_network.positions[self], keys=True, data='Product'))
@@ -84,8 +84,8 @@ class FirmAgent(ap.Agent):
self.firm_network.graph.remove_edge(n1, n2, key)
def disrupt_cus_prod(self, prod, disrupted_up_prod):
# para prod is the product that has disrupted_up_prod
# para disrupted_up_prod is the product that
# parameter prod is the product that has disrupted_up_prod
# parameter disrupted_up_prod is the product that
# self's component exists disrupted supplier
num_lost = \
len(self.dct_prod_up_prod_stat[prod]['s_stat']
@@ -101,6 +101,8 @@ class FirmAgent(ap.Agent):
[firm.size_stat[-1][0] for firm in self.model.a_lst_total_firms]
std_size = (self.size_stat[-1][0] - min(lst_size) + 1) \
/ (max(lst_size) - min(lst_size) + 1)
# calculate probability of disruption
prob_disrupt = 1 - std_size * (1 - lost_percent)
if self.model.nprandom.choice([True, False],
p=[prob_disrupt,
@@ -117,7 +119,7 @@ class FirmAgent(ap.Agent):
# f"disrupted supplier of {disrupted_up_prod.code}")
def seek_alt_supply(self, product):
# para product is the product that self is seeking
# parameter product is the product that self is seeking
# print(f"{self.name} seek alt supply for {product.code}")
if self.dct_n_trial_up_prod_disrupted[
product] <= self.model.int_n_max_trial:
@@ -258,8 +260,8 @@ class FirmAgent(ap.Agent):
# )
def accept_request(self, down_firm, product):
# para product is the product that self is selling
# connected firm has no probability
# parameter product is the product that self is selling
# connected firm has no probability for accepting request
node_self = self.get_firm_network_node()
node_d_firm = down_firm.get_firm_network_node()
if self.model.firm_network.graph.has_edge(node_self, node_d_firm) or \