77 lines
2.4 KiB
Python
77 lines
2.4 KiB
Python
import math
|
||
|
||
import agentpy as ap
|
||
from random import uniform, randint
|
||
from firm import FirmAgent
|
||
|
||
|
||
class WorkerAgent(ap.Agent):
|
||
select_firm: object
|
||
c_effort: float
|
||
s_is_hired: bool
|
||
c_work_months: int
|
||
s_work_duration: int
|
||
working_firm: FirmAgent
|
||
s_salary: float
|
||
s_yield: float
|
||
# s_w_applied: bool
|
||
c_alpha: float
|
||
|
||
def setup(self, alpha):
|
||
# super().__init__(unique_id, model)
|
||
# self.num_workers = 10000
|
||
self.c_effort = uniform(0, 1)
|
||
self.c_work_months = randint(0, 60)
|
||
self.s_is_hired = False
|
||
self.c_alpha = alpha
|
||
# return
|
||
|
||
# def A_Utility(self, c_w_weight=0.5):
|
||
# a = np.exp(FirmAgent.c_f_incentive, c_w_weight)
|
||
# b = np.exp(FirmAgent.s_f_profit/max(FirmAgent.s_f_profit), 1-c_w_weight)
|
||
# self.select_firm = a * b
|
||
|
||
def select_firm(self):
|
||
'''
|
||
挑选出来的企业列表
|
||
数量:列表的长度
|
||
'''
|
||
lst_firms = self.model.provide_lst_random_firms(self)
|
||
n_firms = len(lst_firms)
|
||
# find the max incentive and profit among all firms
|
||
max_incentive, max_profit = 0, 0
|
||
for f in lst_firms:
|
||
if f.c_incentive > max_incentive:
|
||
max_incentive = f.c_incentive
|
||
if f.s_profit > max_profit:
|
||
max_profit = f.s_profit
|
||
# computer the utility for each firm
|
||
max_utility, best_firm = 0, None
|
||
for f in lst_firms:
|
||
u = math.pow(f.c_incentive / max_incentive, self.c_alpha) * math.pow(f.s_profit/max_profit, 1-self.c_alpha)
|
||
if u > max_utility:
|
||
max_utility = u
|
||
best_firm = f
|
||
# print(f'{self}: my best firm is {best_firm} from {n_firms} firms with utility {max_utility}')
|
||
# 选出能够给自己带来最好的效用的企业,并输出/返回
|
||
best_firm.apply(self)
|
||
return best_firm
|
||
|
||
def salary(self, the_firm: FirmAgent):
|
||
'''
|
||
如果员工首次受到雇佣,薪资 = 某公司初始薪资
|
||
如果员工更换了公司, 薪资 = 原薪资 * (1+c_incentive)
|
||
? 换公司
|
||
:return:
|
||
'''
|
||
pass
|
||
|
||
|
||
|
||
def step(self):
|
||
if self.s_is_hired == 1:
|
||
self.s_work_duration +=1
|
||
self.s_yield = 2 / (1 + math.exp(-0.01 * self.s_work_duration * self.c_effort)) - 1
|
||
'''
|
||
是否更换公司成功的状态转换?
|
||
''' |