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

This commit is contained in:
HaoYizhi 2023-07-02 23:16:05 +08:00
parent 84828272e2
commit 098680f3aa
7 changed files with 25 additions and 11 deletions

Binary file not shown.

Binary file not shown.

View File

@ -82,8 +82,8 @@ class ControllerDB:
# list_dct = [{'140': ['1.4.5.1']}] # list_dct = [{'140': ['1.4.5.1']}]
# list_dct = [{'133': ['1.4.4.1']}] # list_dct = [{'133': ['1.4.4.1']}]
# list_dct = [{'2': ['1.1.3']}] # list_dct = [{'2': ['1.1.3']}]
# list_dct = [{'135': ['1.3.2.1']}] list_dct = [{'135': ['1.3.2.1']}]
list_dct = [{'79': ['2.1.3.4']}] # list_dct = [{'79': ['2.1.3.4']}]
# list_dct = [{'99': ['1.3.3']}] # list_dct = [{'99': ['1.3.3']}]
# list_dct = [{'41': ['1.4.5']}] # list_dct = [{'41': ['1.4.5']}]

15
firm.py
View File

@ -94,6 +94,9 @@ class FirmAgent(ap.Agent):
prod]['supply'].keys(): prod]['supply'].keys():
customer.dct_prod_up_prod_stat[ customer.dct_prod_up_prod_stat[
prod]['supply'][disrupted_prod] = False prod]['supply'][disrupted_prod] = False
status, _ = customer.dct_prod_up_prod_stat[
prod]['status'][-1]
if status != 'D':
customer.dct_prod_up_prod_stat[ customer.dct_prod_up_prod_stat[
prod]['status'].append(('D', self.model.t)) prod]['status'].append(('D', self.model.t))
print(self.name, disrupted_prod.code, 'disrupt', print(self.name, disrupted_prod.code, 'disrupt',
@ -294,17 +297,19 @@ class FirmAgent(ap.Agent):
def clean_before_trial(self): def clean_before_trial(self):
self.dct_request_prod_from_firm = {} 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): def clean_before_time_step(self):
self.dct_n_trial_up_prod_disrupted = \ self.dct_n_trial_up_prod_disrupted = \
dict.fromkeys(self.dct_n_trial_up_prod_disrupted.keys(), 0) dict.fromkeys(self.dct_n_trial_up_prod_disrupted.keys(), 0)
self.dct_cand_alt_supp_up_prod_disrupted = {} 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): def get_firm_network_node(self):
return self.firm_network.positions[self] return self.firm_network.positions[self]

View File

@ -311,9 +311,16 @@ class Model(ap.Model):
[product.code == di_supp_node['Product_Code'] [product.code == di_supp_node['Product_Code']
for product in self.a_lst_total_products])[0] for product in self.a_lst_total_products])[0]
# find a dfferent firm can produce the same product # 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([ lst_cand = self.model.a_lst_total_firms.select([
firm.is_prod_in_current_normal(di_supp_prod) 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 for firm in self.model.a_lst_total_firms
]) ])
if len(lst_cand) > 0: if len(lst_cand) > 0:
@ -388,6 +395,8 @@ class Model(ap.Model):
# remove edge to customer and disrupt customer up product # remove edge to customer and disrupt customer up product
for firm in self.a_lst_total_firms: for firm in self.a_lst_total_firms:
for prod in firm.dct_prod_up_prod_stat.keys(): 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] status, ts = firm.dct_prod_up_prod_stat[prod]['status'][-1]
if status == 'D' and ts == self.t-1: if status == 'D' and ts == self.t-1:
firm.remove_edge_to_cus_disrupt_cus_up_prod(prod) firm.remove_edge_to_cus_disrupt_cus_up_prod(prod)

View File

@ -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 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

1 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
2 10 TRUE TRUE uniform 10 0.5 0.1 0.01 1 5 2