遗传002

This commit is contained in:
Cricial
2025-10-18 23:18:16 +08:00
parent dfd5c5b32d
commit a6b06735f6
18 changed files with 712 additions and 553 deletions

View File

@@ -1,5 +1,6 @@
from collections import defaultdict
import numpy as np
from mesa import Agent
@@ -81,7 +82,7 @@ class FirmAgent(Agent):
for product in a_lst_product:
assert self.str_cap_limit_prob_type in ['uniform', 'normal'], \
"cap_limit_prob_type must be either 'uniform' or 'normal'"
extra_cap_mean = self.size_stat[0][0] / self.flt_cap_limit_level
extra_cap_mean = self.size_stat[0][0] / self.flt_cap_limit_level if self.flt_cap_limit_level != 0 else 0
if self.str_cap_limit_prob_type == 'uniform':
extra_cap = self.model.random.uniform(extra_cap_mean - 2, extra_cap_mean + 2)
extra_cap = 0 if round(extra_cap) < 0 else round(extra_cap)
@@ -256,6 +257,9 @@ class FirmAgent(Agent):
prod_accept = 1.0
else:
prod_accept = self.flt_diff_new_conn
# 安全处理,防止异常概率
prod_accept = np.nan_to_num(prod_accept, nan=0.0)
prod_accept = max(0.0, min(1.0, prod_accept))
if self.model.nprandom.choice([True, False], p=[prod_accept, 1 - prod_accept]):
self.firm_network.add_edge(self.unique_id, down_firm.unique_id, Product=product.unique_id)
self.dct_prod_capacity[product] -= 1