rename 3 status into (Normal / Disrupted / Removed)
This commit is contained in:
parent
baf60ffd76
commit
c348f3eb9c
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -79,9 +79,9 @@ class ControllerDB:
|
|||
for product_code in row.index[row == 1].to_list():
|
||||
dct = {code: [product_code]}
|
||||
list_dct.append(dct)
|
||||
list_dct = [{'140': ['1.4.5.1']}]
|
||||
# list_dct = [{'140': ['1.4.5.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 = [{'79': ['2.1.3.4']}]
|
||||
# list_dct = [{'99': ['1.3.3']}]
|
||||
|
|
14
firm.py
14
firm.py
|
@ -35,7 +35,7 @@ class FirmAgent(ap.Agent):
|
|||
# init dct_prod_up_prod_stat (self para)
|
||||
for prod in a_lst_product:
|
||||
self.dct_prod_up_prod_stat[prod] = {
|
||||
# (Normal / Affected / Removed, time step)
|
||||
# (Normal / Disrupted / Removed, time step)
|
||||
'status': [('N', -1)], # ts -1 denotes initialization
|
||||
# have or have no supply
|
||||
'supply': dict.fromkeys(prod.a_predecessors(), True)
|
||||
|
@ -62,8 +62,8 @@ class FirmAgent(ap.Agent):
|
|||
# print(firm_agent.name, extra_cap)
|
||||
self.dct_prod_capacity[product] = extra_cap
|
||||
|
||||
def remove_edge_to_cus_affect_cus_up_prod(self, disrupted_prod):
|
||||
# para remove_product is the product that self got disrupted
|
||||
def remove_edge_to_cus_disrupt_cus_up_prod(self, disrupted_prod):
|
||||
# para disrupted_prod is the product that self got disrupted
|
||||
lst_out_edge = list(
|
||||
self.firm_network.graph.out_edges(
|
||||
self.firm_network.positions[self], keys=True, data='Product'))
|
||||
|
@ -95,8 +95,8 @@ class FirmAgent(ap.Agent):
|
|||
customer.dct_prod_up_prod_stat[
|
||||
prod]['supply'][disrupted_prod] = False
|
||||
customer.dct_prod_up_prod_stat[
|
||||
prod]['status'].append(('A', self.model.t))
|
||||
print(self.name, disrupted_prod.code, 'affect',
|
||||
prod]['status'].append(('D', self.model.t))
|
||||
print(self.name, disrupted_prod.code, 'disrupt',
|
||||
customer.name, prod.code)
|
||||
|
||||
def seek_alt_supply(self, product):
|
||||
|
@ -134,9 +134,9 @@ class FirmAgent(ap.Agent):
|
|||
# select based on size or not
|
||||
if self.is_prf_size:
|
||||
lst_size = \
|
||||
[size for size in
|
||||
[firm.size_stat[-1][0] for firm in
|
||||
self.dct_cand_alt_supp_up_prod_disrupted[
|
||||
product].size_stat[-1][0]]
|
||||
product]]
|
||||
lst_prob = [size / sum(lst_size)
|
||||
for size in lst_size]
|
||||
select_alt_supply = self.model.nprandom.choice(
|
||||
|
|
18
model.py
18
model.py
|
@ -226,8 +226,8 @@ class Model(ap.Model):
|
|||
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]['status'].append(('A', self.t))
|
||||
print(f"initial removal {firm.name} {product.code}")
|
||||
product]['status'].append(('D', self.t))
|
||||
print(f"initial disruption {firm.name} {product.code}")
|
||||
|
||||
# proactive strategy
|
||||
# get all the firm prod affected
|
||||
|
@ -341,7 +341,7 @@ class Model(ap.Model):
|
|||
for firm in self.a_lst_total_firms:
|
||||
for prod in firm.dct_prod_up_prod_stat.keys():
|
||||
status, ts = firm.dct_prod_up_prod_stat[prod]['status'][-1]
|
||||
if status == 'A':
|
||||
if status == 'D':
|
||||
size = firm.size_stat[-1][0] - \
|
||||
firm.size_stat[0][0] \
|
||||
/ len(firm.dct_prod_up_prod_stat.keys()) \
|
||||
|
@ -354,12 +354,12 @@ class Model(ap.Model):
|
|||
firm.dct_prod_up_prod_stat[
|
||||
prod]['status'].append(('R', self.t))
|
||||
|
||||
# stop simulation if any firm still in affected except inital removal
|
||||
# stop simulation if any firm still in disrupted except inital removal
|
||||
if self.t > 0:
|
||||
for firm in self.a_lst_total_firms:
|
||||
for prod in firm.dct_prod_up_prod_stat.keys():
|
||||
status, ts = firm.dct_prod_up_prod_stat[prod]['status'][-1]
|
||||
if status == 'A' and ts != 0:
|
||||
if status == 'D' and ts != 0:
|
||||
print("not stop because", firm.name, prod.code)
|
||||
break
|
||||
else:
|
||||
|
@ -372,12 +372,12 @@ class Model(ap.Model):
|
|||
def step(self):
|
||||
print('\n', '=' * 20, 'step', self.t, '=' * 20)
|
||||
|
||||
# remove edge to customer and affect customer up product
|
||||
# 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():
|
||||
status, ts = firm.dct_prod_up_prod_stat[prod]['status'][-1]
|
||||
if status == 'A' and ts == self.t-1:
|
||||
firm.remove_edge_to_cus_affect_cus_up_prod(prod)
|
||||
if status == 'D' and ts == self.t-1:
|
||||
firm.remove_edge_to_cus_disrupt_cus_up_prod(prod)
|
||||
|
||||
for n_trial in range(self.int_n_max_trial):
|
||||
print('=' * 10, 'trial', n_trial, '=' * 10)
|
||||
|
@ -389,7 +389,7 @@ class Model(ap.Model):
|
|||
lst_seek_prod = []
|
||||
for prod in firm.dct_prod_up_prod_stat.keys():
|
||||
status = firm.dct_prod_up_prod_stat[prod]['status'][-1][0]
|
||||
if status == 'A':
|
||||
if status == 'D':
|
||||
for supply in firm.dct_prod_up_prod_stat[
|
||||
prod]['supply'].keys():
|
||||
if not firm.dct_prod_up_prod_stat[
|
||||
|
|
Loading…
Reference in New Issue