revenue reduce
This commit is contained in:
parent
b0b3cac73e
commit
1d8f319adb
Binary file not shown.
Binary file not shown.
15
firm.py
15
firm.py
|
@ -10,7 +10,8 @@ class FirmAgent(ap.Agent):
|
||||||
self.code = code
|
self.code = code
|
||||||
self.name = name
|
self.name = name
|
||||||
self.type_region = type_region
|
self.type_region = type_region
|
||||||
self.revenue_log = revenue_log
|
self.ori_size = revenue_log
|
||||||
|
self.size = revenue_log
|
||||||
self.a_lst_product = a_lst_product
|
self.a_lst_product = a_lst_product
|
||||||
self.dct_prod_capacity = {}
|
self.dct_prod_capacity = {}
|
||||||
|
|
||||||
|
@ -47,7 +48,7 @@ class FirmAgent(ap.Agent):
|
||||||
"cap_limit_prob_type other than uniform, normal"
|
"cap_limit_prob_type other than uniform, normal"
|
||||||
if self.str_cap_limit_prob_type == 'uniform':
|
if self.str_cap_limit_prob_type == 'uniform':
|
||||||
extra_cap_mean = \
|
extra_cap_mean = \
|
||||||
self.revenue_log / self.flt_cap_limit_level
|
self.size / self.flt_cap_limit_level
|
||||||
extra_cap = self.model.nprandom.integers(extra_cap_mean-2,
|
extra_cap = self.model.nprandom.integers(extra_cap_mean-2,
|
||||||
extra_cap_mean+2)
|
extra_cap_mean+2)
|
||||||
extra_cap = 0 if round(extra_cap) < 0 else round(extra_cap)
|
extra_cap = 0 if round(extra_cap) < 0 else round(extra_cap)
|
||||||
|
@ -55,7 +56,7 @@ class FirmAgent(ap.Agent):
|
||||||
self.dct_prod_capacity[product] = extra_cap
|
self.dct_prod_capacity[product] = extra_cap
|
||||||
elif self.str_cap_limit_prob_type == 'normal':
|
elif self.str_cap_limit_prob_type == 'normal':
|
||||||
extra_cap_mean = \
|
extra_cap_mean = \
|
||||||
self.revenue_log / self.flt_cap_limit_level
|
self.size / self.flt_cap_limit_level
|
||||||
extra_cap = self.model.nprandom.normal(extra_cap_mean, 1)
|
extra_cap = self.model.nprandom.normal(extra_cap_mean, 1)
|
||||||
extra_cap = 0 if round(extra_cap) < 0 else round(extra_cap)
|
extra_cap = 0 if round(extra_cap) < 0 else round(extra_cap)
|
||||||
# print(firm_agent.name, extra_cap)
|
# print(firm_agent.name, extra_cap)
|
||||||
|
@ -146,7 +147,7 @@ class FirmAgent(ap.Agent):
|
||||||
lst_size = \
|
lst_size = \
|
||||||
[size for size in
|
[size for size in
|
||||||
self.dct_cand_alt_supply_up_prod_removed[
|
self.dct_cand_alt_supply_up_prod_removed[
|
||||||
product].revenue_log]
|
product].size]
|
||||||
lst_prob = [size / sum(lst_size)
|
lst_prob = [size / sum(lst_size)
|
||||||
for size in lst_size]
|
for size in lst_size]
|
||||||
select_alt_supply = self.model.nprandom.choice(
|
select_alt_supply = self.model.nprandom.choice(
|
||||||
|
@ -159,7 +160,7 @@ class FirmAgent(ap.Agent):
|
||||||
# select based on size of connected firm or not
|
# select based on size of connected firm or not
|
||||||
if self.is_prf_size:
|
if self.is_prf_size:
|
||||||
lst_firm_size = \
|
lst_firm_size = \
|
||||||
[firm.revenue_log for firm in lst_firm_connect]
|
[firm.size for firm in lst_firm_connect]
|
||||||
lst_prob = \
|
lst_prob = \
|
||||||
[size / sum(lst_firm_size)
|
[size / sum(lst_firm_size)
|
||||||
for size in lst_firm_size]
|
for size in lst_firm_size]
|
||||||
|
@ -228,7 +229,7 @@ class FirmAgent(ap.Agent):
|
||||||
# handling based on size or not
|
# handling based on size or not
|
||||||
if self.is_prf_size:
|
if self.is_prf_size:
|
||||||
lst_firm_size = \
|
lst_firm_size = \
|
||||||
[firm.revenue_log for firm in lst_firm]
|
[firm.size for firm in lst_firm]
|
||||||
lst_prob = \
|
lst_prob = \
|
||||||
[size / sum(lst_firm_size)
|
[size / sum(lst_firm_size)
|
||||||
for size in lst_firm_size]
|
for size in lst_firm_size]
|
||||||
|
@ -243,7 +244,7 @@ class FirmAgent(ap.Agent):
|
||||||
# handling based on size of connected firm or not
|
# handling based on size of connected firm or not
|
||||||
if self.is_prf_size:
|
if self.is_prf_size:
|
||||||
lst_firm_size = \
|
lst_firm_size = \
|
||||||
[firm.revenue_log for firm in lst_firm_connect]
|
[firm.size for firm in lst_firm_connect]
|
||||||
lst_prob = \
|
lst_prob = \
|
||||||
[size / sum(lst_firm_size)
|
[size / sum(lst_firm_size)
|
||||||
for size in lst_firm_size]
|
for size in lst_firm_size]
|
||||||
|
|
20
model.py
20
model.py
|
@ -300,7 +300,7 @@ class Model(ap.Model):
|
||||||
for path in lst_shortest_path]) \
|
for path in lst_shortest_path]) \
|
||||||
/ len(lst_shortest_path)
|
/ len(lst_shortest_path)
|
||||||
drs = n2n_betweenness / \
|
drs = n2n_betweenness / \
|
||||||
(len(lst_cand) * di_supp_firm.revenue_log)
|
(len(lst_cand) * di_supp_firm.size)
|
||||||
dct_drs[di_supp_code] = drs
|
dct_drs[di_supp_code] = drs
|
||||||
dct_drs = dict(sorted(
|
dct_drs = dict(sorted(
|
||||||
dct_drs.items(), key=lambda kv: kv[1], reverse=True))
|
dct_drs.items(), key=lambda kv: kv[1], reverse=True))
|
||||||
|
@ -352,6 +352,18 @@ class Model(ap.Model):
|
||||||
# self.int_stop_times = self.t
|
# self.int_stop_times = self.t
|
||||||
# self.stop()
|
# self.stop()
|
||||||
|
|
||||||
|
# reduce the size of removed firm
|
||||||
|
for firm in self.a_lst_total_firms:
|
||||||
|
for prod in firm.dct_prod_up_prod_stat.keys():
|
||||||
|
status, ts = firm.dct_prod_up_prod_stat[prod]['status'][-1]
|
||||||
|
if status == 'R':
|
||||||
|
firm.size -= \
|
||||||
|
firm.ori_size / len(firm.a_lst_product) / self.drop_t
|
||||||
|
print(self.t, firm.name, prod.code, firm.size)
|
||||||
|
if self.t - ts + 1 == self.drop_t:
|
||||||
|
firm.dct_prod_up_prod_stat[
|
||||||
|
prod]['status'].append(('N', self.t))
|
||||||
|
|
||||||
if self.t > 0:
|
if self.t > 0:
|
||||||
for firm in self.a_lst_total_firms:
|
for firm in self.a_lst_total_firms:
|
||||||
for prod in firm.dct_prod_up_prod_stat.keys():
|
for prod in firm.dct_prod_up_prod_stat.keys():
|
||||||
|
@ -462,14 +474,14 @@ class Model(ap.Model):
|
||||||
# mark disrupted firm as removed based conditionally
|
# mark disrupted firm as removed based conditionally
|
||||||
lost_percent = n_up_product_removed / len(
|
lost_percent = n_up_product_removed / len(
|
||||||
product.a_predecessors())
|
product.a_predecessors())
|
||||||
lst_size = self.a_lst_total_firms.revenue_log
|
lst_size = self.a_lst_total_firms.size
|
||||||
lst_size = [firm.revenue_log for firm
|
lst_size = [firm.size for firm
|
||||||
in self.a_lst_total_firms
|
in self.a_lst_total_firms
|
||||||
if product in firm.a_lst_product
|
if product in firm.a_lst_product
|
||||||
and product
|
and product
|
||||||
not in firm.a_lst_product_removed
|
not in firm.a_lst_product_removed
|
||||||
]
|
]
|
||||||
std_size = (firm.revenue_log - min(lst_size) +
|
std_size = (firm.size - min(lst_size) +
|
||||||
1) / (max(lst_size) - min(lst_size) + 1)
|
1) / (max(lst_size) - min(lst_size) + 1)
|
||||||
prob_remove = 1 - std_size * (1 - lost_percent)
|
prob_remove = 1 - std_size * (1 - lost_percent)
|
||||||
# damp prod
|
# damp prod
|
||||||
|
|
19
test.ipynb
19
test.ipynb
|
@ -298,6 +298,25 @@
|
||||||
" break\n",
|
" break\n",
|
||||||
"\n"
|
"\n"
|
||||||
]
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 4,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"name": "stdout",
|
||||||
|
"output_type": "stream",
|
||||||
|
"text": [
|
||||||
|
"2.25\n",
|
||||||
|
"2.25\n"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"print(27 / (4 * 3))\n",
|
||||||
|
"print(27 / 4 / 3)"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"metadata": {
|
"metadata": {
|
||||||
|
|
Loading…
Reference in New Issue