debug
This commit is contained in:
37
firm.py
37
firm.py
@@ -35,13 +35,12 @@ class FirmAgent(ap.Agent):
|
||||
self.dct_prod_up_prod_stat[prod] = {
|
||||
# (Normal / Disrupted / Removed, time step)
|
||||
'p_stat': [('N', 0)],
|
||||
# have or have no supply
|
||||
'supply': dict.fromkeys(prod.a_predecessors(), True),
|
||||
# supply for each component and respective disrupted supplier
|
||||
# lst_disrupt_firm is refreshed to [] at each update
|
||||
's_stat': dict.fromkeys(prod.a_predecessors(),
|
||||
{'stat': True,
|
||||
'lst_disrupt_firm': []})
|
||||
# set_disrupt_firm is refreshed to empty at each update
|
||||
's_stat': {up_prod: {'stat': True,
|
||||
'set_disrupt_firm': set()}
|
||||
for up_prod in prod.a_predecessors()}
|
||||
# Note: do not use fromkeys as it's a shallow copy
|
||||
}
|
||||
|
||||
# init extra capacity (self para)
|
||||
@@ -76,14 +75,11 @@ class FirmAgent(ap.Agent):
|
||||
if disrupted_prod in \
|
||||
customer.dct_prod_up_prod_stat[
|
||||
prod]['s_stat'].keys():
|
||||
if self not in customer.dct_prod_up_prod_stat[
|
||||
prod]['s_stat'][disrupted_prod][
|
||||
'lst_disrupt_firm']:
|
||||
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}")
|
||||
customer.dct_prod_up_prod_stat[
|
||||
prod]['s_stat'][disrupted_prod][
|
||||
'set_disrupt_firm'].add(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)
|
||||
|
||||
@@ -93,7 +89,7 @@ class FirmAgent(ap.Agent):
|
||||
# self's component exists disrupted supplier
|
||||
num_lost = \
|
||||
len(self.dct_prod_up_prod_stat[prod]['s_stat']
|
||||
[disrupted_up_prod]['lst_disrupt_firm'])
|
||||
[disrupted_up_prod]['set_disrupt_firm'])
|
||||
num_remain = \
|
||||
len([u for u, _, _, d in
|
||||
self.firm_network.graph.in_edges(self.get_firm_network_node(),
|
||||
@@ -117,7 +113,8 @@ 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")
|
||||
print(f"{self.name}'s {prod.code} turn to D status due to "
|
||||
f"disrupted supplier of {disrupted_up_prod.code}")
|
||||
|
||||
def seek_alt_supply(self, product):
|
||||
# para product is the product that self is seeking
|
||||
@@ -283,9 +280,9 @@ class FirmAgent(ap.Agent):
|
||||
|
||||
for prod in down_firm.dct_prod_up_prod_stat.keys():
|
||||
if product in down_firm.dct_prod_up_prod_stat[
|
||||
prod]['supply'].keys():
|
||||
prod]['s_stat'].keys():
|
||||
down_firm.dct_prod_up_prod_stat[
|
||||
prod]['supply'][product] = True
|
||||
prod]['s_stat'][product]['stat'] = True
|
||||
down_firm.dct_prod_up_prod_stat[
|
||||
prod]['p_stat'].append(('N', self.model.t))
|
||||
del down_firm.dct_n_trial_up_prod_disrupted[product]
|
||||
@@ -317,10 +314,10 @@ class FirmAgent(ap.Agent):
|
||||
if ts != self.model.t:
|
||||
self.dct_prod_up_prod_stat[prod]['p_stat'].append(
|
||||
(status, self.model.t))
|
||||
# refresh lst_disrupt_firm
|
||||
# refresh set_disrupt_firm
|
||||
for up_prod in self.dct_prod_up_prod_stat[prod]['s_stat'].keys():
|
||||
self.dct_prod_up_prod_stat[prod][
|
||||
's_stat'][up_prod]['lst_disrupt_firm'] = []
|
||||
's_stat'][up_prod]['set_disrupt_firm'] = set()
|
||||
|
||||
def get_firm_network_node(self):
|
||||
return self.firm_network.positions[self]
|
||||
|
||||
Reference in New Issue
Block a user