discard the modifications on env.py

This commit is contained in:
He Zhou 2023-02-12 22:52:46 +08:00
parent e9f1cca775
commit 6f2e0eb13a
1 changed files with 27 additions and 25 deletions

48
env.py
View File

@ -6,7 +6,6 @@ import math
from worker import WorkerAgent
from firm import FirmAgent
# plt.ion()
@ -14,14 +13,16 @@ class Env(ap.Model):
float_market_size: float
# percent_rh: float
percent_search: float
is_RH_ratio: float
is_FH_ratio: float
n_worker: int
n_firm: int
e_revenue: float
# a_lst_worker: ap.AgentList[WorkerAgent]
# a_lst_firm: ap.AgentList[FirmAgent]
a_lst_worker: ap.AgentList
a_lst_firm: ap.AgentList
a_lst_worker: ap.AgentList[WorkerAgent]
a_lst_firm: ap.AgentList[FirmAgent]
"""
Worker: Mean(s), Gini(s)
@ -32,15 +33,17 @@ class Env(ap.Model):
out_w_gini_salary: float
out_f_avg_profit: float
out_f_gini_profit: float
# out_w_percent_hired: float
out_f_avg_yield: float
out_w_percent_hired: float
def __init__(self, dct_all):
super().__init__()
def setup(self):
# 工作人员、企业数量、搜寻企业数量赋值
self.n_worker = self.p.n_worker
self.n_firm = self.p.n_firm
self.percent_search = self.p.percent_search
self.n_worker = int(dct_all['n_worker'])
self.n_firm = int(dct_all['n_firm'])
self.percent_search = float(dct_all['percent_search'])
self.is_RH_ratio = float(dct_all['is_RH_ratio'])
self.is_FH_ratio = float(dct_all['is_FH_ratio'])
# 工人、企业列表
self.a_lst_worker = ap.AgentList(self)
self.a_lst_firm = ap.AgentList(self)
@ -49,15 +52,18 @@ class Env(ap.Model):
# 在工人列表中添加工人
for i in range(self.n_worker):
# 初始化 worker agent并把alpha属性传过去
w = WorkerAgent(self, self.p.alpha)
w = WorkerAgent(self, float(dct_all['alpha']))
self.a_lst_worker.append(w)
# 在企业列表中添加企业放入一个is_RH_ratio, 即有多大比例的企业是属于RH类型的
for i in range(self.n_firm):
# 对于企业属性true or false 的判断, 影响到firm 板块下, self.s_IsRH = is_RH 语句的判断
f = FirmAgent(self, self.p.is_RH_ratio >= uniform(0, 1), self.p.is_FH_ratio >= uniform(0, 1))
f = FirmAgent(self, self.is_RH_ratio >= uniform(0, 1), self.is_FH_ratio >= uniform(0, 1))
self.a_lst_firm.append(f)
self.running = True
self.t = 0
def update_e_revenue(self):
self.e_revenue += 0.01 * self.e_revenue
@ -84,9 +90,9 @@ class Env(ap.Model):
self.update()
if self.t == 200:
self.stop()
# self.picture_out()
# pass
self.running = False
else:
self.t += 1
def update(self):
lst_salary = []
@ -100,25 +106,21 @@ class Env(ap.Model):
self.out_w_gini_salary = self.gini(lst_salary)
lst_profit = []
lst_a_yield = []
# n_w_firm = 0
for f in self.a_lst_firm:
lst_profit.append(f.s_profit)
lst_a_yield.append(f.s_a_yield)
# if f.s_profit > 0:
# n_w_firm += 1
n_firms = len(lst_profit)
self.out_f_avg_profit = sum(lst_profit) / n_firms
self.out_f_gini_profit = self.gini(lst_profit)
# self.out_w_percent_hired = n_hired / n_workers
self.out_f_avg_yield = sum(lst_a_yield) / n_firms
self.out_w_percent_hired = n_hired / n_workers
self.record('out_w_avg_salary')
self.record('out_f_avg_yield')
self.record('out_w_gini_salary')
self.record('out_f_avg_profit')
self.record('out_f_gini_profit')
# self.record('out_w_percent_hired')
self.record('out_w_percent_hired')
def create_and_destroy_bankrupt_firms(self):
for f in self.a_lst_firm:
@ -132,7 +134,7 @@ class Env(ap.Model):
worker.working_firm = None
self.a_lst_firm.remove(f)
del f
new_f = FirmAgent(self, self.p.is_RH_ratio >= uniform(0, 1), self.p.is_FH_ratio >= uniform(0, 1))
new_f = FirmAgent(self, self.is_RH_ratio >= uniform(0, 1), self.is_FH_ratio >= uniform(0, 1))
self.a_lst_firm.append(new_f)
else:
if f.s_profit < 0: