output_yield change

This commit is contained in:
SongQi 2023-02-12 22:17:12 +08:00
parent 539544099d
commit 20d3e013ed
1 changed files with 24 additions and 26 deletions

48
env.py
View File

@ -6,6 +6,7 @@ import math
from worker import WorkerAgent
from firm import FirmAgent
# plt.ion()
@ -13,16 +14,14 @@ 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[WorkerAgent]
# a_lst_firm: ap.AgentList[FirmAgent]
a_lst_worker: ap.AgentList
a_lst_firm: ap.AgentList
"""
Worker: Mean(s), Gini(s)
@ -33,17 +32,15 @@ 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_w_percent_hired: float
out_f_avg_yield: float
def __init__(self, dct_all):
super().__init__()
def setup(self):
# 工作人员、企业数量、搜寻企业数量赋值
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.n_worker = self.p.n_worker
self.n_firm = self.p.n_firm
self.percent_search = self.p.percent_search
# 工人、企业列表
self.a_lst_worker = ap.AgentList(self)
self.a_lst_firm = ap.AgentList(self)
@ -52,18 +49,15 @@ class Env(ap.Model):
# 在工人列表中添加工人
for i in range(self.n_worker):
# 初始化 worker agent并把alpha属性传过去
w = WorkerAgent(self, float(dct_all['alpha']))
w = WorkerAgent(self, self.p.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.is_RH_ratio >= uniform(0, 1), self.is_FH_ratio >= uniform(0, 1))
f = FirmAgent(self, self.p.is_RH_ratio >= uniform(0, 1), self.p.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
@ -90,9 +84,9 @@ class Env(ap.Model):
self.update()
if self.t == 200:
self.running = False
else:
self.t += 1
self.stop()
# self.picture_out()
# pass
def update(self):
lst_salary = []
@ -106,21 +100,25 @@ 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_w_percent_hired = n_hired / n_workers
self.out_f_avg_yield = sum(lst_a_yield)
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:
@ -134,7 +132,7 @@ class Env(ap.Model):
worker.working_firm = None
self.a_lst_firm.remove(f)
del f
new_f = FirmAgent(self, self.is_RH_ratio >= uniform(0, 1), self.is_FH_ratio >= uniform(0, 1))
new_f = FirmAgent(self, self.p.is_RH_ratio >= uniform(0, 1), self.p.is_FH_ratio >= uniform(0, 1))
self.a_lst_firm.append(new_f)
else:
if f.s_profit < 0: