init extra capacity in firm.py
This commit is contained in:
27
model.py
27
model.py
@@ -18,10 +18,9 @@ class Model(ap.Model):
|
||||
|
||||
self.int_n_max_trial = int(self.p.n_max_trial)
|
||||
self.is_prf_size = bool(self.p.prf_size)
|
||||
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)
|
||||
self.drop_t = int(self.p.drop_t)
|
||||
self.int_netw_prf_n = int(self.p.netw_prf_n)
|
||||
|
||||
# init graph bom
|
||||
@@ -203,25 +202,6 @@ class Model(ap.Model):
|
||||
code in attr['Product_Code']
|
||||
for code in self.a_lst_total_products.code
|
||||
]))
|
||||
for product in firm_agent.a_lst_product:
|
||||
# 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)
|
||||
@@ -406,6 +386,7 @@ class Model(ap.Model):
|
||||
# seek_alt_supply
|
||||
# shuffle self.a_lst_total_firms
|
||||
self.a_lst_total_firms = self.a_lst_total_firms.shuffle()
|
||||
is_stop_trial = True
|
||||
for firm in self.a_lst_total_firms:
|
||||
# if len(firm.a_lst_up_product_removed) > 0:
|
||||
# firm.seek_alt_supply()
|
||||
@@ -420,8 +401,12 @@ class Model(ap.Model):
|
||||
lst_seek_prod.append(supply)
|
||||
# commmon supply only seek once
|
||||
lst_seek_prod = list(set(lst_seek_prod))
|
||||
if len(lst_seek_prod) > 0:
|
||||
is_stop_trial = False
|
||||
for supply in lst_seek_prod:
|
||||
firm.seek_alt_supply(supply)
|
||||
if is_stop_trial:
|
||||
break
|
||||
|
||||
# handle_request
|
||||
# shuffle self.a_lst_total_firms
|
||||
|
||||
Reference in New Issue
Block a user