first normal run

This commit is contained in:
2023-03-16 21:38:57 +08:00
parent 1072d4e2b0
commit 6489ecff90
9 changed files with 50 additions and 50 deletions

34
firm.py
View File

@@ -44,8 +44,8 @@ class FirmAgent(ap.Agent):
if self.model.nprandom.choice([True, False],
p=[prod_remove,
1 - prod_remove]):
print(self.name, remove_product.code, 'affect',
customer.name)
# print(self.name, remove_product.code, 'affect',
# customer.name)
if remove_product not in \
customer.a_lst_up_product_removed:
customer.a_lst_up_product_removed.append(
@@ -55,7 +55,7 @@ class FirmAgent(ap.Agent):
def seek_alt_supply(self):
for product in self.a_lst_up_product_removed:
print(f"{self.name} seek alt supply for {product.code}")
# print(f"{self.name} seek alt supply for {product.code}")
if self.dct_n_trial_up_product_removed[
product] <= self.model.int_n_max_trial:
# select a list of candidate firm that has the product
@@ -73,9 +73,9 @@ class FirmAgent(ap.Agent):
]
select_alt_supply = self.model.nprandom.choice(
candidate_alt_supply, p=lst_prob)
print(
f"{self.name} selct alt supply for {product.code} from {select_alt_supply.name}"
)
# print(
# f"{self.name} selct alt supply for {product.code} from {select_alt_supply.name}"
# )
assert product in select_alt_supply.a_lst_product, \
f"{select_alt_supply} \
does not produce requested product {product}"
@@ -88,17 +88,17 @@ class FirmAgent(ap.Agent):
select_alt_supply.dct_request_prod_from_firm[product] = [
self
]
print(
select_alt_supply.name, 'dct_request_prod_from_firm', {
key.code: [v.name for v in value]
for key, value in
select_alt_supply.dct_request_prod_from_firm.items()
})
# print(
# select_alt_supply.name, 'dct_request_prod_from_firm', {
# key.code: [v.name for v in value]
# for key, value in
# select_alt_supply.dct_request_prod_from_firm.items()
# })
self.dct_n_trial_up_product_removed[product] += 1
def handle_request(self):
print(self.name, 'handle_request')
# print(self.name, 'handle_request')
for product, lst_firm in self.dct_request_prod_from_firm.items():
if self.dct_prod_capacity[product] > 0:
if len(lst_firm) == 0:
@@ -117,7 +117,7 @@ class FirmAgent(ap.Agent):
lst_adj_firm += [ap.AgentIter(self.model, edge[1]).to_list()[0].code for edge in out_edges]
lst_adj_firm += [ap.AgentIter(self.model, edge[0]).to_list()[0].code for edge in in_edges]
if self.code in lst_adj_firm:
lst_firm_connect += firm
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]
@@ -156,9 +156,9 @@ class FirmAgent(ap.Agent):
self.dct_prod_capacity[product] -= 1
self.dct_request_prod_from_firm[product].remove(down_firm)
down_firm.a_lst_up_product_removed.remove(product)
print(
f"{self.name} accept {product.code} request from {down_firm.name}"
)
# print(
# f"{self.name} accept {product.code} request from {down_firm.name}"
# )
def clean_before_trial(self):
self.dct_request_prod_from_firm = {}