From 313870bcc32b600a071984a7cebd66ace1f431bf Mon Sep 17 00:00:00 2001 From: HaoYizhi Date: Sat, 10 Jun 2023 19:51:50 +0800 Subject: [PATCH] rename variable --- __pycache__/controller_db.cpython-38.pyc | Bin 7728 -> 7556 bytes __pycache__/firm.cpython-38.pyc | Bin 6893 -> 6895 bytes __pycache__/model.cpython-38.pyc | Bin 11831 -> 11827 bytes __pycache__/orm.cpython-38.pyc | Bin 3752 -> 3751 bytes controller_db.py | 44 ++++------------------- firm.py | 12 +++---- model.py | 8 ++--- orm.py | 8 ++--- xv_with_exp.csv | 2 +- xv_without_exp.csv | 2 +- 10 files changed, 23 insertions(+), 53 deletions(-) diff --git a/__pycache__/controller_db.cpython-38.pyc b/__pycache__/controller_db.cpython-38.pyc index 5598263f4d316ec49e87cfb0a84b0789319cff0e..40f28131277a8144cfd0ab732924984f4c979a5d 100644 GIT binary patch delta 145 zcmdmB(_+mR%FD~e00fhgTT&iqPUMqe?3<|F%a+0#%%I7!@rfOeeNk#*d_hrKd~s$~ z>Mg;v%%a@*#N=dz5Px23NqKy6K~5!DEbo>OiooV1-X?w~O|i*#vYnHk$tp>S0d13D N6k+56LJnle3;@o?D?9)I delta 298 zcmZp%-eAKQ%FD~e00e2WEh&?AC-TWKZkedvtCK30!ja8Xv>{bAg|nG4N<5WufkX<| zLdFG>3mKxMQl(R+ni&}xQdol-G`TnKv*U3nC`wI>FG?*eO)W0DC6Ja`lp7BgN=!~p zEdYw-rIwUKM2brb3gYu_38RW^w&rc(kGjPXAD^3;nHL{_ixp@_aY>bHu&a-&bBKbo zf2d!GhL)y+zJjr_k-4dXf?JTkuL4+6d~srKK~Abdu|l|qYmlo#v0i3zd`f;^YJ6Hw zV!DE@f}y6&}5Uz}N$dP_7drzActvnV$nSvX1% SER>j>j7=r7@aA;pHgN#(?I-;J delta 103 zcmaEF`qq>;l$V!_0SG3Ax1{Xd$ji^{T~L&o7GIQFSejZ~a!WKVrzActvnV$nSvX1n XA(WV$oLW$FO9WLRM09f|bDKB-m6j(A diff --git a/__pycache__/model.cpython-38.pyc b/__pycache__/model.cpython-38.pyc index 36beee74d4157b2b3a20977a940238ac064fb94e..075a5cf0b528df3eec75211bdcd9976c4da32e78 100644 GIT binary patch delta 461 zcmdlUvpI%0l$V!_0SHzkx1>02P*L`yG_nQW~nDgP*i zDUYd!6DY=+!kEo4fwAaI3L{hmsA_Vp;xoqF%_&ORj6z{RLyH1{#4YyHyv(%xqTI<3 zl_xQ3OfFH$t| s+Zh>mP2R7wQ;-MbR6ZcV!N^h1P|v_Wxl?x`FCz!g**uH_K$?RY0KzejdjJ3c delta 464 zcmdlSvpt44l$V!_0SK;yx1{uL&65Cl?5CPOjzgVvL!5f~S`;YjPNGA7jDfr@XTmOC~q)H8W0_%)-Bvaq;9; z{7V>jPWBflWjsCks6Y?nrO82pt&F!O-w^C(d;v5`ZL)xn{N$BFN{nyd=Dy(Kn`V5(rO0=R+rWa w#&esEwc8mP_e|ccvr~{4yIhtxl$V!_0SIc6TT*m4@~&XBFG?+pFDOcjFV3t=y(O5IS(F=}n4F9d;?GMh XDUUBM$f*R2<=qlO5!n2dZ8JLnqSqq2 delta 92 zcmZ23yF!*Xl$V!_0SK1KwxsB7j>oLT@B a$xAIMhlmuH78Jzi-4aF>+5ClVGdlpkbt4J@ diff --git a/controller_db.py b/controller_db.py index f70faed..dfe5de2 100644 --- a/controller_db.py +++ b/controller_db.py @@ -112,9 +112,9 @@ class ControllerDB: def add_experiment_1(self, idx_scenario, idx_init_removal, dct_lst_init_remove_firm_prod, g_bom, - n_max_trial, crit_supplier, firm_pref_request, - firm_pref_accept, netw_pref_supp_n, - netw_pref_supp_size, cap_limit, diff_new_conn, + n_max_trial, crit_supplier, firm_req_prf_size, + firm_acc_prf_size, netw_sply_prf_n, + netw_sply_prf_size, cap_limit, diff_new_conn, diff_remove, proactive_ratio): e = Experiment( idx_scenario=idx_scenario, @@ -125,10 +125,10 @@ class ControllerDB: g_bom=g_bom, n_max_trial=n_max_trial, crit_supplier=crit_supplier, - firm_pref_request=firm_pref_request, - firm_pref_accept=firm_pref_accept, - netw_pref_supp_n=netw_pref_supp_n, - netw_pref_supp_size=netw_pref_supp_size, + firm_req_prf_size=firm_req_prf_size, + firm_acc_prf_size=firm_acc_prf_size, + netw_sply_prf_n=netw_sply_prf_n, + netw_sply_prf_size=netw_sply_prf_size, cap_limit=cap_limit, diff_new_conn=diff_new_conn, diff_remove=diff_remove, @@ -262,33 +262,3 @@ class ControllerDB: def lock_the_sample(sample: Sample): sample.is_done_flag, sample.computer_name = 0, platform.node() db_session.commit() - - -if __name__ == '__main__': - # pprint.pprint(dct_exp_config) - # pprint.pprint(dct_conf_problem) - db = ControllerDB('first') - ratio = db_session.execute( - 'SELECT COUNT(*) / 332750 FROM first_sample s WHERE s.is_done_flag = 1' - ).scalar() - print(ratio) - # db.fill_experiment_table() - # print(db.dct_parameter) - # db.init_tables() - # db.fill_sample_table() - # pprint.pprint(dct_conf_exp) - # db.update_bi() - # db.reset_db(force_drop=True) - # db.prepare_list_sample() - # - # for i in range(1000): - # if i % 10 == 0: - # print(i) - # print(len(db.lst_saved_s_id_1_2), len(db.lst_saved_s_id_3)) - # r = db.fetch_a_sample() - # if i % 10 == 0: - # print(len(db.lst_saved_s_id_1_2), len(db.lst_saved_s_id_3)) - # print(r, r.experiment.idx_exp) - # if i == 400: - # print() - # pass diff --git a/firm.py b/firm.py index e88a64a..ca8f8d1 100644 --- a/firm.py +++ b/firm.py @@ -24,8 +24,8 @@ class FirmAgent(ap.Agent): # para self.flt_crit_supplier = float(self.p.crit_supplier) - self.flt_firm_pref_request = float(self.p.firm_pref_request) - self.flt_firm_pref_accept = float(self.p.firm_pref_accept) + self.flt_firm_req_prf_size = float(self.p.firm_req_prf_size) + self.flt_firm_acc_prf_size = float(self.p.firm_acc_prf_size) self.flt_diff_new_conn = float(self.p.diff_new_conn) def remove_edge_to_cus_remove_cus_up_prod(self, remove_product): @@ -95,7 +95,7 @@ class FirmAgent(ap.Agent): if len(lst_firm_connect) == 0: # select based on size lst_size_damp = \ - [size ** self.flt_firm_pref_request for size in + [size ** self.flt_firm_req_prf_size for size in self.dct_cand_alt_supply_up_prod_removed[ product].revenue_log] lst_prob = [size_damp / sum(lst_size_damp) @@ -106,7 +106,7 @@ class FirmAgent(ap.Agent): elif len(lst_firm_connect) > 0: # select based on size of firm that has connection lst_firm_size_damp = \ - [size ** self.flt_firm_pref_accept + [size ** self.flt_firm_acc_prf_size for size in lst_firm_connect.revenue_log] lst_prob = \ [size_damp / sum(lst_firm_size_damp) @@ -167,7 +167,7 @@ class FirmAgent(ap.Agent): if len(lst_firm_connect) == 0: # handling based on size lst_firm_size_damp = \ - [size ** self.flt_firm_pref_accept + [size ** self.flt_firm_acc_prf_size for size in lst_firm.revenue_log] lst_prob = \ [size_damp / sum(lst_firm_size_damp) @@ -178,7 +178,7 @@ class FirmAgent(ap.Agent): elif len(lst_firm_connect) > 0: # handling based on size of firm that has connection lst_firm_size_damp = \ - [size ** self.flt_firm_pref_accept + [size ** self.flt_firm_acc_prf_size for size in lst_firm_connect.revenue_log] lst_prob = \ [size_damp / sum(lst_firm_size_damp) diff --git a/model.py b/model.py index 5facb84..956334c 100644 --- a/model.py +++ b/model.py @@ -19,8 +19,8 @@ class Model(ap.Model): self.dct_lst_remove_firm_prod = self.p.dct_lst_init_remove_firm_prod self.int_n_max_trial = int(self.p.n_max_trial) - self.flt_netw_pref_supp_n = float(self.p.netw_pref_supp_n) - self.flt_netw_pref_supp_size = float(self.p.netw_pref_supp_size) + self.flt_netw_sply_prf_n = float(self.p.netw_sply_prf_n) + self.flt_netw_sply_prf_size = float(self.p.netw_sply_prf_size) self.flt_cap_limit = int(self.p.cap_limit) self.flt_diff_remove = float(self.p.diff_remove) self.proactive_ratio = float(self.p.proactive_ratio) @@ -76,7 +76,7 @@ class Model(ap.Model): 1].to_list() lst_pred_firm_size_damp = \ [G_Firm.nodes[pred_firm]['Revenue_Log'] ** - self.flt_netw_pref_supp_size + self.flt_netw_sply_prf_size for pred_firm in lst_pred_firm ] lst_prob = \ @@ -94,7 +94,7 @@ class Model(ap.Model): share = G_Firm.nodes[node]['Revenue_Log'] / sum( lst_same_prod_firm_size) # damp share - share = share ** self.flt_netw_pref_supp_n + share = share ** self.flt_netw_sply_prf_n n_pred_firm = round(share * len(lst_pred_firm)) if round( share * len(lst_pred_firm)) > 0 else 1 # at least one lst_choose_firm = self.nprandom.choice(lst_pred_firm, diff --git a/orm.py b/orm.py index 962d2de..e9f115b 100644 --- a/orm.py +++ b/orm.py @@ -56,10 +56,10 @@ class Experiment(Base): n_max_trial = Column(Integer, nullable=False) crit_supplier = Column(DECIMAL(8, 4), nullable=False) - firm_pref_request = Column(DECIMAL(8, 4), nullable=False) - firm_pref_accept = Column(DECIMAL(8, 4), nullable=False) - netw_pref_supp_n = Column(DECIMAL(8, 4), nullable=False) - netw_pref_supp_size = Column(DECIMAL(8, 4), nullable=False) + firm_req_prf_size = Column(DECIMAL(8, 4), nullable=False) + firm_acc_prf_size = Column(DECIMAL(8, 4), nullable=False) + netw_sply_prf_n = Column(DECIMAL(8, 4), nullable=False) + netw_sply_prf_size = Column(DECIMAL(8, 4), nullable=False) cap_limit = Column(Integer, nullable=False) diff_new_conn = Column(DECIMAL(8, 4), nullable=False) diff_remove = Column(DECIMAL(8, 4), nullable=False) diff --git a/xv_with_exp.csv b/xv_with_exp.csv index fae4d3a..8a2314d 100644 --- a/xv_with_exp.csv +++ b/xv_with_exp.csv @@ -1,4 +1,4 @@ -n_max_trial,crit_supplier,firm_pref_request,firm_pref_accept,netw_pref_supp_n,netw_pref_supp_size,cap_limit,diff_new_conn,diff_remove,proactive_ratio +n_max_trial,crit_supplier,firm_req_prf_size,firm_acc_prf_size,netw_sply_prf_size,netw_pref_supp_size,cap_limit,diff_new_conn,diff_remove,proactive_ratio 15,2,2,2,0.5,2,4,0.5,0.5,0.4 10,1,1,1,1,1,2,1,1,0.6 5,0.5,0.5,0.5,2,0.5,1,2,2,0.8 diff --git a/xv_without_exp.csv b/xv_without_exp.csv index 5da5d04..63fb0b8 100644 --- a/xv_without_exp.csv +++ b/xv_without_exp.csv @@ -1,2 +1,2 @@ -n_max_trial,crit_supplier,firm_pref_request,firm_pref_accept,netw_pref_supp_n,netw_pref_supp_size,cap_limit,diff_new_conn,diff_remove,proactive_ratio +n_max_trial,crit_supplier,firm_req_prf_size,firm_acc_prf_size,netw_sply_prf_n,netw_sply_prf_size,cap_limit,diff_new_conn,diff_remove,proactive_ratio 10,1,1,1,1,1,2,1,1,0.8