baseline
This commit is contained in:
52
firm.py
52
firm.py
@@ -99,12 +99,12 @@ class FirmAgent(ap.Agent):
|
||||
if status != 'D':
|
||||
customer.dct_prod_up_prod_stat[
|
||||
prod]['status'].append(('D', self.model.t))
|
||||
print(self.name, disrupted_prod.code, 'disrupt',
|
||||
customer.name, prod.code)
|
||||
# print(self.name, disrupted_prod.code, 'disrupt',
|
||||
# customer.name, prod.code)
|
||||
|
||||
def seek_alt_supply(self, product):
|
||||
# para product is the product that self is seeking
|
||||
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_prod_disrupted[
|
||||
product] <= self.model.int_n_max_trial:
|
||||
if self.dct_n_trial_up_prod_disrupted[product] == 0:
|
||||
@@ -163,10 +163,10 @@ class FirmAgent(ap.Agent):
|
||||
else:
|
||||
select_alt_supply = \
|
||||
self.model.nprandom.choice(lst_firm_connect)
|
||||
print(
|
||||
f"{self.name} selct alt supply for {product.code} "
|
||||
f"from {select_alt_supply.name}"
|
||||
)
|
||||
# print(
|
||||
# f"{self.name} selct alt supply for {product.code} "
|
||||
# f"from {select_alt_supply.name}"
|
||||
# )
|
||||
assert select_alt_supply.is_prod_in_current_normal(product), \
|
||||
f"{select_alt_supply} \
|
||||
does not produce requested product {product}"
|
||||
@@ -179,17 +179,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_prod_disrupted[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:
|
||||
@@ -254,10 +254,10 @@ class FirmAgent(ap.Agent):
|
||||
down_firm.dct_cand_alt_supp_up_prod_disrupted[
|
||||
product].remove(self)
|
||||
|
||||
print(
|
||||
f"{self.name} denied {product.code} request "
|
||||
f"from {down_firm.name} for lack of capacity"
|
||||
)
|
||||
# print(
|
||||
# f"{self.name} denied {product.code} request "
|
||||
# f"from {down_firm.name} for lack of capacity"
|
||||
# )
|
||||
|
||||
def accept_request(self, down_firm, product):
|
||||
# para product is the product that self is selling
|
||||
@@ -283,17 +283,17 @@ class FirmAgent(ap.Agent):
|
||||
del down_firm.dct_n_trial_up_prod_disrupted[product]
|
||||
del down_firm.dct_cand_alt_supp_up_prod_disrupted[product]
|
||||
|
||||
print(
|
||||
f"{self.name} accept {product.code} request "
|
||||
f"from {down_firm.name}"
|
||||
)
|
||||
# print(
|
||||
# f"{self.name} accept {product.code} request "
|
||||
# f"from {down_firm.name}"
|
||||
# )
|
||||
else:
|
||||
down_firm.dct_cand_alt_supp_up_prod_disrupted[product].remove(self)
|
||||
|
||||
print(
|
||||
f"{self.name} denied {product.code} request "
|
||||
f"from {down_firm.name}"
|
||||
)
|
||||
# print(
|
||||
# f"{self.name} denied {product.code} request "
|
||||
# f"from {down_firm.name}"
|
||||
# )
|
||||
|
||||
def clean_before_trial(self):
|
||||
self.dct_request_prod_from_firm = {}
|
||||
|
||||
Reference in New Issue
Block a user