diff --git a/__pycache__/firm.cpython-38.pyc b/__pycache__/firm.cpython-38.pyc index ebcd157..6500669 100644 Binary files a/__pycache__/firm.cpython-38.pyc and b/__pycache__/firm.cpython-38.pyc differ diff --git a/__pycache__/model.cpython-38.pyc b/__pycache__/model.cpython-38.pyc index d65f2ac..432b0f5 100644 Binary files a/__pycache__/model.cpython-38.pyc and b/__pycache__/model.cpython-38.pyc differ diff --git a/firm.py b/firm.py index ba91572..d6c38d0 100644 --- a/firm.py +++ b/firm.py @@ -10,7 +10,8 @@ class FirmAgent(ap.Agent): self.code = code self.name = name 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.dct_prod_capacity = {} @@ -47,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.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_mean+2) 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 elif self.str_cap_limit_prob_type == 'normal': 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 = 0 if round(extra_cap) < 0 else round(extra_cap) # print(firm_agent.name, extra_cap) @@ -146,7 +147,7 @@ class FirmAgent(ap.Agent): lst_size = \ [size for size in self.dct_cand_alt_supply_up_prod_removed[ - product].revenue_log] + product].size] lst_prob = [size / sum(lst_size) for size in lst_size] select_alt_supply = self.model.nprandom.choice( @@ -159,7 +160,7 @@ class FirmAgent(ap.Agent): # select based on size of connected firm or not if self.is_prf_size: lst_firm_size = \ - [firm.revenue_log for firm in lst_firm_connect] + [firm.size for firm in lst_firm_connect] lst_prob = \ [size / sum(lst_firm_size) for size in lst_firm_size] @@ -228,7 +229,7 @@ class FirmAgent(ap.Agent): # handling based on size or not if self.is_prf_size: lst_firm_size = \ - [firm.revenue_log for firm in lst_firm] + [firm.size for firm in lst_firm] lst_prob = \ [size / sum(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 if self.is_prf_size: lst_firm_size = \ - [firm.revenue_log for firm in lst_firm_connect] + [firm.size for firm in lst_firm_connect] lst_prob = \ [size / sum(lst_firm_size) for size in lst_firm_size] diff --git a/model.py b/model.py index 6c42b76..d14ac1f 100644 --- a/model.py +++ b/model.py @@ -300,7 +300,7 @@ class Model(ap.Model): for path in lst_shortest_path]) \ / len(lst_shortest_path) 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 = dict(sorted( 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.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: for firm in self.a_lst_total_firms: 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 lost_percent = n_up_product_removed / len( product.a_predecessors()) - lst_size = self.a_lst_total_firms.revenue_log - lst_size = [firm.revenue_log for firm + lst_size = self.a_lst_total_firms.size + lst_size = [firm.size for firm in self.a_lst_total_firms if product in firm.a_lst_product and product 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) prob_remove = 1 - std_size * (1 - lost_percent) # damp prod diff --git a/test.ipynb b/test.ipynb index 759c09e..83d5656 100644 --- a/test.ipynb +++ b/test.ipynb @@ -298,6 +298,25 @@ " break\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": {