From 7255c3b0460217a971fc85c97a8b600ff22f4a87 Mon Sep 17 00:00:00 2001 From: HaoYizhi Date: Fri, 28 Jul 2023 15:29:16 +0800 Subject: [PATCH] test --- __pycache__/controller_db.cpython-38.pyc | Bin 7536 -> 7536 bytes __pycache__/firm.cpython-38.pyc | Bin 7974 -> 8866 bytes __pycache__/model.cpython-38.pyc | Bin 12880 -> 13401 bytes firm.py | 53 ++++++++++++----------- model.py | 28 ++++++------ 5 files changed, 41 insertions(+), 40 deletions(-) diff --git a/__pycache__/controller_db.cpython-38.pyc b/__pycache__/controller_db.cpython-38.pyc index bf6834881face60daa8f1e12710851693b02229b..7e581bfbd3e9bd78051ccdc97d95c3189df5d3a4 100644 GIT binary patch delta 19 Zcmexh^}&iOl$V!_0SJC&ZRARm1pquR1$qDg delta 19 Zcmexh^}&iOl$V!_0SH7gH*%%P0suC~1d{*& diff --git a/__pycache__/firm.cpython-38.pyc b/__pycache__/firm.cpython-38.pyc index 319af18b43a64cdf1d0e8aa0fb3fffff6abed02e..2c2b235b7340cc8e8be782eae167229f95c1c85b 100644 GIT binary patch delta 3230 zcma)8O>7&-6`q;>;qsr<4=KvBwXoG%^k417u3T7=TSZBo)RCRUaTC{yN^@5-R}>}A zu2hRynuS%w3Xl|P=1`!85wb-CxF`xFMSJL}P;Nfu5VQf0K?)Q-1P#!W(L#N1mSSbW zXhVQ+X5PGc@9q2fX5O3l#WRUl;_(Q9-$eOC>*TlIPbBp?jnN3}*=8(72dOxsAB>>H z)9`oyF0SgM^iQIppP{Sb_xkjt7x#&i_&Kpcen^gnZ#WvP!#>6FUTB?CQoROJ)M3q} zulTC3wG`luSmb4rkBH&W=ujfD}r^IuiYlgPWOBIi& z#k-+9`Xu^tSsXSlsj4!nh+D>4dRDw|Y|+!g3!guC8m;*>N33LyG!s?|*1D6NV=eH- z!&MqQOoN9#F!tP2(MRb`ulRHLGQBSjM?Rrb??iLG&x5HFnp1)3gb{vG9E%=2%AbUF zEp2)$yn=2{nXXsxR@{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|NGzS}J?L(KRZ!fOcMMEDVJAK1sg+n-Eaf@W1- rom*jZIfFrCMqNppFJ_IUtHwp_>g=9?)-eC1zg2z%%{jh*;MD&B3JRGp diff --git a/firm.py b/firm.py index c5e273b..395b553 100644 --- a/firm.py +++ b/firm.py @@ -55,14 +55,12 @@ class FirmAgent(ap.Agent): extra_cap = self.model.nprandom.integers(extra_cap_mean-2, extra_cap_mean+2) extra_cap = 0 if round(extra_cap) < 0 else round(extra_cap) - # print(firm_agent.name, extra_cap) self.dct_prod_capacity[product] = extra_cap elif self.str_cap_limit_prob_type == 'normal': extra_cap_mean = \ self.size_stat[0][0] / self.flt_cap_limit_level extra_cap = self.model.nprandom.normal(extra_cap_mean, 1) extra_cap = 0 if round(extra_cap) < 0 else round(extra_cap) - # print(firm_agent.name, extra_cap) self.dct_prod_capacity[product] = extra_cap def remove_edge_to_cus(self, disrupted_prod): @@ -84,6 +82,8 @@ class FirmAgent(ap.Agent): customer.dct_prod_up_prod_stat[ prod]['s_stat'][disrupted_prod][ 'lst_disrupt_firm'].append(self) + print(f"{self.name} disrupt {customer.name}'s " + f"{prod.code} due to {disrupted_prod.code}") # remove edge to customer self.firm_network.graph.remove_edge(n1, n2, key) @@ -117,10 +117,11 @@ class FirmAgent(ap.Agent): if status != 'D': self.dct_prod_up_prod_stat[ prod]['p_stat'].append(('D', self.model.t)) + print(f"{self.name}'s {prod.code} turn to D status") def seek_alt_supply(self, product): # para product is the product that self is seeking - # print(f"{self.name} seek alt supply for {product.code}") + print(f"{self.name} seek alt supply for {product.code}") if self.dct_n_trial_up_prod_disrupted[ product] <= self.model.int_n_max_trial: if self.dct_n_trial_up_prod_disrupted[product] == 0: @@ -173,10 +174,10 @@ class FirmAgent(ap.Agent): else: select_alt_supply = \ self.model.nprandom.choice(lst_firm_connect) - # print( - # f"{self.name} selct alt supply for {product.code} " - # f"from {select_alt_supply.name}" - # ) + print( + f"{self.name} selct alt supply for {product.code} " + f"from {select_alt_supply.name}" + ) assert select_alt_supply.is_prod_in_current_normal(product), \ f"{select_alt_supply} \ does not produce requested product {product}" @@ -189,17 +190,17 @@ class FirmAgent(ap.Agent): select_alt_supply.dct_request_prod_from_firm[product] = [ self ] - # print( - # select_alt_supply.name, 'dct_request_prod_from_firm', { - # key.code: [v.name for v in value] - # for key, value in - # select_alt_supply.dct_request_prod_from_firm.items() - # }) + print( + select_alt_supply.name, 'dct_request_prod_from_firm', { + key.code: [v.name for v in value] + for key, value in + select_alt_supply.dct_request_prod_from_firm.items() + }) self.dct_n_trial_up_prod_disrupted[product] += 1 def handle_request(self): - # print(self.name, 'handle_request') + print(self.name, 'handle_request') for product, lst_firm in self.dct_request_prod_from_firm.items(): if self.dct_prod_capacity[product] > 0: if len(lst_firm) == 0: @@ -254,10 +255,10 @@ class FirmAgent(ap.Agent): down_firm.dct_cand_alt_supp_up_prod_disrupted[ product].remove(self) - # print( - # f"{self.name} denied {product.code} request " - # f"from {down_firm.name} for lack of capacity" - # ) + print( + f"{self.name} denied {product.code} request " + f"from {down_firm.name} for lack of capacity" + ) def accept_request(self, down_firm, product): # para product is the product that self is selling @@ -290,17 +291,17 @@ class FirmAgent(ap.Agent): del down_firm.dct_n_trial_up_prod_disrupted[product] del down_firm.dct_cand_alt_supp_up_prod_disrupted[product] - # print( - # f"{self.name} accept {product.code} request " - # f"from {down_firm.name}" - # ) + print( + f"{self.name} accept {product.code} request " + f"from {down_firm.name}" + ) else: down_firm.dct_cand_alt_supp_up_prod_disrupted[product].remove(self) - # print( - # f"{self.name} denied {product.code} request " - # f"from {down_firm.name}" - # ) + print( + f"{self.name} denied {product.code} request " + f"from {down_firm.name}" + ) def clean_before_trial(self): self.dct_request_prod_from_firm = {} diff --git a/model.py b/model.py index 9f086c1..0a716b5 100644 --- a/model.py +++ b/model.py @@ -222,14 +222,14 @@ class Model(ap.Model): self.dct_lst_init_disrupt_firm_prod = t_dct # set the initial firm product that are disrupted - # print('\n', '=' * 20, 'step', self.t, '=' * 20) + print('\n', '=' * 20, 'step', self.t, '=' * 20) for firm, a_lst_product in self.dct_lst_init_disrupt_firm_prod.items(): for product in a_lst_product: 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]['p_stat'].append(('D', self.t)) - # print(f"initial disruption {firm.name} {product.code}") + print(f"initial disruption {firm.name} {product.code}") # proactive strategy # get all the firm prod affected @@ -331,10 +331,10 @@ class Model(ap.Model): 'Product': di_supp_prod.code }) ]) - # print(f"proactive add {select_cand.name} to " - # f"{pro_firm.name} " - # f"for {di_supp_node['Firm_Code']} " - # f"{di_supp_node['Product_Code']}") + print(f"proactive add {select_cand.name} to " + f"{pro_firm.name} " + f"for {di_supp_node['Firm_Code']} " + f"{di_supp_node['Product_Code']}") # change capacity select_cand.dct_prod_capacity[di_supp_prod] -= 1 break @@ -356,8 +356,8 @@ class Model(ap.Model): / len(firm.dct_prod_up_prod_stat.keys()) \ / self.remove_t firm.size_stat.append((size, self.t)) - # print(f'in ts {self.t}, reduce {firm.name} size ' - # f'to {firm.size_stat[-1][0]} due to {prod.code}') + print(f'in ts {self.t}, reduce {firm.name} size ' + f'to {firm.size_stat[-1][0]} due to {prod.code}') lst_is_disrupt = \ [stat == 'D' for stat, _ in firm.dct_prod_up_prod_stat[prod]['p_stat'] @@ -377,7 +377,7 @@ class Model(ap.Model): firm in self.dct_lst_init_disrupt_firm_prod.keys() \ and prod in self.dct_lst_init_disrupt_firm_prod[firm] if status == 'D' and not is_init: - # print("not stop because", firm.name, prod.code) + print("not stop because", firm.name, prod.code) break else: continue @@ -390,7 +390,7 @@ class Model(ap.Model): self.stop() def step(self): - # print('\n', '=' * 20, 'step', self.t, '=' * 20) + print('\n', '=' * 20, 'step', self.t, '=' * 20) # remove edge to customer and disrupt customer up product for firm in self.a_lst_total_firms: @@ -410,7 +410,7 @@ class Model(ap.Model): firm.disrupt_cus_prod(prod, up_prod) for n_trial in range(self.int_n_max_trial): - # print('=' * 10, 'trial', n_trial, '=' * 10) + print('=' * 10, 'trial', n_trial, '=' * 10) # seek_alt_supply # shuffle self.a_lst_total_firms self.a_lst_total_firms = self.a_lst_total_firms.shuffle() @@ -447,7 +447,7 @@ class Model(ap.Model): # self.a_lst_total_firms.dct_request_prod_from_firm = {} why? def end(self): - # print('/' * 20, 'output', '/' * 20) + print('/' * 20, 'output', '/' * 20) qry_result = db_session.query(Result).filter_by(s_id=self.sample.id) if qry_result.count() == 0: @@ -458,8 +458,8 @@ class Model(ap.Model): lst_is_normal = [stat == 'N' for stat, _ in dct_status_supply['p_stat']] if not all(lst_is_normal): - # print(f"{firm.name} {prod.code}:") - # print(dct_status_supply['p_stat']) + print(f"{firm.name} {prod.code}:") + print(dct_status_supply['p_stat']) for status, ts in dct_status_supply['p_stat']: db_r = Result(s_id=self.sample.id, id_firm=firm.code,