From 11abfa5ce88db4e835d136c86d46dd7c9034a01b Mon Sep 17 00:00:00 2001 From: HaoYizhi Date: Sun, 18 Jun 2023 22:12:47 +0800 Subject: [PATCH] drop firm attr a_lst_product/_disrupted --- __pycache__/firm.cpython-38.pyc | Bin 8205 -> 8364 bytes __pycache__/model.cpython-38.pyc | Bin 12888 -> 12801 bytes firm.py | 18 ++++++++++++------ model.py | 19 +++++++------------ 4 files changed, 19 insertions(+), 18 deletions(-) diff --git a/__pycache__/firm.cpython-38.pyc b/__pycache__/firm.cpython-38.pyc index 170a1685232b5b492d36f99d63c6dac38380488a..da4039eea97b8a364d7ded136608863536798863 100644 GIT binary patch delta 2604 zcma)8O>A355Z-;ZU*2pkU2>~|_APxv5IPruya04VHgo-#d%#2+pq^(M#_hn~x zW@mQh+ud9_^zmW;DWA{F;OBJUsu4S|(jWUO z8CGUVjZi1_5;haIl-Vqs^?`-Y_QSY!HgJi96tvq&3Xv4H+ezvmsk1J1k`gbjCAwSKXqhUXH0 z1Hyww%_`Tp*big0=-k8>HTcVB`>UJFn$gt75IfnjvZ&hwW&IL2v@8RUErwQ5Ynny9 zte4s3tX^({fZx!vdR7rQ+PG*8mh;}XSZU*8_tuhEl-Kzd+3Gs6@}BEk-s<>L$(&^; zOQLAZr)`<>?BLtvb5yO$1o+)P1rU-)|+7O0hLhn@{ z!{L*1QJ)FKaY)ggz|nSjN8idvR{FiS6|JmQ+b=82T>jYdkv!3*=Q_Y-8fY`+U*u(8 zWtZ79UsC4W6SXDc-099(wAo~)kW9}DVHWIUp(ygH+zmzS1$W1NE+g`BF19uT<2J>9 zfGm8L8$eZ*Rr#lHk9!CN`Gx;!nf6Ea9s)reMnH~>XAyh|djOyow5vwpXvNp$ZU5QG z>3c@v435^B$eaE_Sq?dkuSS zWiFcQW5Coq@YOcPl~wT+Nb+iM*I;dhT9_9>S@ZgDtamZi5a|+Vf{|`;$A^)yk`D@Z zUH%-%@(y_{xImkNYWu-0Uhe>3cu=6*^0(m8J-gA)M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X+(5k~e(@gYBO5|>>D*uQyxaX{@p#RdSC$;&(n!fUJBMaCcOtt6>bIsx`d;N9ikz;Y3?okkZdw#Xb07Q@Y5 zsp6Yr!Ix(3!sDN!zF+`e2!jF9P}tN;g+3M^_#b~jKUIUQiR@MNMl9{@!%3fEqOZ`(_*3_k|fiGls61aK1=M-l6Pf~p?erkQG z=eY;^-30RWAsKpTbDzh6`%&S0q{2?}t5Jc+FrqdXI$1w}X+^^Qj~chJ#?XUn{CsB( zBf#tPr%5GnRY8QKVx(lU|g*;Eka(UD065n)gb`2X%;@hs?>FrqU zX@oQa?mEY%^YaKCp@>lLuHK>y4;1(neE=HM_GrD@DQ%zDrMWbP<5NR%8prV(F1$dO gAU^^|N1>aU95%0%*wLa{xW_Zre!S=DctCd7-!2#Ze*gdg diff --git a/__pycache__/model.cpython-38.pyc b/__pycache__/model.cpython-38.pyc index 20f6e1428d1e4a79646d519f19a576e15e80f2fd..f1db79e11d636caa587f2acc8589d3c01a432d1f 100644 GIT binary patch delta 1295 zcmZuvUrbw77(d^+x3{+iO65-hsdS|<+5#=}bI+nTVL?;f|SVMLS>qY49>BY&s z%{DusxVY7wWHBz7+xVdIPcqX7A51VY#%RKWi9Q&fmY6*(naMOhXpG=F1vDn!gods7Kh zXq5G;@H6|cdI4`C=C8R53j3tyb#Sqs+N>-~Y&0a(@pCjq;>r2=nFUG{^G19=MdzkoVmCc4WzB$4TIQh&X5Ahy`^hs3 zZM<{?do@zaX6m{i!rrdC0s918v}G60y937uOEsCGK@Jf<*sQbzJ}kg7yIvpm!~}vO z5G1_m1R4;o)5Y)W_e-4{wd9Pk-QL2v?K5pm85{C!VllnpI*?8$sF6&~4^x_=>&-%=$gww~euPn6HUvo>-0L*4R>n^` zE0?M|Ot~HrxvmsFi>cTPHZgy0Xh2puv5CBCEU2J2>27f&3a1p%AlG>p>`rquwrTeXXPg^|ewTC|+SA%f$`_2BDH&4m3Ud3ZI!S3em*Hgqots zcsh9@LFd?7;B;U_yvO6*g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lJB zfYas#H`Id)GI)1n%GL0T&{{bkUV|srt)FBoN#Z9JVe*a2qqYvHevG)9N{#{%Z@Lob zr~$amyCct>_=mvlnAsw5;9mkWX`jGM{9^iF8t)P4R-~=&j(}E$_hmw<6DUYK(l&n> zY4ZixRdlm!LKs5qcFJAR7??aBy-(R0{(H16Gm+vx|EO~bWZoPL3ziJUHsC?!r`R6= zkN6K=E3nPA?%R}5?(X^Szzs|{?#wLW(@9=o$s}9izx8b3>s{~t#(r82s+aimk@DY} CWM^Ff diff --git a/firm.py b/firm.py index a88c479..8c2819f 100644 --- a/firm.py +++ b/firm.py @@ -13,8 +13,6 @@ class FirmAgent(ap.Agent): self.type_region = type_region self.ori_size = revenue_log self.size = revenue_log - self.a_lst_product = a_lst_product - self.a_lst_product_disrupted = ap.AgentList(self.model, []) self.dct_prod_up_prod_stat = {} self.dct_prod_capacity = {} @@ -41,7 +39,7 @@ class FirmAgent(ap.Agent): } # init extra capacity (self para) - for product in self.a_lst_product: + for product in 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" @@ -107,8 +105,7 @@ class FirmAgent(ap.Agent): # select a list of candidate firm that has the product self.dct_cand_alt_supp_up_prod_disrupted[product] = \ self.model.a_lst_total_firms.select([ - product in firm.a_lst_product - and product not in firm.a_lst_product_disrupted + firm.is_prod_in_current_normal(product) for firm in self.model.a_lst_total_firms ]) if self.dct_cand_alt_supp_up_prod_disrupted[product]: @@ -163,7 +160,7 @@ class FirmAgent(ap.Agent): f"{self.name} selct alt supply for {product.code} " f"from {select_alt_supply.name}" ) - assert product in select_alt_supply.a_lst_product, \ + assert select_alt_supply.is_prod_in_current_normal(product), \ f"{select_alt_supply} \ does not produce requested product {product}" @@ -286,3 +283,12 @@ class FirmAgent(ap.Agent): def get_firm_network_node(self): return self.firm_network.positions[self] + + def is_prod_in_current_normal(self, prod): + if prod in self.dct_prod_up_prod_stat.keys(): + if self.dct_prod_up_prod_stat[prod]['status'][-1][0] == 'N': + return True + else: + return False + else: + return False diff --git a/model.py b/model.py index a1dd4ac..49f551f 100644 --- a/model.py +++ b/model.py @@ -224,9 +224,8 @@ class Model(ap.Model): print('\n', '=' * 20, 'step', self.t, '=' * 20) for firm, a_lst_product in self.dct_lst_disrupt_firm_prod.items(): for product in a_lst_product: - assert product in firm.a_lst_product, \ + assert product in firm.dct_prod_up_prod_stat.keys(), \ f"product {product.code} not in firm {firm.code}" - firm.a_lst_product_disrupted.append(product) firm.dct_prod_up_prod_stat[ product]['status'].append(('D', self.t)) @@ -289,8 +288,7 @@ class Model(ap.Model): [firm.code == di_supp_node['Firm_Code'] for firm in self.a_lst_total_firms])[0] lst_cand = self.model.a_lst_total_firms.select([ - di_supp_prod in firm.a_lst_product and - di_supp_prod not in firm.a_lst_product_disrupted + firm.is_prod_in_current_normal(di_supp_prod) for firm in self.model.a_lst_total_firms ]) n2n_betweenness = \ @@ -311,8 +309,7 @@ class Model(ap.Model): for product in self.a_lst_total_products])[0] # find a dfferent firm can produce the same product lst_cand = self.model.a_lst_total_firms.select([ - di_supp_prod in firm.a_lst_product and - di_supp_prod not in firm.a_lst_product_disrupted + firm.is_prod_in_current_normal(di_supp_prod) and firm.code != di_supp_node['Firm_Code'] for firm in self.model.a_lst_total_firms ]) @@ -345,7 +342,9 @@ class Model(ap.Model): status, ts = firm.dct_prod_up_prod_stat[prod]['status'][-1] if status == 'D': firm.size -= \ - firm.ori_size / len(firm.a_lst_product) / self.remove_t + firm.ori_size \ + / len(firm.dct_prod_up_prod_stat.keys()) \ + / self.remove_t print(self.t, firm.name, prod.code, firm.size) if self.t - ts + 1 == self.remove_t: # turn disrupted firm into removed firm @@ -432,10 +431,7 @@ class Model(ap.Model): 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_disrupted - ] + if firm.is_prod_in_current_normal(product)] std_size = (firm.size - min(lst_size) + 1) / (max(lst_size) - min(lst_size) + 1) prob_disrupt = 1 - std_size * (1 - lost_percent) @@ -449,7 +445,6 @@ class Model(ap.Model): if self.nprandom.choice([True, False], p=[prob_disrupt, 1 - prob_disrupt]): - firm.a_lst_product_disrupted.append(product) firm.dct_prod_up_prod_stat[ product]['status'].append(('D', self.t)) print(firm.name, 'disrupted product:',