capacity init network
This commit is contained in:
54
model.py
54
model.py
@@ -71,20 +71,29 @@ class Model(ap.Model):
|
||||
G_Firm.nodes[succ_firm]['Revenue_Log']
|
||||
for succ_firm in list_succ_firms
|
||||
]
|
||||
# list_prob = [
|
||||
# (v - min(list_revenue_log) + 1) /
|
||||
# (max(list_revenue_log) - min(list_revenue_log) + 1)
|
||||
# for v in list_revenue_log
|
||||
# ]
|
||||
# list_flag = [
|
||||
# self.nprandom.choice([1, 0], p=[prob, 1 - prob])
|
||||
# for prob in list_prob
|
||||
# ]
|
||||
# # print(list(zip(list_succ_firms,list_flag,list_prob)))
|
||||
# list_added_edges = [(node, succ_firm, {
|
||||
# 'Product': product_code
|
||||
# }) for succ_firm, flag in zip(list_succ_firms, list_flag)
|
||||
# if flag == 1]
|
||||
list_prob = [
|
||||
(v - min(list_revenue_log) + 1) /
|
||||
(max(list_revenue_log) - min(list_revenue_log) + 1)
|
||||
for v in list_revenue_log
|
||||
size / sum(list_revenue_log)
|
||||
for size in list_revenue_log
|
||||
]
|
||||
list_flag = [
|
||||
self.nprandom.choice([1, 0], p=[prob, 1 - prob])
|
||||
for prob in list_prob
|
||||
]
|
||||
# print(list(zip(list_succ_firms,list_flag,list_prob)))
|
||||
succ_firm = self.nprandom.choice(list_succ_firms,
|
||||
p=list_prob)
|
||||
list_added_edges = [(node, succ_firm, {
|
||||
'Product': product_code
|
||||
}) for succ_firm, flag in zip(list_succ_firms, list_flag)
|
||||
if flag == 1]
|
||||
})]
|
||||
G_Firm.add_edges_from(list_added_edges)
|
||||
# print('-' * 20)
|
||||
|
||||
@@ -118,16 +127,19 @@ class Model(ap.Model):
|
||||
code in attr['Product_Code']
|
||||
for code in self.a_list_total_products.code
|
||||
]))
|
||||
# init capacity as the degree of out edges of a specific product
|
||||
list_out_edges = list(
|
||||
self.firm_network.graph.out_edges(ag_node,
|
||||
keys=True,
|
||||
data='Product'))
|
||||
# init capacity based on discrete uniform distribution
|
||||
# list_out_edges = list(
|
||||
# self.firm_network.graph.out_edges(ag_node,
|
||||
# keys=True,
|
||||
# data='Product'))
|
||||
# for product in firm_agent.a_list_product:
|
||||
# capacity = len([
|
||||
# edge for edge in list_out_edges if edge[-1] ==
|
||||
# product.code])
|
||||
# firm_agent.dct_prod_capacity[product] = capacity
|
||||
for product in firm_agent.a_list_product:
|
||||
capacity = len([
|
||||
edge for edge in list_out_edges if edge[-1] == product.code
|
||||
])
|
||||
firm_agent.dct_prod_capacity[product] = capacity
|
||||
firm_agent.dct_prod_capacity[product] = self.nprandom.integers(
|
||||
firm_agent.revenue_log / 5, firm_agent.revenue_log / 5 + 2)
|
||||
# print(firm_agent.name, firm_agent.dct_prod_capacity)
|
||||
|
||||
self.firm_network.add_agents([firm_agent], [ag_node])
|
||||
@@ -184,7 +196,7 @@ class Model(ap.Model):
|
||||
firm.remove_edge_to_cus_and_cus_up_prod(product)
|
||||
|
||||
for n_trial in range(self.int_n_max_trial):
|
||||
print('='*20, n_trial, '='*20)
|
||||
print('=' * 20, n_trial, '=' * 20)
|
||||
# seek_alt_supply
|
||||
for firm in self.a_list_total_firms:
|
||||
if len(firm.a_list_up_product_removed) > 0:
|
||||
@@ -241,6 +253,6 @@ class Model(ap.Model):
|
||||
|
||||
model = Model(dct_sample_para)
|
||||
model.setup()
|
||||
model.draw_network()
|
||||
model.update()
|
||||
model.step()
|
||||
# model.draw_network()
|
||||
|
||||
Reference in New Issue
Block a user