From 6baaa8ecba1377dfb78b4d28da1e75268c0b22d4 Mon Sep 17 00:00:00 2001 From: SongQi Date: Mon, 1 Aug 2022 10:04:35 +0800 Subject: [PATCH] first commit --- .idea/.gitignore | 3 + .idea/hire.iml | 10 ++ .../inspectionProfiles/profiles_settings.xml | 6 + .idea/misc.xml | 4 + .idea/modules.xml | 8 ++ __pycache__/firm.cpython-38.pyc | Bin 0 -> 2840 bytes __pycache__/worker.cpython-38.pyc | Bin 0 -> 1672 bytes env.py | 77 +++++++++++++ firm.py | 105 ++++++++++++++++++ main.py | 16 +++ worker.py | 77 +++++++++++++ 11 files changed, 306 insertions(+) create mode 100644 .idea/.gitignore create mode 100644 .idea/hire.iml create mode 100644 .idea/inspectionProfiles/profiles_settings.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 __pycache__/firm.cpython-38.pyc create mode 100644 __pycache__/worker.cpython-38.pyc create mode 100644 env.py create mode 100644 firm.py create mode 100644 main.py create mode 100644 worker.py diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/hire.iml b/.idea/hire.iml new file mode 100644 index 0000000..74d515a --- /dev/null +++ b/.idea/hire.iml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..105ce2d --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..addf024 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..9d36c46 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/__pycache__/firm.cpython-38.pyc b/__pycache__/firm.cpython-38.pyc new file mode 100644 index 0000000000000000000000000000000000000000..c9482ee0f36eb76b6e1ba672c5b6cca7dde130d3 GIT binary patch literal 2840 zcmb_e-EY%Y6!-N<;v_9CP}cIfXb%&Srj9*q(hx(Sp?yeOHLc@eUXf*T-Qwan!FCvl z5~)xMMZhT9Rz6ydAwl_2fl45jLD~KfzY@F6Q{VTrb8N>=$~InR%jevWbMHOpcRsEU zc6KHicpC349WHk>%uDRFK0I{x!DsCSLK#YQCPyTaV71>e&3sWv>s!oHEQGg>FNuZ2B>4=tW zDY{~oBp5W+?>n$KQIGnQMY=x1D%~Fo?ew!O%U!Ux-t0T9lh<|y+ksgRolqjeAthk*0daAJUjYEbB|2SF)mA5lY4e7ypK zr#k{-R_cSM+{ovD;|Kw$#nSC7f;q}*S&LpxRVRs?3g$H*gHS7eDdnj_0#UY=yCyI;>iDh=@Zphm_Xh z(g|)Ai$+^hZ>_b7LBQ!-Ow$kH zC`$yw@G%l&#Z-CYs)dnMn{}uze!g{>8I(Zou;uR}A7M)L>-iDQwjdSM^has+L}6#N zTjt%gQRugdxt;C9nP`Joygm?EfG$~UOY#dmXb=zj5~hQ&7Ro)VW~>TiF_xQ8o0qo0 zXoXbRUIrqXgLoFJJfs;|7Fbt&9|W5EEkC@u^ze#zW6GVFcQ4hvpP$rU{0OnTJbk}$ z_OiF|#QptoQ#Ku_9=dbYzfvdEFI{hX)7%XEzhc^8F&Ea!Z(uqo9lS_Hw$;2XUXNxQbJOkwj9hRhZ+X)Xf*PQ?vv-3+F}gHAZ+lmsdb2kGZ4uWdN?Bt>v_d?x@1`~3@Da1{Hs|Y#UIY+b%)nA%Qo?jH+zv_**CW# z*^Xofk~fj0k>CyALhw2@@qWb5dK*X*E{T75Sy2!Irl`)e{uCuWxlnlWNx zmYGDdtVp`q FzX1g?N5%jE literal 0 HcmV?d00001 diff --git a/__pycache__/worker.cpython-38.pyc b/__pycache__/worker.cpython-38.pyc new file mode 100644 index 0000000000000000000000000000000000000000..92088f47e7e14ee61cd9a741d6aff828d83a55bd GIT binary patch literal 1672 zcmZ8h&1)n@6tC*<>6zIi8rbMwg6zQo*^?khkf_V`QZusxE3*Te)4rKHnH#vA-DJWN_7M|y zZ0vf6X3!D*12%AGu){V6hH@u)GAd-ITp8se$*TcZog0bF-rbJ#YDjA5mkD7VUzr19 z7I47=<2H-U*b;n=#Wtt`>VTS{E~wQ~8`OjBfRdiuQm>_*H70z~Jz{XOC;FhixFi-p zyJ8VeFRAW_h1`p!c1?B5IE{x@ID)gv8;0=+aa77L!=wy%5*Z8CABJ~vBFu`s+9}mS zITyu5MpaVeL681T@@;J+@XD}^(nwB~TZYplPK9!ZVU&({qM?CspDp6)9p1-Rz7D96 z5Mdk|H4AxVfHyU73JW_{&4IRHh``>E9Qrd2Yv67S97*P+OF%|thX6IeWDkH0S%`C_ zZ0*NSOfF&f-&d}`y*Zu^cOsc>QmC60NGz|7r^+tlYBFAiR!LTv+2cL#@PnmuZ+A`W z49SgWi>@UnbWq=cso5?&hU+K1K~Ob6n4zhV74+f4=$q!O;_RhwcO#j&cQ{%=q4T-Yi{+1Fm21 ze*vRos(4K8HSYjKd5K@;2a6XXgUZIBr@S!Cqbv?X<%gIPVv-Wy3&Z_Ml(zpk#nvt+ zjamr9D9?*Z504UR_9!hPq;{()Qe|RzN*dJiWdeF0xk^ACdk%C?Z0u2JB}IiST>Kfx z&?WCxNm>Jc9=RLQKt_Wb(O5b2vYXEi8XJK{#iOrRww{mr@VRTX7j(Ds*5+}(Ls`^M KL 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列表。 + ''' diff --git a/main.py b/main.py new file mode 100644 index 0000000..5596b44 --- /dev/null +++ b/main.py @@ -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/ diff --git a/worker.py b/worker.py new file mode 100644 index 0000000..e05fc0f --- /dev/null +++ b/worker.py @@ -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 + ''' + 是否更换公司成功的状态转换? + ''' \ No newline at end of file