From a19860bdb204ade2b0b1dee8d9a73f79d0bf759f Mon Sep 17 00:00:00 2001 From: HaoYizhi Date: Sun, 18 Jun 2023 21:03:11 +0800 Subject: [PATCH] beautify --- __pycache__/firm.cpython-38.pyc | Bin 8204 -> 8198 bytes __pycache__/model.cpython-38.pyc | Bin 12818 -> 12880 bytes firm.py | 46 ++++++---------- model.py | 90 ++++--------------------------- 4 files changed, 26 insertions(+), 110 deletions(-) diff --git a/__pycache__/firm.cpython-38.pyc b/__pycache__/firm.cpython-38.pyc index 650066999aa2d639875b9aec5c79e404b63bd6d9..dac71807a11bd6320185666448b3be4278385176 100644 GIT binary patch delta 2383 zcma)7Z){Ul6o2=f5YPYxhcFa0nX&=830>)XjQ;QLdmGMl zE=WW)L@@V@F(z&w{IJ9ini*p>F@7-dJH~{(g!sjnm>519V^lonv}+koaZ7(a=iJ}9 z=iGD7y}dSkW!O0B_xmLHOGwwvGkZTVy4a%QUGkNsj5IAR%VjCin3e#W2>pZxVKZS1 zGBW{S1e_qqq0FYs4766KjkI>sI-E|@!lZRowQkaSs#=7!-tuYnh;(Mlf@ZR5=JYLX zE^A9$mL*eOmQCe-NGQ`(*5cC47a-}t{A{5Cqz==Q)$HG$ep9{7UV{X{qGjb9j6Vl5 zGP=ZFw!hO~ZUEmOY2BNZIZBn)F?kpBi#OzNnJY$>UU5k|5Db_pCsE=>Gm%P`lBu*a zzj|94V&W^MPx#ew78K{yA+|#Zbz)G_SpB~R<%&h|F=Opt(G`zu{9)*;VXc)-nx1k) zCU{kfOYj|9+O#aed8QT`uaaJF?37ISpgpVcTc(bzHS3xe=}o|DHT`fFZ>H_Myv&$* zt0By8i4PmDx9x!L@)&^Yi|5j|lPcy*2S>$mecad$)}!1DxWagk_(;DxvIU7s&MNSS zQPNTuis_WaJ3!%W2#=CESt?lt(`AmUmUz10a0ATICcX_R`^3E0YT1q=1>cKOOx*Eq z(}qE`OCsWnD^M6Q=^I?V;fp9wA}=cQATnD4R%HG-e7T8{`QRq?TLHg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KdWai%ej0)JMwA%@)o*fbyJ+M}u)Dcx zwY1=@eAWD;%#N=kUt>Q%fu0Yg(|4k${f)kp|7rLAD(!muXsFZZ@E{8OgcP6-c%1_L z40_ZTLeI<3aC8sF{zvrRG5R7!dT8`N)<@Ty`P#;5H#1mI3IVt2$8)A>S3QH<=jUwK z3s^wU?R}}Rh>kG?A_Q@vP6Iu|No>R6t z%?e&X#DMzVc@b>CkffEp>93hOg5EntvU6y$4@IiCUd9@Up*zbmY-`qbjT!Eg13pvv zGyxoluX4NW%&&XD2CW^zz-a_}I_gu@!_;IpVmYr=jA7~!Iht*xU#ei7dy@mps7HC1!uuBy3JACm zYKd1-I*-5+*1E2@!ezJ!!`H?4hQ_oJZBU!ip456ZMN{ck5Bm+dS-av@7kD##^ Q2l0pulK%=Ue(6sC1C{RW2LJ#7 diff --git a/__pycache__/model.cpython-38.pyc b/__pycache__/model.cpython-38.pyc index 432b0f5bd8709331e1e90725d825276af354ca07..a6d75f72fa729dd32cb46d4309add6e69a22c7e7 100644 GIT binary patch delta 3389 zcmZ`*YfN0%5kBYMyASro0t@W2=DCJtSukL1^Dyxv23*^TA0e@80^Z`>g>b>Z-o5yx zbGxzE3A;^jS3Xs%)^)V&Mr~rLQW~QEu9Pa3l2%IpRV%f>sz|Y{I<5MvmE+Ew#m2T$ zuI}8KIcH|RnKN_P8|oLT=M}fxLEta*;JWIb`;BK8r9FIMoHjJkYKSZ^uprv++K zqdwoj2%`lF!5EGCCRGBx#3WS?kbJYM6e#k;gh^V9YEiAKZB3#mg?OD*p9-l&C2vZq z6X}cuHd_m1giN(eN~XoMG9};2tjwyq=3z~1%ZCf3Kq<-5gr6x))*jirXC#OrYwfE1 zC8yFli!JPrnr>Isk%{CrP=pib*mJ*o>}mao}lsD(q@&WGhds#Gn9 z>K!H}?52}B0lPzM+d%F@zJwgOP2es8TuOWgfiov_3E=*GGy~Ndft04MXPvXebYtcj zCjfE>u*&{y1#=sHjOKS_Dz+48n)bt{oRr8Jea24aP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XyjI{L?+~XJHKw`fuQd z2{MUXAv-Y&WTg?)3zGr}GyTUk$jk8s)ke2^ z+y6kwY4KIZPC7_Md*^lMNw7HpZNW~74?Ex5bq$tm5y{gI*n1!w0lkzJ7%OoEie8um!K7p1YHWIjO)tGVSz^Af%&x@dr(a)O*4bsWSU|1vnK*R* zq8g7)>pGjgw5-Qd>Ln%DF4(qf9` zOslv$6NfOD;`0UYcR*?uJMUK6^lPz&xc=HAo9m_GFWu|@@8ND52_6NzjpUxV*3)>} z2dtggSEW^H+};Xrmp#HT?XYjsHa!zx(3f6kQ?Slkm!=og=@h#Ni%EOY|5b)XD9j?x Q8_eFro+ff$l=cq)4~eWj00000 diff --git a/firm.py b/firm.py index d6c38d0..b763afe 100644 --- a/firm.py +++ b/firm.py @@ -7,33 +7,23 @@ class FirmAgent(ap.Agent): self.firm_network = self.model.firm_network self.product_network = self.model.product_network + # self para self.code = code self.name = name 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_removed = ap.AgentList(self.model, []) + self.dct_prod_up_prod_stat = {} self.dct_prod_capacity = {} - # self.a_lst_up_product_removed = ap.AgentList(self.model, []) - # self.a_lst_product_disrupted = ap.AgentList(self.model, []) - self.a_lst_product_removed = ap.AgentList(self.model, []) - - self.dct_prod_up_prod_stat = {} - for prod in a_lst_product: - self.dct_prod_up_prod_stat[prod] = { - # Normal / Disrupted / Removed + time step - 'status': [('N', 0)], - # have or have no supply - 'supply': dict.fromkeys(prod.a_predecessors(), True) - } - # print(self.dct_prod_up_prod_stat) - + # para in trial self.dct_n_trial_up_prod_removed = {} self.dct_cand_alt_supply_up_prod_removed = {} self.dct_request_prod_from_firm = {} - # para + # external variable self.is_prf_size = self.model.is_prf_size self.is_prf_conn = bool(self.p.prf_conn) self.str_cap_limit_prob_type = str(self.p.cap_limit_prob_type) @@ -41,7 +31,16 @@ class FirmAgent(ap.Agent): self.flt_diff_new_conn = float(self.p.diff_new_conn) self.flt_crit_supplier = float(self.p.crit_supplier) - # init extra capacity + # init dct_prod_up_prod_stat (self para) + for prod in a_lst_product: + self.dct_prod_up_prod_stat[prod] = { + # Normal / Disrupted / Removed + time step + 'status': [('N', 0)], + # have or have no supply + 'supply': dict.fromkeys(prod.a_predecessors(), True) + } + + # init extra capacity (self para) for product in self.a_lst_product: # init extra capacity based on discrete uniform distribution assert self.str_cap_limit_prob_type in ['uniform', 'normal'], \ @@ -86,13 +85,7 @@ class FirmAgent(ap.Agent): if self.model.nprandom.choice([True, False], p=[prod_remove, 1 - prod_remove]): - # if remove_product not in \ - # customer.a_lst_up_product_removed: - # customer.a_lst_up_product_removed.append( - # remove_product) - # customer.dct_n_trial_up_prod_removed[ - # remove_product] = 0 - + customer.dct_n_trial_up_prod_removed[remove_product] = 0 for prod in customer.dct_prod_up_prod_stat.keys(): if remove_product in \ customer.dct_prod_up_prod_stat[ @@ -101,12 +94,8 @@ class FirmAgent(ap.Agent): prod]['supply'][remove_product] = False customer.dct_prod_up_prod_stat[ prod]['status'].append(('D', self.model.t)) - - customer.dct_n_trial_up_prod_removed[ - remove_product] = 0 print(self.name, remove_product.code, 'affect', customer.name, prod.code) - # print(customer.dct_prod_up_prod_stat) def seek_alt_supply(self, product): # para product is the product that self is seeking @@ -269,7 +258,6 @@ class FirmAgent(ap.Agent): ]) self.dct_prod_capacity[product] -= 1 self.dct_request_prod_from_firm[product].remove(down_firm) - # down_firm.a_lst_up_product_removed.remove(product) for prod in down_firm.dct_prod_up_prod_stat.keys(): if product in down_firm.dct_prod_up_prod_stat[ @@ -278,7 +266,6 @@ class FirmAgent(ap.Agent): prod]['supply'][product] = True down_firm.dct_prod_up_prod_stat[ prod]['status'].append(('N', self.model.t)) - # print(down_firm.dct_prod_up_prod_stat) del down_firm.dct_n_trial_up_prod_removed[product] del down_firm.dct_cand_alt_supply_up_prod_removed[product] @@ -296,7 +283,6 @@ class FirmAgent(ap.Agent): self.dct_n_trial_up_prod_removed = \ dict.fromkeys(self.dct_n_trial_up_prod_removed.keys(), 0) self.dct_cand_alt_supply_up_prod_removed = {} - # self.a_lst_up_product_removed = ap.AgentList(self.model, []) def get_firm_network_node(self): return self.firm_network.positions[self] diff --git a/model.py b/model.py index d14ac1f..845e240 100644 --- a/model.py +++ b/model.py @@ -10,12 +10,16 @@ import json class Model(ap.Model): def setup(self): + # self para self.sample = self.p.sample self.int_stop_times, self.int_stop_t = 0, None self.int_n_iter = int(self.p.n_iter) - + self.product_network = None # agentpy network + self.firm_network = None # agentpy network + self.firm_prod_network = None # networkx self.dct_lst_remove_firm_prod = self.p.dct_lst_init_remove_firm_prod + # external variable self.int_n_max_trial = int(self.p.n_max_trial) self.is_prf_size = bool(self.p.prf_size) self.flt_diff_remove = float(self.p.diff_remove) @@ -215,15 +219,9 @@ class Model(ap.Model): code in lst_product for code in self.a_lst_total_products.code ]) self.dct_lst_remove_firm_prod = t_dct - # self.dct_lst_disrupt_firm_prod = t_dct - - # # init output - # self.lst_dct_lst_remove_firm_prod = [] - # self.lst_dct_lst_disrupt_firm_prod = [] - - # self.dct_ts_dct_a_lst_remove = {} # set the initial firm product that are removed + print('\n', '=' * 20, 'step', self.t, '=' * 20) for firm, a_lst_product in self.dct_lst_remove_firm_prod.items(): for product in a_lst_product: assert product in firm.a_lst_product, \ @@ -333,24 +331,13 @@ class Model(ap.Model): # change capacity select_cand.dct_prod_capacity[di_supp_prod] -= 1 break - # nx.to_pandas_adjacency(G_Firm).to_csv('adj_g_firm_proactive.csv') + # draw network # self.draw_network() def update(self): self.a_lst_total_firms.clean_before_time_step() - # # output - # self.lst_dct_lst_remove_firm_prod.append( - # (self.t, self.dct_lst_remove_firm_prod)) - # self.lst_dct_lst_disrupt_firm_prod.append( - # (self.t, self.dct_lst_disrupt_firm_prod)) - - # # stop simulation if reached terminal number of iteration - # if self.t == self.int_n_iter or len( - # self.dct_lst_remove_firm_prod) == 0: - # self.int_stop_times = self.t - # self.stop() # reduce the size of removed firm for firm in self.a_lst_total_firms: @@ -364,6 +351,7 @@ class Model(ap.Model): firm.dct_prod_up_prod_stat[ prod]['status'].append(('N', self.t)) + # stop simulation if all firm returned to normal except inital removal if self.t > 0: for firm in self.a_lst_total_firms: for prod in firm.dct_prod_up_prod_stat.keys(): @@ -380,11 +368,6 @@ class Model(ap.Model): def step(self): print('\n', '=' * 20, 'step', self.t, '=' * 20) - # print( - # 'dct_list_remove_firm_prod', { - # key.name: value.code - # for key, value in self.dct_lst_remove_firm_prod.items() - # }) # remove_edge_to_cus_and_cus_up_prod for firm in self.a_lst_total_firms: @@ -400,8 +383,6 @@ class Model(ap.Model): 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() lst_seek_prod = [] for prod in firm.dct_prod_up_prod_stat.keys(): status = firm.dct_prod_up_prod_stat[prod]['status'][-1][0] @@ -432,16 +413,8 @@ class Model(ap.Model): # do not use: # self.a_lst_total_firms.dct_request_prod_from_firm = {} why? - # based on dct_prod_up_prod_stat - # update a_lst_product_disrupted / a_lst_product_removed - # update dct_lst_disrupt_firm_prod / dct_lst_remove_firm_prod - # self.dct_lst_remove_firm_prod = {} - # self.dct_lst_disrupt_firm_prod = {} + # turn disrupted firm into removed firm conditionally for firm in self.a_lst_total_firms: - # if len(firm.a_lst_up_product_removed) > 0: - # print(firm.name, 'a_lst_up_product_removed', [ - # product.code for product in firm.a_lst_up_product_removed - # ]) for product in firm.dct_prod_up_prod_stat.keys(): status = firm.dct_prod_up_prod_stat[product]['status'][-1][0] if status == 'D': @@ -450,28 +423,9 @@ class Model(ap.Model): sum([not stat for stat in firm.dct_prod_up_prod_stat[ product]['supply'].values()]) - # for product in firm.a_lst_product: - # n_up_product_removed = 0 - # for up_product_removed in firm.a_lst_up_product_removed: - # if product in up_product_removed.a_successors(): - # n_up_product_removed += 1 if n_up_product_removed == 0: continue else: - # # update a_lst_product_disrupted - # # update dct_lst_disrupt_firm_prod - # if product not in firm.a_lst_product_disrupted: - # firm.a_lst_product_disrupted.append(product) - # if firm in self.dct_lst_disrupt_firm_prod.keys(): - # self.dct_lst_disrupt_firm_prod[firm].append( - # product) - # else: - # self.dct_lst_disrupt_firm_prod[ - # firm] = ap.AgentList( - # self.model, [product]) - # update a_lst_product_removed - # update dct_list_remove_firm_prod - # mark disrupted firm as removed based conditionally lost_percent = n_up_product_removed / len( product.a_predecessors()) lst_size = self.a_lst_total_firms.size @@ -484,7 +438,7 @@ class Model(ap.Model): 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 + # damp prob prob_remove = prob_remove ** self.flt_diff_remove # sample prob prob_remove = self.nprandom.uniform( @@ -495,14 +449,6 @@ class Model(ap.Model): p=[prob_remove, 1 - prob_remove]): firm.a_lst_product_removed.append(product) - # if firm in self.dct_lst_remove_firm_prod.keys(): - # self.dct_lst_remove_firm_prod[firm].append( - # product) - # else: - # self.dct_lst_remove_firm_prod[ - # firm] = ap.AgentList( - # self.model, [product]) - firm.dct_prod_up_prod_stat[ product]['status'].append(('R', self.t)) print(firm.name, 'removed product: ', product.code) @@ -510,24 +456,8 @@ class Model(ap.Model): firm.dct_prod_up_prod_stat[ product]['status'].append(('N', self.t)) - # print( - # 'dct_list_remove_firm_prod', { - # key.name: value.code - # for key, value in self.dct_lst_remove_firm_prod.items() - # }) - def end(self): print('/' * 20, 'output', '/' * 20) - # print('dct_list_remove_firm_prod') - # for t, dct in self.lst_dct_lst_remove_firm_prod: - # for firm, a_lst_product in dct.items(): - # for product in a_lst_product: - # print(t, firm.name, product.code) - # print('dct_lst_disrupt_firm_prod') - # for t, dct in self.lst_dct_lst_disrupt_firm_prod: - # for firm, a_lst_product in dct.items(): - # for product in a_lst_product: - # print(t, firm.name, product.code) # qry_result = db_session.query(Result).filter_by(s_id=self.sample.id) # if qry_result.count() == 0: