diff --git a/__pycache__/controller_db.cpython-38.pyc b/__pycache__/controller_db.cpython-38.pyc index 84efc08..d75a0e9 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 c41df15..f35eab2 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 d3844ca..b7c8463 100644 Binary files a/__pycache__/model.cpython-38.pyc and b/__pycache__/model.cpython-38.pyc differ 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