output_yield change
This commit is contained in:
parent
539544099d
commit
20d3e013ed
50
env.py
50
env.py
|
@ -6,6 +6,7 @@ import math
|
||||||
from worker import WorkerAgent
|
from worker import WorkerAgent
|
||||||
from firm import FirmAgent
|
from firm import FirmAgent
|
||||||
|
|
||||||
|
|
||||||
# plt.ion()
|
# plt.ion()
|
||||||
|
|
||||||
|
|
||||||
|
@ -13,16 +14,14 @@ class Env(ap.Model):
|
||||||
float_market_size: float
|
float_market_size: float
|
||||||
# percent_rh: float
|
# percent_rh: float
|
||||||
percent_search: float
|
percent_search: float
|
||||||
|
|
||||||
is_RH_ratio: float
|
|
||||||
is_FH_ratio: float
|
|
||||||
|
|
||||||
n_worker: int
|
n_worker: int
|
||||||
n_firm: int
|
n_firm: int
|
||||||
e_revenue: float
|
e_revenue: float
|
||||||
|
|
||||||
a_lst_worker: ap.AgentList[WorkerAgent]
|
# a_lst_worker: ap.AgentList[WorkerAgent]
|
||||||
a_lst_firm: ap.AgentList[FirmAgent]
|
# a_lst_firm: ap.AgentList[FirmAgent]
|
||||||
|
a_lst_worker: ap.AgentList
|
||||||
|
a_lst_firm: ap.AgentList
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Worker: Mean(s), Gini(s)
|
Worker: Mean(s), Gini(s)
|
||||||
|
@ -33,17 +32,15 @@ class Env(ap.Model):
|
||||||
out_w_gini_salary: float
|
out_w_gini_salary: float
|
||||||
out_f_avg_profit: float
|
out_f_avg_profit: float
|
||||||
out_f_gini_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_worker = self.p.n_worker
|
||||||
self.n_firm = int(dct_all['n_firm'])
|
self.n_firm = self.p.n_firm
|
||||||
self.percent_search = float(dct_all['percent_search'])
|
self.percent_search = self.p.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_worker = ap.AgentList(self)
|
||||||
self.a_lst_firm = 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):
|
for i in range(self.n_worker):
|
||||||
# 初始化 worker agent,并把alpha属性传过去
|
# 初始化 worker agent,并把alpha属性传过去
|
||||||
w = WorkerAgent(self, float(dct_all['alpha']))
|
w = WorkerAgent(self, self.p.alpha)
|
||||||
self.a_lst_worker.append(w)
|
self.a_lst_worker.append(w)
|
||||||
|
|
||||||
# 在企业列表中添加企业,放入一个is_RH_ratio, 即有多大比例的企业是属于RH类型的
|
# 在企业列表中添加企业,放入一个is_RH_ratio, 即有多大比例的企业是属于RH类型的
|
||||||
for i in range(self.n_firm):
|
for i in range(self.n_firm):
|
||||||
# 对于企业属性true or false 的判断, 影响到firm 板块下, self.s_IsRH = is_RH 语句的判断
|
# 对于企业属性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.a_lst_firm.append(f)
|
||||||
|
|
||||||
self.running = True
|
|
||||||
self.t = 0
|
|
||||||
|
|
||||||
def update_e_revenue(self):
|
def update_e_revenue(self):
|
||||||
self.e_revenue += 0.01 * self.e_revenue
|
self.e_revenue += 0.01 * self.e_revenue
|
||||||
|
|
||||||
|
@ -90,9 +84,9 @@ class Env(ap.Model):
|
||||||
self.update()
|
self.update()
|
||||||
|
|
||||||
if self.t == 200:
|
if self.t == 200:
|
||||||
self.running = False
|
self.stop()
|
||||||
else:
|
# self.picture_out()
|
||||||
self.t += 1
|
# pass
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
lst_salary = []
|
lst_salary = []
|
||||||
|
@ -106,21 +100,25 @@ class Env(ap.Model):
|
||||||
self.out_w_gini_salary = self.gini(lst_salary)
|
self.out_w_gini_salary = self.gini(lst_salary)
|
||||||
|
|
||||||
lst_profit = []
|
lst_profit = []
|
||||||
|
lst_a_yield = []
|
||||||
# n_w_firm = 0
|
# n_w_firm = 0
|
||||||
for f in self.a_lst_firm:
|
for f in self.a_lst_firm:
|
||||||
lst_profit.append(f.s_profit)
|
lst_profit.append(f.s_profit)
|
||||||
|
lst_a_yield.append(f.s_a_yield)
|
||||||
# if f.s_profit > 0:
|
# if f.s_profit > 0:
|
||||||
# n_w_firm += 1
|
# n_w_firm += 1
|
||||||
n_firms = len(lst_profit)
|
n_firms = len(lst_profit)
|
||||||
self.out_f_avg_profit = sum(lst_profit) / n_firms
|
self.out_f_avg_profit = sum(lst_profit) / n_firms
|
||||||
self.out_f_gini_profit = self.gini(lst_profit)
|
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_w_avg_salary')
|
||||||
|
# self.record('out_f_avg_yield')
|
||||||
self.record('out_w_gini_salary')
|
self.record('out_w_gini_salary')
|
||||||
self.record('out_f_avg_profit')
|
self.record('out_f_avg_profit')
|
||||||
self.record('out_f_gini_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):
|
def create_and_destroy_bankrupt_firms(self):
|
||||||
for f in self.a_lst_firm:
|
for f in self.a_lst_firm:
|
||||||
|
@ -134,7 +132,7 @@ class Env(ap.Model):
|
||||||
worker.working_firm = None
|
worker.working_firm = None
|
||||||
self.a_lst_firm.remove(f)
|
self.a_lst_firm.remove(f)
|
||||||
del 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)
|
self.a_lst_firm.append(new_f)
|
||||||
else:
|
else:
|
||||||
if f.s_profit < 0:
|
if f.s_profit < 0:
|
||||||
|
@ -223,7 +221,7 @@ if __name__ == '__main__':
|
||||||
'percent_search': 0.2,
|
'percent_search': 0.2,
|
||||||
'is_RH_ratio': 0.5,
|
'is_RH_ratio': 0.5,
|
||||||
'is_FH_ratio': 0.5,
|
'is_FH_ratio': 0.5,
|
||||||
}
|
}
|
||||||
sample = ap.Sample(parameters)
|
sample = ap.Sample(parameters)
|
||||||
# sample = ap.Sample(parameters, n=3)
|
# sample = ap.Sample(parameters, n=3)
|
||||||
#
|
#
|
||||||
|
|
Loading…
Reference in New Issue