From baf60ffd764bc5b17103102ee17ebadb0226804a Mon Sep 17 00:00:00 2001 From: HaoYizhi Date: Sun, 2 Jul 2023 13:00:13 +0800 Subject: [PATCH] remove disrupt to removed, 3 status (Normal / Affected / Removed) + size_stat --- __pycache__/controller_db.cpython-38.pyc | Bin 7932 -> 7909 bytes __pycache__/firm.cpython-38.pyc | Bin 8364 -> 8494 bytes __pycache__/model.cpython-38.pyc | Bin 13008 -> 12031 bytes __pycache__/orm.cpython-38.pyc | Bin 3762 -> 3728 bytes controller_db.py | 7 +-- firm.py | 30 ++++++---- model.py | 67 +++++------------------ oa_without_exp.csv | 4 +- orm.py | 1 - xv_without_exp.csv | 4 +- 10 files changed, 40 insertions(+), 73 deletions(-) diff --git a/__pycache__/controller_db.cpython-38.pyc b/__pycache__/controller_db.cpython-38.pyc index b57bb9a8a42da4c4fecde8ccaa961666aa3a0e6d..fb5de82c0c9c52188b757bf270b885d606819a6d 100644 GIT binary patch delta 646 zcmZ{hO=uHA6vutpG_^6=$wxP_?q&}aLV{2dtx$`_hy_6pLPgLXTtap=Tel|8F49UW zMXC_Ruf9`@#;6A`ibyXWOU?srxyMekRUREr=#{EMq&R?OuPwk&xq?z;d=B$#FQS# z7MLfsgAIlUm41g3op zs8X%j6^jSSvV@qLOg2dN`_5~&<5`@~;bv-5zU!Mz%dv#b!ISAJxQ9>EIrz}|k`4u+ ziEDZizYh(^Awbw|#-GtA_24svIYL1oFHP@vT+eU~ z+vH8MzVsWZssewpsIHCgS%cE~D*|mMALJ_OUJX(!exXwugFd{Vjl&8))JoYl#fJDY zMIgZ+Q1EdQ>%uL#`iK%xcXiI{K zk6=-%9#<`D>tiRPj62;3f=fkrS-H`Tg1Ayd(R(J+ofqzR&-~|{`yb|hocJ{%AC;ug z7QSALteE*dPvv8w!F+zHfA8qn=$O|Cy%7RJcmVfHc0#4He@o-1&i6sSog?^4+9$UZ zGjL67t8QRD*ivy&PJ@Oy`Jxmy?P|4T+74?jxai5#T>m3a3+yCLDI>5O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i%(h0T6`vHe$PG_<>S%F)ab?NR6(^Hz}gX8_HlFc$;fon zdUD2`{F_|Zl&zYh&3T&a9&(+ax8 diff --git a/__pycache__/orm.cpython-38.pyc b/__pycache__/orm.cpython-38.pyc index 61ffc60af34e5c6496224d7eda8023b50d5d18d9..e9f3b53cc7ccae6dfe356d2e13ac7cbec5b301e9 100644 GIT binary patch delta 242 zcmdlaJ3*E=l$V!_0SFol7o@OlzZEAw$}wiK2W)?TJ4=~UKK7+WS) zHiavNJB25Ox0g9eE`=|Jzl9-6esd>_H6x?@= zyDuZ7^W+B{t&H)L(>UKVdQT4H`eNb;Kj!vf^qOqI;{!CdmPeKqWK{Cx`8=wOo|}*Ih%*8u@ABF+ UdQO(*>)})skPr~!V&q~30N)2YQUCw| delta 273 zcmbOryGfQel$V!_0SGwR`%@e?@&+(7>P(JferGF|!jZz+%#^~C!rIFeC7sHe$_8c2 zAhBgrZyz{vg70@&gXz$^G1hj75_Va{DlPPv+zC0U906 rBg+ahE@g5pk1C_r=EXeXj6liVy!MP 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 == 'D' and ts != 0: + if status == 'A' and ts != 0: print("not stop because", firm.name, prod.code) break else: @@ -374,7 +376,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 == 'D' and ts == self.t-1: + if status == 'A' and ts == self.t-1: firm.remove_edge_to_cus_affect_cus_up_prod(prod) for n_trial in range(self.int_n_max_trial): @@ -387,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 != 'N': + if status == 'A': for supply in firm.dct_prod_up_prod_stat[ prod]['supply'].keys(): if not firm.dct_prod_up_prod_stat[ @@ -414,49 +416,6 @@ class Model(ap.Model): # do not use: # self.a_lst_total_firms.dct_request_prod_from_firm = {} why? - # turn affected firm into disrupted firm conditionally - for firm in self.a_lst_total_firms: - for product in firm.dct_prod_up_prod_stat.keys(): - status = firm.dct_prod_up_prod_stat[product]['status'][-1][0] - if status == 'A': - print(firm.name, 'affected product:', product.code) - n_up_product_lost = \ - sum([not stat for stat in - firm.dct_prod_up_prod_stat[ - product]['supply'].values()]) - if n_up_product_lost == 0: - continue - else: - lost_percent = n_up_product_lost / len( - product.a_predecessors()) - # firm (affected) + other firm (same product, normal) - lst_firm = [firm] - lst_firm += \ - [firm for firm - in self.a_lst_total_firms - if firm.is_prod_in_current_normal(product)] - lst_size = [firm.size for firm in lst_firm] - std_size = (firm.size - min(lst_size) + - 1) / (max(lst_size) - min(lst_size) + 1) - prob_disrupt = 1 - std_size * (1 - lost_percent) - # damp prob - prob_disrupt = prob_disrupt ** self.flt_diff_disrupt - # sample prob - prob_disrupt = self.nprandom.uniform( - prob_disrupt - 0.1, prob_disrupt + 0.1) - prob_disrupt = 1 if prob_disrupt > 1 else prob_disrupt - prob_disrupt = 0 if prob_disrupt < 0 else prob_disrupt - if self.nprandom.choice([True, False], - p=[prob_disrupt, - 1 - prob_disrupt]): - firm.dct_prod_up_prod_stat[ - product]['status'].append(('D', self.t)) - print(firm.name, 'disrupted product:', - product.code) - else: - firm.dct_prod_up_prod_stat[ - product]['status'].append(('N', self.t)) - def end(self): print('/' * 20, 'output', '/' * 20) diff --git a/oa_without_exp.csv b/oa_without_exp.csv index fcb75bf..66c1886 100644 --- a/oa_without_exp.csv +++ b/oa_without_exp.csv @@ -1,2 +1,2 @@ -X1,X2,X3,X4,X5,X6,X7,X8,X9,X10,X11 -0,0,0,0,0,0,0,0,0,0,0 +X1,X2,X3,X4,X5,X6,X7,X8,X9,X10 +0,0,0,0,0,0,0,0,0,0 diff --git a/orm.py b/orm.py index 39f82c2..a955bf1 100644 --- a/orm.py +++ b/orm.py @@ -61,7 +61,6 @@ class Experiment(Base): cap_limit_level = Column(DECIMAL(8, 4), nullable=False) diff_new_conn = Column(DECIMAL(8, 4), nullable=False) crit_supplier = Column(DECIMAL(8, 4), nullable=False) - diff_disrupt = Column(DECIMAL(8, 4), nullable=False) proactive_ratio = Column(DECIMAL(8, 4), nullable=False) remove_t = Column(Integer, nullable=False) netw_prf_n = Column(Integer, nullable=False) diff --git a/xv_without_exp.csv b/xv_without_exp.csv index a6fa87e..2f2b311 100644 --- a/xv_without_exp.csv +++ b/xv_without_exp.csv @@ -1,2 +1,2 @@ -n_max_trial,prf_size,prf_conn,cap_limit_prob_type,cap_limit_level,diff_new_conn,crit_supplier,diff_disrupt,proactive_ratio,remove_t,netw_prf_n -10,TRUE,TRUE,uniform,10,0.5,0.1,0.01,1,5,2 +n_max_trial,prf_size,prf_conn,cap_limit_prob_type,cap_limit_level,diff_new_conn,crit_supplier,proactive_ratio,remove_t,netw_prf_n +10,TRUE,TRUE,uniform,10,0.1,0.1,1,5,2