affect customer / remove customer up product conditionally
This commit is contained in:
29
firm.py
29
firm.py
@@ -1,4 +1,5 @@
|
||||
import agentpy as ap
|
||||
import math
|
||||
|
||||
|
||||
class FirmAgent(ap.Agent):
|
||||
@@ -29,7 +30,8 @@ class FirmAgent(ap.Agent):
|
||||
# remove edge
|
||||
# print(n1, n2, key, product_code)
|
||||
self.firm_network.graph.remove_edge(n1, n2, key)
|
||||
# remove customer up product if does not have alternative
|
||||
|
||||
# remove customer up product if does not have alternative / con
|
||||
customer = ap.AgentIter(self.model, n2).to_list()[0]
|
||||
list_in_edges = list(
|
||||
self.firm_network.graph.in_edges(n2,
|
||||
@@ -40,7 +42,8 @@ class FirmAgent(ap.Agent):
|
||||
if edge[-1] == remove_product.code
|
||||
]
|
||||
# print(select_edges)
|
||||
if len(select_edges) == 0:
|
||||
p_remove = math.exp(-1 * len(select_edges))
|
||||
if self.model.nprandom.choice([True, False], p=[p_remove, 1-p_remove]):
|
||||
print(self.name, remove_product.code, 'affect', customer.name)
|
||||
if remove_product not in \
|
||||
customer.a_list_up_product_removed:
|
||||
@@ -123,17 +126,17 @@ class FirmAgent(ap.Agent):
|
||||
# print(product.code, [firm.name for firm in list_firm])
|
||||
|
||||
def accept_request(self, down_firm, product):
|
||||
# if self.model.nprandom.choice([True, False], p=[0.1, 0.9]):
|
||||
self.firm_network.graph.add_edges_from([
|
||||
(self.firm_network.positions[self],
|
||||
self.firm_network.positions[down_firm], {
|
||||
'Product': product.code
|
||||
})
|
||||
])
|
||||
self.dct_prod_capacity[product] -= 1
|
||||
self.dct_request_prod_from_firm[product].remove(down_firm)
|
||||
down_firm.a_list_up_product_removed.remove(product)
|
||||
print(f"{self.name} accept {product.code} request from {down_firm.name}")
|
||||
if self.model.nprandom.choice([True, False], p=[0.1, 0.9]):
|
||||
self.firm_network.graph.add_edges_from([
|
||||
(self.firm_network.positions[self],
|
||||
self.firm_network.positions[down_firm], {
|
||||
'Product': product.code
|
||||
})
|
||||
])
|
||||
self.dct_prod_capacity[product] -= 1
|
||||
self.dct_request_prod_from_firm[product].remove(down_firm)
|
||||
down_firm.a_list_up_product_removed.remove(product)
|
||||
print(f"{self.name} accept {product.code} request from {down_firm.name}")
|
||||
|
||||
def clean_before_trial(self):
|
||||
self.dct_request_prod_from_firm = {}
|
||||
|
||||
Reference in New Issue
Block a user