From c348f3eb9cdb94255c3f6a01f11a9079fa8fd405 Mon Sep 17 00:00:00 2001 From: HaoYizhi Date: Sun, 2 Jul 2023 15:03:51 +0800 Subject: [PATCH] rename 3 status into (Normal / Disrupted / Removed) --- __pycache__/controller_db.cpython-38.pyc | Bin 7909 -> 7905 bytes __pycache__/firm.cpython-38.pyc | Bin 8494 -> 8626 bytes __pycache__/model.cpython-38.pyc | Bin 12031 -> 12035 bytes controller_db.py | 4 ++-- firm.py | 14 +++++++------- model.py | 18 +++++++++--------- 6 files changed, 18 insertions(+), 18 deletions(-) diff --git a/__pycache__/controller_db.cpython-38.pyc b/__pycache__/controller_db.cpython-38.pyc index fb5de82c0c9c52188b757bf270b885d606819a6d..9a63791e09a21cf9473085097e1957a9ae90c559 100644 GIT binary patch delta 44 ycmaEA`_PsxaG^vrYzsrb6E(r_Oi3{Dt+C4`A({?>Or?PTrzUMh6B~V=;lFMxV~7i(-Bb zCymiS; zWg{19A+;@}4&*&mvRzgI&axWSxJ5Ct)(ze+Yq>0;EKwQdqC#bY%`(lx|CMpsRsn0X zfXig+l57=L6mEGe!)On=hPi-u+66(q({m@J=44uI1BMz1e6*1=)t`F`p7wc;p2| zRrV`fIiUtoPso+3k2MHi)m-!?285`!N0(@&~Umv4@8Xl;WthP0;Q>7@pWeh@!{fLw(r=Ki8d`&Ccsi0CZx=^Q# z|HHK^vxId{DXWy!PomKA)o6L(ysOqit|mz+oTp^O7ZqcK&rqCA`!T#9JsQjLEs!z^ zYXkfSk8~YNNMTLvEt{^H3Cng#3m`ML#*>UHpuj*1YRVdsobT#Sgz|Xrr zf;%|UeFg4r5V!LYO5k_m?+DRQjdjBxkMs4X{GpHWMS-{&5AJzrI6Re`PI2d<<%m>a zK2?|xm=(_uJj6tjHnBsRVQI2tZqO=TCZj+*M8GDiH%}JM_MCX$Vg}okg}EV* z)~@;58;lVSn)J)1GU#b6#_&LQZ0$i$5lk^ldBqGFtn?;)A}>$3dw2Q7oIC~k2K5{r zRKUG`cVH0B{xx_SZ}y)7fj!$^gk5-Y+xPGs_B%ye28yCIC28id?mX*%$#}|m-8hWD HIOG2Uf&^bT delta 1175 zcmZWoU1%It6u#%q>}0apo!S3iH`x$tNE5BZ2SHnl-Ga3ce+ac~ld@>63`~AcEF&H%%=#aKC%c`Of+7 zopaB9uW)gnaVQw{Gx}OeS6sgLUE{J3l->`%M|pUbypBeo0SDt+vw(Z`T;%a`**exJ z9b0iqE6b&2yC(3rU<}*(uzvp$t(vm;gF+HVA>D7RzEWnm`H*1hw1w=$dMT`zDGt(Ff#)I*@ znZkB6!DiV+0;hwoz%pJ6ehF(BHb*gM?8KjpJE7gT&W8slLv+gv%wFt*@%iV$;I984JHerlS&Qj5Awd49}PapM97-xM^nLH2!Tqh(&V>Ud6T4 z3>?M}Lt}8Z_kCyx-~;?6d=lQrCn5#N;2V)u2xBI?4s-ZcbWD3vN`H!9M~glc_%)8> zu~ED|n?ezL%#@ufJCb%}&R2k!V%fQi^SlKu?mep9Em+ndGQnLt(3(Hxn*k+-e-isdx&WxKYNZ|ZqrRTnLh$53v+epTCgxme8Y8ags4YEM^7DvXz^bzk~jJQ diff --git a/__pycache__/model.cpython-38.pyc b/__pycache__/model.cpython-38.pyc index 4bab2c30d7747fbe18d9f0c9f251bf118b768f34..63a8eab1d3966360267348376da348c5520c1929 100644 GIT binary patch delta 131 zcmew#+Z@Lm%FD~e00dv97p8D*mM6>0}l42aF|?Sv9UQF5Y}w<2NJYnaS6+ g+8HlTj@Mqncx^L>PCFyxk;xNuPcte{j?r5T0GS~$9RL6T delta 135 zcmZpU`yb02%FD~e00f@Q3sX*S{i@?;J52aFYyIW?{_F5i4#<2NJY kg~_+I+8M7;PS#$*cxy9{PCFyxiOExRPcy1dPS9Hn059h;LjV8( diff --git a/controller_db.py b/controller_db.py index 5d1a776..550a28c 100644 --- a/controller_db.py +++ b/controller_db.py @@ -79,9 +79,9 @@ class ControllerDB: for product_code in row.index[row == 1].to_list(): dct = {code: [product_code]} list_dct.append(dct) - list_dct = [{'140': ['1.4.5.1']}] + # list_dct = [{'140': ['1.4.5.1']}] # list_dct = [{'133': ['1.4.4.1']}] - # list_dct = [{'2': ['1.1.3']}] + list_dct = [{'2': ['1.1.3']}] # list_dct = [{'135': ['1.3.2.1']}] # list_dct = [{'79': ['2.1.3.4']}] # list_dct = [{'99': ['1.3.3']}] diff --git a/firm.py b/firm.py index afe58c3..e7d97c8 100644 --- a/firm.py +++ b/firm.py @@ -35,7 +35,7 @@ class FirmAgent(ap.Agent): # init dct_prod_up_prod_stat (self para) for prod in a_lst_product: self.dct_prod_up_prod_stat[prod] = { - # (Normal / Affected / Removed, time step) + # (Normal / Disrupted / Removed, time step) 'status': [('N', -1)], # ts -1 denotes initialization # have or have no supply 'supply': dict.fromkeys(prod.a_predecessors(), True) @@ -62,8 +62,8 @@ class FirmAgent(ap.Agent): # print(firm_agent.name, extra_cap) self.dct_prod_capacity[product] = extra_cap - def remove_edge_to_cus_affect_cus_up_prod(self, disrupted_prod): - # para remove_product is the product that self got disrupted + def remove_edge_to_cus_disrupt_cus_up_prod(self, disrupted_prod): + # para disrupted_prod is the product that self got disrupted lst_out_edge = list( self.firm_network.graph.out_edges( self.firm_network.positions[self], keys=True, data='Product')) @@ -95,8 +95,8 @@ class FirmAgent(ap.Agent): customer.dct_prod_up_prod_stat[ prod]['supply'][disrupted_prod] = False customer.dct_prod_up_prod_stat[ - prod]['status'].append(('A', self.model.t)) - print(self.name, disrupted_prod.code, 'affect', + prod]['status'].append(('D', self.model.t)) + print(self.name, disrupted_prod.code, 'disrupt', customer.name, prod.code) def seek_alt_supply(self, product): @@ -134,9 +134,9 @@ class FirmAgent(ap.Agent): # select based on size or not if self.is_prf_size: lst_size = \ - [size for size in + [firm.size_stat[-1][0] for firm in self.dct_cand_alt_supp_up_prod_disrupted[ - product].size_stat[-1][0]] + product]] lst_prob = [size / sum(lst_size) for size in lst_size] select_alt_supply = self.model.nprandom.choice( diff --git a/model.py b/model.py index 99614b7..d6e6881 100644 --- a/model.py +++ b/model.py @@ -226,8 +226,8 @@ class Model(ap.Model): assert product in firm.dct_prod_up_prod_stat.keys(), \ f"product {product.code} not in firm {firm.code}" firm.dct_prod_up_prod_stat[ - product]['status'].append(('A', self.t)) - print(f"initial removal {firm.name} {product.code}") + product]['status'].append(('D', self.t)) + print(f"initial disruption {firm.name} {product.code}") # proactive strategy # get all the firm prod affected @@ -341,7 +341,7 @@ class Model(ap.Model): 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 == 'A': + if status == 'D': size = firm.size_stat[-1][0] - \ firm.size_stat[0][0] \ / len(firm.dct_prod_up_prod_stat.keys()) \ @@ -354,12 +354,12 @@ class Model(ap.Model): firm.dct_prod_up_prod_stat[ prod]['status'].append(('R', self.t)) - # stop simulation if any firm still in affected except inital removal + # stop simulation if any firm still in disrupted 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(): status, ts = firm.dct_prod_up_prod_stat[prod]['status'][-1] - if status == 'A' and ts != 0: + if status == 'D' and ts != 0: print("not stop because", firm.name, prod.code) break else: @@ -372,12 +372,12 @@ class Model(ap.Model): def step(self): print('\n', '=' * 20, 'step', self.t, '=' * 20) - # remove edge to customer and affect customer up product + # remove edge to customer and disrupt customer up product 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 == 'A' and ts == self.t-1: - firm.remove_edge_to_cus_affect_cus_up_prod(prod) + if status == 'D' and ts == self.t-1: + firm.remove_edge_to_cus_disrupt_cus_up_prod(prod) for n_trial in range(self.int_n_max_trial): print('=' * 10, 'trial', n_trial, '=' * 10) @@ -389,7 +389,7 @@ class Model(ap.Model): lst_seek_prod = [] for prod in firm.dct_prod_up_prod_stat.keys(): status = firm.dct_prod_up_prod_stat[prod]['status'][-1][0] - if status == 'A': + if status == 'D': for supply in firm.dct_prod_up_prod_stat[ prod]['supply'].keys(): if not firm.dct_prod_up_prod_stat[