first commit

This commit is contained in:
SongQi 2022-08-01 10:04:35 +08:00
commit 6baaa8ecba
11 changed files with 306 additions and 0 deletions

3
.idea/.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
# Default ignored files
/shelf/
/workspace.xml

10
.idea/hire.iml Normal file
View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/venv" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

View File

@ -0,0 +1,6 @@
<component name="InspectionProjectProfileManager">
<settings>
<option name="USE_PROJECT_PROFILE" value="false" />
<version value="1.0" />
</settings>
</component>

4
.idea/misc.xml Normal file
View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.8 (venv) (3)" project-jdk-type="Python SDK" />
</project>

8
.idea/modules.xml Normal file
View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/hire.iml" filepath="$PROJECT_DIR$/.idea/hire.iml" />
</modules>
</component>
</project>

Binary file not shown.

Binary file not shown.

77
env.py Normal file
View File

@ -0,0 +1,77 @@
import agentpy as ap
from random import uniform
from worker import WorkerAgent
from firm import FirmAgent
class Env(ap.Model):
float_market_size: float
percent_rh: float
percent_search: float
n_worker: int
n_firm: int
a_lst_worker: ap.AgentList
a_lst_firm: ap.AgentList
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.a_lst_worker = ap.AgentList(self)
self.a_lst_firm = ap.AgentList(self)
# 在工人列表中添加工人
for i in range(self.n_worker):
# 初始化 workeragent并把alpha属性传过去
w = WorkerAgent(self, self.p.alpha)
self.a_lst_worker.append(w)
# 在企业列表中添加企业
for i in range(self.n_firm):
f = FirmAgent(self)
self.a_lst_firm.append(f)
def step(self):
self.a_lst_worker.select_firm()
if self.t == 100:
self.stop()
pass
def provide_lst_random_firms(self, the_worker: WorkerAgent):
'''选择企业数量 = 企业总数*百分比
选择企业的列表 = 随机选择的企业的个数
如果员工处于被雇佣的状态
如果员工工作的企业在随机选定的企业列表中
打开列表中的企业
移除该企业
返回值移除后再重新选择随机选择企业
否则
返回值选择企业列表
'''
n_select_firms = int(self.percent_search * self.n_firm)
a_lst_select_firms = self.a_lst_firm.random(n_select_firms)
if the_worker.s_is_hired:
if the_worker.working_firm in a_lst_select_firms:
lst_f = self.a_lst_firm.to_list()
lst_f.remove(the_worker.working_firm)
return ap.AgentList(self, lst_f).random(n_select_firms)
else:
return ap.AgentList(self, a_lst_select_firms)
if __name__ == '__main__':
dict_para = {'n_worker': 100,
'n_firm': 10,
'percent_search': 0.2,
'alpha': 0.5}
my_model = Env(dict_para)
my_model.run()

105
firm.py Normal file
View File

@ -0,0 +1,105 @@
from typing import Union, Any
import agentpy as ap
from random import uniform, randint
class FirmAgent(ap.Agent):
c_incentive: float
s_IsRH: bool
s_a_senior_yield: float
s_a_junior_yield: float
s_a_yield: float
s_salary: float
s_revenue: float
s_profit: float
l_senior_workers: list
l_junior_workers: list
l_applied_workers: list
def setup(self):
self.c_incentive = uniform(0, 1)
self.s_profit = randint(10, 20)
self.l_applied_workers = []
def apply(self, the_worker):
self.l_applied_workers.append(the_worker)
def select_worker(self):
'''
企业找到最想招聘的员工
:return:
'''
n_a_firms = len(self.l_applied_workers)
# 对员工产出进行排队和比较
max_s_yield: float
max_s_yield, best_worker = 0, None
for i in self.l_applied_workers:
y = max_s_yield
if y > max_s_yield:
max_s_yield = y
best_worker = i
# print(f'{self}: my best firm is {best_firm} from {n_firms} firms with utility {max_utility}')
# return best_worker
# 当企业是想要利用产出最高的员工时,从申请的员工中选出产出最高的员工
'''if self.s_IsRH :
# 计算该名员工的工资水平: 原有工资水平* 1+incentive
bw_salary = self.best_worker.salary()
# 将该名员工的产出与公司原有员工的产出进行对比如果高于senior列表中的最后一名的产出就进入senior_list, 否则进入junior_list
self.l_senior_workers.append(best_worker)
else:
self.l_junior_workers.append(best_worker)
# best_worker.apply(self)
else:
# 计算由于改名员工下一期的薪资总数(根据薪资函数更新)以及企业下一期的利润的差值,并选出最大值
'''
def S_a_Yield(self):
# 更新总产出
# s_total_senior_yield = self.s_a_senior_yield * len(self.l_senior_workers)
# s_total_junior_yield = self.s_a_junior_yield * len(self.l_senior_workers)
l_s_workers = self.l_senior_workers
l_j_workers = self.l_junior_workers
# s_a_yield = s_total_yield / len(self.l_senior_workers + self.l_junior_workers)
s_total_senior_yield, s_total_junior_yield = 0, 0
'''for i in range(len(self.l_senior_workers)):
# 加入工人主体的产出属性
s_total_senior_yield += '工人的yield'
for i in range (len(self.l_junior_workers)):
s_total_junior_yield += '工人的yield'
s_a_senior_yield = s_total_senior_yield / len(l_s_workers)
s_a_junior_yield = s_total_junior_yield / len(l_j_workers)
s_a_yield = 0.8*s_a_senior_yield+0.2*s_a_junior_yield
return s_a_yield
'''
return
def LogitShare(self):
'''
self.logitshare = exp(S_a_Yield)/ np.sum(exp(S_a_Yield))
:return:
'''
return
def Sum_salary(self, l_senior_workers, l_junior_workers):
'''
计算某公司整体的薪金水平
'''
l_all_workers = l_senior_workers + l_junior_workers
for i in l_all_workers:
#self.sum_salary = np.sum()
return
def S_Profit(self):
# self.s_profit =self.LogitShare() * EnvironmentAgent.s_e_Irevenue - self.Sum_salary()
return
def step(self):
'''
更新三个集合
首先判断员工i在企业j第t时期的l_applied_workers列表里
第二步判断企业j 的s_IsRH是0或者是1
如果是1则将应聘员工中s_w_yield最大的员工从l_applied_workers列表转移到l_senior_workers或l_junior_workers列表
否则即如果是0则计算每名员工如果进入企业下一期企业利润的提升max的员工
从l_applied_workers列表转移到l_senior_workers或l_junior_workers列表
'''

16
main.py Normal file
View File

@ -0,0 +1,16 @@
# This is a sample Python script.
# Press Shift+F10 to execute it or replace it with your code.
# Press Double Shift to search everywhere for classes, files, tool windows, actions, and settings.
def print_hi(name):
# Use a breakpoint in the code line below to debug your script.
print(f'Hi, {name}') # Press Ctrl+F8 to toggle the breakpoint.
# Press the green button in the gutter to run the script.
if __name__ == '__main__':
print_hi('PyCharm')
# See PyCharm help at https://www.jetbrains.com/help/pycharm/

77
worker.py Normal file
View File

@ -0,0 +1,77 @@
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
'''
是否更换公司成功的状态转换
'''