From 098680f3aa1f0835cefb87bab3015bcb4ada0177 Mon Sep 17 00:00:00 2001 From: HaoYizhi Date: Sun, 2 Jul 2023 23:16:05 +0800 Subject: [PATCH] update the status of firm in clean_before_time_step + remove_edge_to_cus_disrupt_cus_up_prod update disrupted status instead of append + proactive find candidate that is not a current supplier for the same product --- __pycache__/controller_db.cpython-38.pyc | Bin 7908 -> 7909 bytes __pycache__/firm.cpython-38.pyc | Bin 8760 -> 8813 bytes __pycache__/model.cpython-38.pyc | Bin 13017 -> 13227 bytes controller_db.py | 4 ++-- firm.py | 19 ++++++++++++------- model.py | 11 ++++++++++- xv_without_exp.csv | 2 +- 7 files changed, 25 insertions(+), 11 deletions(-) diff --git a/__pycache__/controller_db.cpython-38.pyc b/__pycache__/controller_db.cpython-38.pyc index 84efc0861813012ebfd97bb19ca01540fb28f362..d75a0e94f5bd8ab6712ccc0731f685762478c54d 100644 GIT binary patch delta 693 zcmZ{hKWGzS7{>kXl508gSDVDtG@=wG9YSIdR49a!sdb7}Xe141a?-13lfHM=)T$Iw zp$MYBQx*JE1t*7+&C$Js4kEX>w2O72 zMeaop)sEx15W^aHT|7UPf=nd`FGNXDoGU7#<1|Jm`eG$s@U@*ksC8PrXG#qv!A$@W(!b^4GJW-tqU` z$BWp?3)zHWC5XO0(IIXOFG_+2jq(LCQ+93+GQbnaojmVU;1nAJHZImWPH8D+lud4)T zg%BWBNQjSH$~W{sK-pkphXDp8i-7?c5CcrCypN5_gomH*p1bosK7XD3GHJ}jV#Y4@ zl#4HoStC}_#!p`EIgvY_8_kV%SB#1K6N5*QErHvdjS-SQnC%ap_x%goe~XXuL1J=E?4{_4Ak ze2Yy)FZ`h&nTMz0&I>!XbZI{-hkye>88`?$0G=p#QR&uPyMEDfms*X$)pHbaa@ywi jL)%A#U$atMZqy`=Lx&ZwciD2=Eoye?6togQ%9j2B)&;8c diff --git a/__pycache__/firm.cpython-38.pyc b/__pycache__/firm.cpython-38.pyc index c41df1570e4b0100fed6d737ecf5bffda9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b}wCFH$2im@>T?YHMYUT&MOOx0CmuA<0XeulxD?E7_da%11DdLMf3Vd=g#@#e*}m`ng0#Uu21elyQDhpDT|?CLGF!oK4Nol-F7gNwi*E zYm17%+J?nwdmGJ^PqaTOQD^!6yNeRNBuaxJajZ+GXT^!GDf+Z{qpSJov&ixs!V3r) zgwqIVgl7;gAdDbjwi}M*{JcJm;wcp6tg)EUABSVqqpt~9_W&@Bc6ZX_5fR;C+KT%rPtobwXec$f>*T5m}nq>*>W!wt~?C0`XL%#x+ zO6VFmMH}@CVo!g2>?8;q(k$C>o?TpCF!Y->oW~275jI<+r^V&|Ln^ip$@*JT*5#GX4_nX<8>@YfrCP8{#IaH ze#5Nvx5TxA4$Wn=j-&L`9*sM3vSVX`<=x-o=D3(SV#UI15>I-^OjF0pvuVbJyVt!=&A5_|cg#Z8m diff --git a/controller_db.py b/controller_db.py index 9aba433..bb1b520 100644 --- a/controller_db.py +++ b/controller_db.py @@ -82,8 +82,8 @@ class ControllerDB: # list_dct = [{'140': ['1.4.5.1']}] # list_dct = [{'133': ['1.4.4.1']}] # list_dct = [{'2': ['1.1.3']}] - # list_dct = [{'135': ['1.3.2.1']}] - list_dct = [{'79': ['2.1.3.4']}] + list_dct = [{'135': ['1.3.2.1']}] + # list_dct = [{'79': ['2.1.3.4']}] # list_dct = [{'99': ['1.3.3']}] # list_dct = [{'41': ['1.4.5']}] diff --git a/firm.py b/firm.py index 5428e4a..10c1166 100644 --- a/firm.py +++ b/firm.py @@ -94,8 +94,11 @@ class FirmAgent(ap.Agent): prod]['supply'].keys(): customer.dct_prod_up_prod_stat[ prod]['supply'][disrupted_prod] = False - customer.dct_prod_up_prod_stat[ - prod]['status'].append(('D', self.model.t)) + status, _ = customer.dct_prod_up_prod_stat[ + prod]['status'][-1] + if status != 'D': + customer.dct_prod_up_prod_stat[ + prod]['status'].append(('D', self.model.t)) print(self.name, disrupted_prod.code, 'disrupt', customer.name, prod.code) @@ -294,17 +297,19 @@ class FirmAgent(ap.Agent): def clean_before_trial(self): self.dct_request_prod_from_firm = {} - for prod in self.dct_prod_up_prod_stat.keys(): - status, ts = self.dct_prod_up_prod_stat[prod]['status'][-1] - if ts != self.model.t: - self.dct_prod_up_prod_stat[prod]['status'].append( - (status, self.model.t)) def clean_before_time_step(self): self.dct_n_trial_up_prod_disrupted = \ dict.fromkeys(self.dct_n_trial_up_prod_disrupted.keys(), 0) self.dct_cand_alt_supp_up_prod_disrupted = {} + # update the status of firm + for prod in self.dct_prod_up_prod_stat.keys(): + status, ts = self.dct_prod_up_prod_stat[prod]['status'][-1] + if ts != self.model.t: + self.dct_prod_up_prod_stat[prod]['status'].append( + (status, self.model.t)) + def get_firm_network_node(self): return self.firm_network.positions[self] diff --git a/model.py b/model.py index 8ae7b8c..034487c 100644 --- a/model.py +++ b/model.py @@ -311,9 +311,16 @@ class Model(ap.Model): [product.code == di_supp_node['Product_Code'] for product in self.a_lst_total_products])[0] # find a dfferent firm can produce the same product + # and is not a current supplier for the same product + lst_current_supp_code = \ + [self.firm_prod_network.nodes[code]['Firm_Code'] + for code in self.firm_prod_network.predecessors( + pro_firm_prod_code) + if self.firm_prod_network.nodes[code][ + 'Product_Code'] == di_supp_prod.code] lst_cand = self.model.a_lst_total_firms.select([ firm.is_prod_in_current_normal(di_supp_prod) - and firm.code != di_supp_node['Firm_Code'] + and firm.code not in lst_current_supp_code for firm in self.model.a_lst_total_firms ]) if len(lst_cand) > 0: @@ -388,6 +395,8 @@ class Model(ap.Model): # 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(): + # repetition of disrupted firm that last for multiple ts is ok, + # as their edge has already been removed status, ts = firm.dct_prod_up_prod_stat[prod]['status'][-1] if status == 'D' and ts == self.t-1: firm.remove_edge_to_cus_disrupt_cus_up_prod(prod) diff --git a/xv_without_exp.csv b/xv_without_exp.csv index c53192d..027114d 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,proactive_ratio,remove_t,netw_prf_n -10,TRUE,TRUE,uniform,10,0.5,0.1,1,5,2 +10,TRUE,TRUE,uniform,10,0.5,0.01,1,5,2