experiments in model and firm py
This commit is contained in:
46
firm.py
46
firm.py
@@ -22,6 +22,12 @@ class FirmAgent(ap.Agent):
|
||||
self.dct_cand_alt_supply_up_prod_removed = {}
|
||||
self.dct_request_prod_from_firm = {}
|
||||
|
||||
# para
|
||||
self.flt_crit_supplier = float(self.p.crit_supplier)
|
||||
self.flt_firm_pref_request = float(self.p.firm_pref_request)
|
||||
self.flt_firm_pref_accept = float(self.p.firm_pref_accept)
|
||||
self.flt_diff_new_conn = float(self.p.diff_new_conn)
|
||||
|
||||
def remove_edge_to_cus_remove_cus_up_prod(self, remove_product):
|
||||
lst_out_edge = list(
|
||||
self.firm_network.graph.out_edges(
|
||||
@@ -41,7 +47,8 @@ class FirmAgent(ap.Agent):
|
||||
edge for edge in lst_in_edge
|
||||
if edge[-1] == remove_product.code
|
||||
]
|
||||
prod_remove = math.exp(-1 * len(lst_select_in_edge))
|
||||
prod_remove = math.exp(-1 * self.flt_crit_supplier *
|
||||
len(lst_select_in_edge))
|
||||
if self.model.nprandom.choice([True, False],
|
||||
p=[prod_remove,
|
||||
1 - prod_remove]):
|
||||
@@ -70,13 +77,13 @@ class FirmAgent(ap.Agent):
|
||||
if not self.dct_cand_alt_supply_up_prod_removed[product]:
|
||||
continue
|
||||
# select based on size
|
||||
lst_prob = [
|
||||
size /
|
||||
sum(self.dct_cand_alt_supply_up_prod_removed[
|
||||
product].revenue_log)
|
||||
for size in self.dct_cand_alt_supply_up_prod_removed[
|
||||
product].revenue_log
|
||||
]
|
||||
lst_size_damp = \
|
||||
[size ** self.flt_firm_pref_request for size in
|
||||
self.dct_cand_alt_supply_up_prod_removed[
|
||||
product].revenue_log]
|
||||
lst_prob = [size_damp / sum(lst_size_damp)
|
||||
for size_damp in lst_size_damp
|
||||
]
|
||||
select_alt_supply = self.model.nprandom.choice(
|
||||
self.dct_cand_alt_supply_up_prod_removed[product],
|
||||
p=lst_prob)
|
||||
@@ -132,10 +139,12 @@ class FirmAgent(ap.Agent):
|
||||
lst_firm_connect.append(firm)
|
||||
if len(lst_firm_connect) == 0:
|
||||
# handling based on size
|
||||
lst_firm_size = [firm.revenue_log for firm in lst_firm]
|
||||
lst_prob = [
|
||||
size / sum(lst_firm_size) for size in lst_firm_size
|
||||
]
|
||||
lst_firm_size_damp = \
|
||||
[firm.revenue_log ** self.flt_firm_pref_accept
|
||||
for firm in lst_firm]
|
||||
lst_prob = \
|
||||
[size_damp / sum(lst_firm_size_damp)
|
||||
for size_damp in lst_firm_size_damp]
|
||||
select_customer = \
|
||||
self.model.nprandom.choice(lst_firm, p=lst_prob)
|
||||
self.accept_request(select_customer, product)
|
||||
@@ -143,11 +152,12 @@ class FirmAgent(ap.Agent):
|
||||
self.accept_request(lst_firm_connect[0], product)
|
||||
elif len(lst_firm_connect) > 1:
|
||||
# handling based on size of firm that has connection
|
||||
lst_firm_size = [
|
||||
firm.revenue_log for firm in lst_firm_connect]
|
||||
lst_prob = [
|
||||
size / sum(lst_firm_size) for size in lst_firm_size
|
||||
]
|
||||
lst_firm_size_damp = \
|
||||
[firm.revenue_log ** self.flt_firm_pref_accept
|
||||
for firm in lst_firm_connect]
|
||||
lst_prob = \
|
||||
[size_damp / sum(lst_firm_size_damp)
|
||||
for size_damp in lst_firm_size_damp]
|
||||
select_customer = \
|
||||
self.model.nprandom.choice(lst_firm_connect,
|
||||
p=lst_prob)
|
||||
@@ -160,6 +170,8 @@ class FirmAgent(ap.Agent):
|
||||
and product not in firm.a_lst_product_removed
|
||||
]
|
||||
prod_accept = self.revenue_log / sum(lst_firm_size)
|
||||
# damp prod
|
||||
prod_accept = prod_accept ** self.flt_diff_new_conn
|
||||
if self.model.nprandom.choice([True, False],
|
||||
p=[prod_accept, 1 - prod_accept]):
|
||||
self.firm_network.graph.add_edges_from([
|
||||
|
||||
Reference in New Issue
Block a user