debug the run_id

This commit is contained in:
He Zhou 2023-02-12 23:43:40 +08:00
parent 6f2e0eb13a
commit f11e771218
4 changed files with 18 additions and 9 deletions

19
env.py
View File

@ -21,21 +21,22 @@ class Env(ap.Model):
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
"""
Worker: Mean(s), Gini(s)
Firm: Mean((pi_{j,t})), Gini(pi_{j,t})
Firm: Mean((pi_{j,t})), Gini(pi_{j,t}), Mean(s_a_yield)
Env: Percent(IsHired)
"""
out_w_avg_salary: float
out_w_gini_salary: float
out_f_avg_profit: float
out_f_avg_yield: float
out_f_gini_profit: float
out_w_percent_hired: float
def __init__(self, dct_all):
def __init__(self, dct_all, _run_id=None):
super().__init__()
# 工作人员、企业数量、搜寻企业数量赋值
@ -89,10 +90,12 @@ class Env(ap.Model):
# self.picture_out()
self.update()
if self.t == 200:
if self.t >= 200:
self.running = False
self.stop()
else:
self.t += 1
# print(f"running the {self.t} step")
def update(self):
lst_salary = []
@ -106,19 +109,23 @@ class Env(ap.Model):
self.out_w_gini_salary = self.gini(lst_salary)
lst_profit = []
lst_yield = []
# n_w_firm = 0
for f in self.a_lst_firm:
lst_profit.append(f.s_profit)
lst_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_avg_yield = sum(lst_yield) / n_firms
self.out_f_gini_profit = self.gini(lst_profit)
self.out_w_percent_hired = n_hired / n_workers
self.record('out_w_avg_salary')
self.record('out_w_gini_salary')
self.record('out_f_avg_profit')
self.record('out_f_avg_yield')
self.record('out_f_gini_profit')
self.record('out_w_percent_hired')
@ -229,4 +236,4 @@ if __name__ == '__main__':
#
exp = ap.Experiment(Env, sample, iterations=10, record=True)
results = exp.run()
results['variables']['Env'].to_excel('env_data.xlsx', engine='openpyxl')
results['variables']['Env'].to_excel('env_data.xlsx', engine='openpyxl')

Binary file not shown.

View File

@ -24,7 +24,8 @@ model_para = {
"n_firm": 100
}
lst_op_key = ['out_w_avg_salary', 'out_w_gini_salary', 'out_f_avg_profit', 'out_f_gini_profit', 'out_w_percent_hired']
lst_op_key = ['out_w_avg_salary', 'out_w_gini_salary', 'out_f_avg_profit', 'out_f_avg_yield',
'out_f_gini_profit', 'out_w_percent_hired']
lst_2d_op_avg = []
lst_2d_xv = []
for idx_row in range(idx_start-1, n_row, 1):
@ -48,8 +49,8 @@ for idx_row in range(idx_start-1, n_row, 1):
break
lst_2d_op.append([the_model.out_w_avg_salary, the_model.out_w_gini_salary,
the_model.out_f_avg_profit, the_model.out_f_gini_profit,
the_model.out_w_percent_hired])
the_model.out_f_avg_profit, the_model.out_f_avg_yield,
the_model.out_f_gini_profit, the_model.out_w_percent_hired])
arr_op = np.array(lst_2d_op)
lst_2d_op_avg.append(arr_op.mean(axis=0).tolist())

View File

@ -40,6 +40,7 @@ class FirmAgent(ap.Agent):
self.initial_f_salary = randint(8000, 10000)
self.s_profit = 0
self.s_value = 0
self.s_a_yield = 0
def apply(self, the_worker):
self.l_applied_workers.append(the_worker)