diff --git a/__pycache__/controller_db.cpython-38.pyc b/__pycache__/controller_db.cpython-38.pyc index bf68348..7e581bf 100644 Binary files a/__pycache__/controller_db.cpython-38.pyc and b/__pycache__/controller_db.cpython-38.pyc differ diff --git a/__pycache__/firm.cpython-38.pyc b/__pycache__/firm.cpython-38.pyc index 319af18..2c2b235 100644 Binary files a/__pycache__/firm.cpython-38.pyc and b/__pycache__/firm.cpython-38.pyc differ diff --git a/__pycache__/model.cpython-38.pyc b/__pycache__/model.cpython-38.pyc index 57ddfca..8239885 100644 Binary files a/__pycache__/model.cpython-38.pyc and b/__pycache__/model.cpython-38.pyc differ 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,