From 7a08a52f3f048b3577d3343087eb1579e5e20648 Mon Sep 17 00:00:00 2001 From: HaoYizhi Date: Sat, 10 Jun 2023 20:56:34 +0800 Subject: [PATCH] exp connect first --- __pycache__/controller_db.cpython-38.pyc | Bin 7556 -> 7623 bytes __pycache__/firm.cpython-38.pyc | Bin 6895 -> 7068 bytes __pycache__/model.cpython-38.pyc | Bin 11827 -> 11842 bytes __pycache__/orm.cpython-38.pyc | Bin 3751 -> 3822 bytes __pycache__/product.cpython-38.pyc | Bin 1382 -> 1382 bytes controller_db.py | 16 +++-- firm.py | 77 +++++++++++++---------- model.py | 2 +- orm.py | 2 + xv_with_exp.csv | 8 +-- xv_without_exp.csv | 4 +- 11 files changed, 62 insertions(+), 47 deletions(-) diff --git a/__pycache__/controller_db.cpython-38.pyc b/__pycache__/controller_db.cpython-38.pyc index 40f28131277a8144cfd0ab732924984f4c979a5d..4452c70b94dfccf17200fc953723ea5a086d7481 100644 GIT binary patch delta 993 zcmZ{i%TE(g6o==u)0RSCw54zAD^@T{iWn0>6HpQoBhiSuFiL4=rZQNdy)#kNsYb*Y zL=AF?B98=P+_=)zg}PE>V*Cfd)Qzr9bmhv0-ZLe*@+SA2bARVCXYQHF&X1j*lWupd zz*k3cQhu}Zh3At9Z_A&>-H95&pGf*djY zoY7_54X*O+3BC`O@7otF&i3}pw$_%mmNwkylmT$j*$Hu6bH2CRw4rQ4DbLp)0C3=H zT@n)btF9|nPoJ^A{QMc@`w-vSDLm?G_ZeQpCtL6OOZB>SMKtPh&Xr2|*-;+BjuZL` zCkQD*AFjIELrf`V3M`kA#zsdg^*NP|WU`Wke_RofB#gVShy5%}3I8gs=f85NTiF1) zGK4{n3Mec}2NN-}4ios+c5w&}to3YhfCVf+?7?!2M**0{Id8Y!>@JO8yb5Ho+ZTg= zJmYHu32*wk5~Dn`0$R1I$`8yeo#fU``J3;h1c(W+N{jH*pwZ)692#j(i8(|Hoo6zgIeeXvPV zZxJknjULz(9qH99ODGWN4x6o~Yx0_&(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2UQX^0rAAx)}~$9J~2NFc+{#aSzN^kz#jf=cR5#v+;@3y5OZB(MLLBE@{TYi zK)n#J2YpYFD+=!is=1_8XIgaqR%}$6A@%|c+W zA&u;YFhNTCRr&?Lk8`Nd!Krr*U-v0hLA%A{;`%)A6)++cv2)lFN2cnxnKDJ$NDsl@Hg8rfo+b z8lf3ImCI($ltZ7z5WW*`;)U4B$gZdOAZ2<6eJ>+)BJktkB8=FkIjSeqj&6_T^XbdS z!EJxUzKS%88ezXgdWg&#qekol)Elvc0+}mn?kf8*ditO%a>2>q@>vQ>Zh2MV${;w& zkU_(jaE2qfKHXD*aq^?(~_x_nRj$* zUK}%Rrzq)-$veJ=xQRfKSIDqFwM0*P9`{+zP5LU@`Y;aomj?3csWIEhWlYLPln{%A zU7@M=S~6>-%~Ff+L#kbq2Nc9O(MX8M@E;=~Q6?(VwzXzSUJ~U1C>@{CB@yTxk^-E~ z@jJcM&yZFeUqV{B42z%B4p!QMu==pRXLlcIKgsXF-RNz^?8@S-&Y^*;_$6FzMp)5v zd6F<_!_ZA**tGQ_n#<5O)>E^i3%|0j!pL39ay@f}_JvFH)A8Et3+8Fg(2M6(Y>cxW&us$p~a(#e|6r5qjAvpK`O&t~h+jBkSgdK}>b!TF?ZdH diff --git a/__pycache__/model.cpython-38.pyc b/__pycache__/model.cpython-38.pyc index 075a5cf0b528df3eec75211bdcd9976c4da32e78..b3619500fb1e5b7c5b98c37328573fe8cc6ccc50 100644 GIT binary patch delta 242 zcmdlSb0~&4l$V!_0SK1lx1>01UvpI%0l$V!_0SHzkx1>02?~)>#@MpCQbm%9v3v4lwPga`K@`fgC^5U9+2vJlasVv85d1nq5W5P0Z<@{D>WrOH9jXXDK)1^ z0;FOVh>!#lw|G*D63gTBQcKG7i?S!5)aev$0Le9jh%OK@6-2C@oUS{Caq{Fpx^4id CWk0w8 diff --git a/__pycache__/orm.cpython-38.pyc b/__pycache__/orm.cpython-38.pyc index f54f93fa9789285cb63dd066539ab808c9b5e728..e7f1513e7b5022c1453677dacaca495e5265a3af 100644 GIT binary patch delta 404 zcmZ23`%acOl$V!_0SKfDT2kh3 z0ArP~Yehk7QD$yxUWs0Od{JsaQGC3grsCu$tal}fc!5f838rNhQ)@-gu+@-RcN0FW&NgdmbnDl zz-lyk1-Cw9@#GuaK8)UzRe5|^TtE_b>{6^CLsKVD;ZbGu+PsTLoDnF0iPxUdYqAhu O52vz#gn$qi(5(P{tzb?7 delta 286 zcmaDSyIhtxl$V!_0SIc6TT*m4@&+(7>P?PgUL+})!k)s>%#^~C!rIFeC6daT3Kf~m z$Rf+gHd&rUUlmo2RH}3eX9`yecM4B0bCgU9Zwg-vLzL|1#VlrwjP8?fu_`jkP5#4r zck)Lzk;xM5J+cNsYdILX82OlZ7SOCZt0>RBk*~1taohHk0wlc;~Uc~vH(R=bF zt}jv^Kux#Uie!M?A{P+hJb3}P2wMP%=|0(x(|Gb*ZbQbx$?`ltjGmKo yczjr#fKrni*`-)PMkG(Z&7;cbv6+!qoDnE5$!E{#F*%a2hf`5NLO_TM=qdooyFh6G diff --git a/__pycache__/product.cpython-38.pyc b/__pycache__/product.cpython-38.pyc index e37a3c68315af6c34c768089390cffd314bcbd77..5a8864c59bec77492656540a25042d036251aadb 100644 GIT binary patch delta 20 acmaFH^^A)8U&jF diff --git a/controller_db.py b/controller_db.py index dfe5de2..c62fa65 100644 --- a/controller_db.py +++ b/controller_db.py @@ -75,7 +75,8 @@ class ControllerDB: # list_dct = [{'133': ['1.4.4.1']}] # list_dct = [{'2': ['1.1.3']}] # list_dct = [{'135': ['1.3.2.1']}] - list_dct = [{'79': ['2.1.3.4']}] + # list_dct = [{'79': ['2.1.3.4']}] + list_dct = [{'99': ['1.3.3']}] # fill g_bom BomNodes = pd.read_csv('BomNodes.csv', index_col=0) @@ -94,7 +95,7 @@ class ControllerDB: df_xv = pd.read_csv("xv_without_exp.csv", index_col=None) # read the OA table df_oa = pd.read_csv("oa_without_exp.csv", index_col=None) - df_oa = df_oa.iloc[:, 0:10] + df_oa = df_oa.iloc[:, 0:df_xv.shape[1]] for idx_scenario, row in df_oa.iterrows(): dct_exp_para = {} for idx_col, para_level in enumerate(row): @@ -112,10 +113,11 @@ 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_req_prf_size, - firm_acc_prf_size, netw_sply_prf_n, - netw_sply_prf_size, cap_limit, diff_new_conn, - diff_remove, proactive_ratio): + n_max_trial, crit_supplier, + firm_req_prf_size, firm_req_prf_conn, + firm_acc_prf_size, firm_acc_prf_conn, + netw_sply_prf_n, netw_sply_prf_size, cap_limit, + diff_new_conn, diff_remove, proactive_ratio): e = Experiment( idx_scenario=idx_scenario, idx_init_removal=idx_init_removal, @@ -126,7 +128,9 @@ class ControllerDB: n_max_trial=n_max_trial, crit_supplier=crit_supplier, firm_req_prf_size=firm_req_prf_size, + firm_req_prf_conn=firm_req_prf_conn, firm_acc_prf_size=firm_acc_prf_size, + firm_acc_prf_conn=firm_acc_prf_conn, netw_sply_prf_n=netw_sply_prf_n, netw_sply_prf_size=netw_sply_prf_size, cap_limit=cap_limit, diff --git a/firm.py b/firm.py index ca8f8d1..e865c72 100644 --- a/firm.py +++ b/firm.py @@ -25,7 +25,9 @@ class FirmAgent(ap.Agent): # para self.flt_crit_supplier = float(self.p.crit_supplier) self.flt_firm_req_prf_size = float(self.p.firm_req_prf_size) + self.is_firm_req_prf_conn = bool(self.p.firm_req_prf_conn) self.flt_firm_acc_prf_size = float(self.p.firm_acc_prf_size) + self.is_firm_acc_prf_conn = bool(self.p.firm_acc_prf_conn) self.flt_diff_new_conn = float(self.p.diff_new_conn) def remove_edge_to_cus_remove_cus_up_prod(self, remove_product): @@ -78,20 +80,22 @@ class FirmAgent(ap.Agent): continue # select based on connection lst_firm_connect = [] - for firm in self.dct_cand_alt_supply_up_prod_removed[product]: - out_edges = self.model.firm_network.graph.out_edges( - self.model.firm_network.positions[firm], keys=True) - in_edges = self.model.firm_network.graph.in_edges( - self.model.firm_network.positions[firm], keys=True) - lst_adj_firm = [] - lst_adj_firm += \ - [ap.AgentIter(self.model, edge[1]).to_list()[ - 0].code for edge in out_edges] - lst_adj_firm += \ - [ap.AgentIter(self.model, edge[0]).to_list()[ - 0].code for edge in in_edges] - if self.code in lst_adj_firm: - lst_firm_connect.append(firm) + if self.is_firm_req_prf_conn: + for firm in \ + self.dct_cand_alt_supply_up_prod_removed[product]: + out_edges = self.model.firm_network.graph.out_edges( + self.model.firm_network.positions[firm], keys=True) + in_edges = self.model.firm_network.graph.in_edges( + self.model.firm_network.positions[firm], keys=True) + lst_adj_firm = [] + lst_adj_firm += \ + [ap.AgentIter(self.model, edge[1]).to_list()[ + 0].code for edge in out_edges] + lst_adj_firm += \ + [ap.AgentIter(self.model, edge[0]).to_list()[ + 0].code for edge in in_edges] + if self.code in lst_adj_firm: + lst_firm_connect.append(firm) if len(lst_firm_connect) == 0: # select based on size lst_size_damp = \ @@ -106,8 +110,8 @@ 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_acc_prf_size - for size in lst_firm_connect.revenue_log] + [firm.revenue_log ** self.flt_firm_acc_prf_size + for firm in lst_firm_connect] lst_prob = \ [size_damp / sum(lst_firm_size_damp) for size_damp in lst_firm_size_damp] @@ -150,25 +154,30 @@ class FirmAgent(ap.Agent): elif len(lst_firm) > 1: # handling based on connection lst_firm_connect = [] - for firm in lst_firm: - out_edges = self.model.firm_network.graph.out_edges( - self.model.firm_network.positions[firm], keys=True) - in_edges = self.model.firm_network.graph.in_edges( - self.model.firm_network.positions[firm], keys=True) - lst_adj_firm = [] - lst_adj_firm += \ - [ap.AgentIter(self.model, edge[1]).to_list()[ - 0].code for edge in out_edges] - lst_adj_firm += \ - [ap.AgentIter(self.model, edge[0]).to_list()[ - 0].code for edge in in_edges] - if self.code in lst_adj_firm: - lst_firm_connect.append(firm) + if self.is_firm_acc_prf_conn: + for firm in lst_firm: + out_edges = \ + self.model.firm_network.graph.out_edges( + self.model.firm_network.positions[firm], + keys=True) + in_edges = \ + self.model.firm_network.graph.in_edges( + self.model.firm_network.positions[firm], + keys=True) + lst_adj_firm = [] + lst_adj_firm += \ + [ap.AgentIter(self.model, edge[1]).to_list()[ + 0].code for edge in out_edges] + lst_adj_firm += \ + [ap.AgentIter(self.model, edge[0]).to_list()[ + 0].code for edge in in_edges] + if self.code in lst_adj_firm: + lst_firm_connect.append(firm) if len(lst_firm_connect) == 0: # handling based on size lst_firm_size_damp = \ - [size ** self.flt_firm_acc_prf_size - for size in lst_firm.revenue_log] + [firm.revenue_log ** self.flt_firm_acc_prf_size + for firm in lst_firm] lst_prob = \ [size_damp / sum(lst_firm_size_damp) for size_damp in lst_firm_size_damp] @@ -178,8 +187,8 @@ 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_acc_prf_size - for size in lst_firm_connect.revenue_log] + [firm.revenue_log ** self.flt_firm_acc_prf_size + for firm in lst_firm_connect] lst_prob = \ [size_damp / sum(lst_firm_size_damp) for size_damp in lst_firm_size_damp] diff --git a/model.py b/model.py index 956334c..6b9aa4a 100644 --- a/model.py +++ b/model.py @@ -277,7 +277,7 @@ class Model(ap.Model): break # draw network - # self.draw_network() + self.draw_network() def update(self): self.a_lst_total_firms.clean_before_time_step() diff --git a/orm.py b/orm.py index e9f115b..b40cc32 100644 --- a/orm.py +++ b/orm.py @@ -57,7 +57,9 @@ class Experiment(Base): n_max_trial = Column(Integer, nullable=False) crit_supplier = Column(DECIMAL(8, 4), nullable=False) firm_req_prf_size = Column(DECIMAL(8, 4), nullable=False) + firm_req_prf_conn = Column(Boolean, nullable=False) firm_acc_prf_size = Column(DECIMAL(8, 4), nullable=False) + firm_acc_prf_conn = Column(Boolean, 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 --git a/xv_with_exp.csv b/xv_with_exp.csv index 8a2314d..60acfd7 100644 --- a/xv_with_exp.csv +++ b/xv_with_exp.csv @@ -1,4 +1,4 @@ -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 +n_max_trial,crit_supplier,firm_req_prf_size,firm_req_prf_conn,firm_acc_prf_size,firm_acc_prf_conn,netw_sply_prf_size,netw_pref_supp_size,cap_limit,diff_new_conn,diff_remove,proactive_ratio +15,2,2,True,2,True,0.5,2,4,0.5,0.5,0.4 +10,1,1,False,1,False,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 63fb0b8..e9ca291 100644 --- a/xv_without_exp.csv +++ b/xv_without_exp.csv @@ -1,2 +1,2 @@ -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 +n_max_trial,crit_supplier,firm_req_prf_size,firm_req_prf_conn,firm_acc_prf_size,firm_acc_prf_conn,netw_sply_prf_n,netw_sply_prf_size,cap_limit,diff_new_conn,diff_remove,proactive_ratio +10,1,1,True,1,True,1,1,2,1,1,0.2