cap prob type and level

This commit is contained in:
2023-06-10 21:26:35 +08:00
parent 7a08a52f3f
commit 3b9252d93d
9 changed files with 35 additions and 16 deletions

View File

@@ -21,7 +21,8 @@ class Model(ap.Model):
self.int_n_max_trial = int(self.p.n_max_trial)
self.flt_netw_sply_prf_n = float(self.p.netw_sply_prf_n)
self.flt_netw_sply_prf_size = float(self.p.netw_sply_prf_size)
self.flt_cap_limit = int(self.p.cap_limit)
self.str_cap_limit_prob_type = str(self.p.cap_limit_prob_type)
self.flt_cap_limit_level = float(self.p.cap_limit_level)
self.flt_diff_remove = float(self.p.diff_remove)
self.proactive_ratio = float(self.p.proactive_ratio)
@@ -143,12 +144,25 @@ class Model(ap.Model):
code in attr['Product_Code']
for code in self.a_lst_total_products.code
]))
# init extra capacity based on discrete uniform distribution
for product in firm_agent.a_lst_product:
firm_agent.dct_prod_capacity[product] = \
self.nprandom.integers(firm_agent.revenue_log / 5,
firm_agent.revenue_log / 5 +
self.flt_cap_limit)
# init 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':
extra_cap_mean = \
firm_agent.revenue_log / self.flt_cap_limit_level
extra_cap = self.nprandom.integers(extra_cap_mean-2,
extra_cap_mean+2)
extra_cap = 0 if round(extra_cap) < 0 else round(extra_cap)
# print(firm_agent.name, extra_cap)
firm_agent.dct_prod_capacity[product] = extra_cap
elif self.str_cap_limit_prob_type == 'normal':
extra_cap_mean = \
firm_agent.revenue_log / self.flt_cap_limit_level
extra_cap = self.nprandom.normal(extra_cap_mean, 1)
extra_cap = 0 if round(extra_cap) < 0 else round(extra_cap)
# print(firm_agent.name, extra_cap)
firm_agent.dct_prod_capacity[product] = extra_cap
self.firm_network.add_agents([firm_agent], [ag_node])
self.a_lst_total_firms = ap.AgentList(self, self.firm_network.agents)
@@ -277,7 +291,7 @@ class Model(ap.Model):
break
# draw network
self.draw_network()
# self.draw_network()
def update(self):
self.a_lst_total_firms.clean_before_time_step()