model output
This commit is contained in:
44
model.py
44
model.py
@@ -171,6 +171,11 @@ class Model(ap.Model):
|
||||
for code in self.a_list_total_products.code
|
||||
])
|
||||
self.dct_list_remove_firm_prod = t_dct
|
||||
self.dct_list_disrupt_firm_prod = t_dct
|
||||
|
||||
# init output
|
||||
self.list_dct_list_remove_firm_prod = []
|
||||
self.list_dct_list_disrupt_firm_prod = []
|
||||
|
||||
# set the initial firm product that are removed
|
||||
for firm, a_list_product in self.dct_list_remove_firm_prod.items():
|
||||
@@ -184,6 +189,10 @@ class Model(ap.Model):
|
||||
|
||||
def update(self):
|
||||
self.a_list_total_firms.clean_before_time_step()
|
||||
# output
|
||||
self.list_dct_list_remove_firm_prod.append((self.t, self.dct_list_remove_firm_prod))
|
||||
self.list_dct_list_disrupt_firm_prod.append((self.t, self.dct_list_disrupt_firm_prod))
|
||||
|
||||
# stop simulation if reached terminal number of iteration
|
||||
if self.t == self.int_n_iter or len(
|
||||
self.dct_list_remove_firm_prod) == 0:
|
||||
@@ -235,8 +244,10 @@ class Model(ap.Model):
|
||||
# self.a_list_total_firms.dct_request_prod_from_firm = {} why?
|
||||
|
||||
# based on a_list_up_product_removed,
|
||||
# update a_list_product_disrupted / a_list_product_removed / dct_list_remove_firm_prod
|
||||
# update a_list_product_disrupted / a_list_product_removed
|
||||
# update dct_list_disrupt_firm_prod / dct_list_remove_firm_prod
|
||||
self.dct_list_remove_firm_prod = {}
|
||||
self.dct_list_disrupt_firm_prod = {}
|
||||
for firm in self.a_list_total_firms:
|
||||
if len(firm.a_list_up_product_removed) > 0:
|
||||
print(firm.name, 'a_list_up_product_removed', [product.code for product in firm.a_list_up_product_removed])
|
||||
@@ -248,9 +259,16 @@ class Model(ap.Model):
|
||||
if n_up_product_removed == 0:
|
||||
continue
|
||||
else:
|
||||
# update a_list_product_disrupted
|
||||
# update a_list_product_disrupted / dct_list_disrupt_firm_prod
|
||||
if product not in firm.a_list_product_disrupted:
|
||||
firm.a_list_product_disrupted.append(product)
|
||||
if firm in self.dct_list_disrupt_firm_prod.keys():
|
||||
self.dct_list_disrupt_firm_prod[firm].append(
|
||||
product)
|
||||
else:
|
||||
self.dct_list_disrupt_firm_prod[
|
||||
firm] = ap.AgentList(
|
||||
self.model, [product])
|
||||
# update a_list_product_removed / dct_list_remove_firm_prod
|
||||
lost_percent = n_up_product_removed / len(
|
||||
product.a_predecessors())
|
||||
@@ -259,9 +277,9 @@ class Model(ap.Model):
|
||||
1) / (max(list_revenue_log) -
|
||||
min(list_revenue_log) + 1)
|
||||
p_remove = 1 - std_size * (1 - lost_percent)
|
||||
# flag = self.nprandom.choice([1, 0],
|
||||
# p=[p_remove, 1 - p_remove])
|
||||
flag = 1
|
||||
flag = self.nprandom.choice([1, 0],
|
||||
p=[p_remove, 1 - p_remove])
|
||||
# flag = 1
|
||||
if flag == 1:
|
||||
firm.a_list_product_removed.append(product)
|
||||
# if firm in
|
||||
@@ -288,7 +306,17 @@ class Model(ap.Model):
|
||||
})
|
||||
|
||||
def end(self):
|
||||
pass
|
||||
print('/'*20, 'output', '/'*20)
|
||||
print('dct_list_remove_firm_prod')
|
||||
for t, dct in self.list_dct_list_remove_firm_prod:
|
||||
for firm, a_list_product in dct.items():
|
||||
for product in a_list_product:
|
||||
print(t, firm.name, product.code)
|
||||
print('dct_list_disrupt_firm_prod')
|
||||
for t, dct in self.list_dct_list_disrupt_firm_prod:
|
||||
for firm, a_list_product in dct.items():
|
||||
for product in a_list_product:
|
||||
print(t, firm.name, product.code)
|
||||
|
||||
def draw_network(self):
|
||||
import matplotlib.pyplot as plt
|
||||
@@ -324,5 +352,5 @@ class Model(ap.Model):
|
||||
plt.savefig("network.png")
|
||||
|
||||
|
||||
# model = Model(dct_sample_para)
|
||||
# model.run()
|
||||
model = Model(dct_sample_para)
|
||||
model.run()
|
||||
|
||||
Reference in New Issue
Block a user