From 6489ecff90d6dbcb30678695d15ab0aaf750e22d Mon Sep 17 00:00:00 2001 From: HaoYizhi Date: Thu, 16 Mar 2023 21:38:57 +0800 Subject: [PATCH] first normal run --- __pycache__/controller_db.cpython-38.pyc | Bin 6642 -> 6614 bytes __pycache__/firm.cpython-38.pyc | Bin 5995 -> 5329 bytes __pycache__/model.cpython-38.pyc | Bin 8604 -> 7705 bytes __pycache__/orm.cpython-38.pyc | Bin 3321 -> 3321 bytes conf_db_prefix.yaml | 2 +- controller_db.py | 3 +- firm.py | 34 +++++++------- main.py | 7 +-- model.py | 54 +++++++++++------------ 9 files changed, 50 insertions(+), 50 deletions(-) diff --git a/__pycache__/controller_db.cpython-38.pyc b/__pycache__/controller_db.cpython-38.pyc index b65e0259b807317e1c9b1c9fa6f0ac8662cec104..c56b41c570d637e34b46a3c735c2e8ce9ded4079 100644 GIT binary patch delta 910 zcmZ{i&rcIk5XX0Rw`EJWKd8_G;!mVlO$?DlO%J9d@-svfP!UupeM{I@Z!abDe-_O@#w{aa_ApmI2aEmoJ`a=TjR|=d@}Q$nVs*xw?A4pT774H zzDh|v?>0kh{f+OT0;%FlWdxuLf2oD2Ev12Zn93@b%anmyfkic&5Zn%hPZyR*tYj65M4|T`_CD-hn!RNV~VkMc$ly_E8Dw~YAU_y^T zFAnL6hO;DsRo-!0B-~lFLqsFRRee>4Q)mWux(0-h!+U{FFz|C=5eBh8*a8z+2oBVa z(b#!`k~=jyW2OwQlEUzN@Wi$Y6gsQj6K2LXI3L3Hst*4pr=J-aLukGDq^cjr@mtk? z$QEltThP!V>M<9OP@BRHtNaaZ^fnWt)y?n``k}oR3NB5?VF;;VnL^c_07pJdN_}gaExnb?p9~Cv^cI zh4;cbu7%^UfLq~2^al00Ij5>ca4gJH1r&&T=mJ|Dy1!;W!> zqt>K9N4M(P#-?LKgp=jR;yHjZ{B2(8WL8$2f;6O{Bxt4#FdH*7`Q27 zb%4-^n^uq1t%pP9x7LdQy?DU33(n(^trz-n-Ijqt{A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!M3Yx3z_02ii-E6nw-1Bsj*xlJA5^%$JbeFYkr7M-BqpGKyYdx+Z@L z?>0}MXjDE9_u3bLB{WLAsoZLBvlyeBR&-4c+nW;_qdMecYN7vN;K8VUVE#L(st2Rw zQcfEThstG38g?J%{&rALIMaO?AI?g;==KbsHDI<&Obl1MtE+nr_LrM<$@Cd#fC#z_ z*49Yj<`q)cup<-K>wp^9azpNX*tMUq5nl%vx|)3B$ywNqZXh+mkmXwnVkWl$Vg|PP z(9_e9IyF~M!A8ut00|Xe^L5bEsuf5BAUuzG+@j(bjK8%yFAGHB(?%mrg@Zak3*wEt z37`2P9szKMRj%PRd4f3(RRC-6Dw(#f4uKr%z@y5S2H{g-KDUUMLZ!*W-$*H247US}l#8wBP7hF-b zdkeN4R&5oMGMOBpwtOXdiT)t(B#+aF^6zA}-%G&LpH%NRac%g*P~kp!sBfis#J5ohS1VJgAve(E2w~75}7#>P|at zVc;2-rxnj}K3U*b3bjdmi^ZTEO!u97TG@=D(#?kX?E5o8B}VZwCY+5_#4Mi-f(U{= ziZWH2i@<#Xt2Q7P)6bhxim#OXK7E>=k$T4$K)>$zu;*3OKaB)SDe#iWBDo|_b-qDg Jly^E`{vT=*(dz&J diff --git a/__pycache__/model.cpython-38.pyc b/__pycache__/model.cpython-38.pyc index e0a4743f9aad773475bade759b66cd59e335ad04..7f4280626424a5ba71302443ed18d3428c4bff08 100644 GIT binary patch delta 1691 zcmaJ>TTC2P7(V~pc6asy1@;14ZlSjYTP>-!jntA9D$oi|3&E`7x-i4a?y~HhokB=v zBnICq26GZ)6HR8{d8iT-(+A%)kq48$ZsNN(KJ?Ki@&9K_gEeuJ{pP=&^Zhgbch1*0 z9*#ukqEVgUulx5lrj4lG6ds{RH``+HhSh7Ivk=nPEm{~7ueASvx%j$nXlv)&E++2=IoVKGgq_CD!+wE z{w6{LY<`KH+XPbt!vxm}h7cM`&0ec!fX`5*;|0Vir`@j_dE0y-W?FCSL5VSk6`2R( zNo#UTa^yMyvl5nW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ET&dJ?w2A%ToyM$w({ERTw>gU#QnDp+Xjp{}KR$YjS@I(o!~z)WoC5)UnY-v}=d;D>oafULJ+u@UGV|lsc)+GIi*=5pDhZ)>L#+8A|^6j_V7<*Vy&E7si24V;9X>t zjh9Ijl?lou-~eUu#zF>ohY5U|d*H=0sC$5G3$R5mPJWA{N~O_(-vf4Vs8|}$7OT5Z z!2)~9i4Jr;zEAYy%PTOxz32becYh0p$lyNl0tu@3B2eRK{(<9e5mlC6;c8`(pR&Yr z}uCID_`plVPu0>-ePRU63gGiS-ek5UfgI zZ6N-i)oPAm`x+q|10nifDnC@d!N6hLM>c8^;_Y@V?E6BTT@>OZhG+wBbXrECs}*jN zqaLN8p4LsFCwWtG{I=gqq}F2QVKie%_`WhNo@A5uZKa($7IU%OVwM3#!;oC`|K@FQ8Vsp3S*Fh6m^p&6VtM_t>5s95jLJRHVUHcboVJ=b|N=rl`o1NXd|5Ll$ouHN63(~%T}!R c2!nXI#j3=8r<9U7C+MpPjl_9*bJ_lX0D`qg_y7O^ diff --git a/__pycache__/orm.cpython-38.pyc b/__pycache__/orm.cpython-38.pyc index 5749e7566d02ea44b6bbaf58f01ea3d3fd524056..4a7776e94e2b45b154cf8209b6e6b9f3fa9e196f 100644 GIT binary patch delta 26 gcmew<`BRcBl$V!_0SJO#Y~)(c!kD~y7mGay0A`X0YybcN delta 26 gcmew<`BRcBl$V!_0SI&tZsc0e!sxtt7mGay0Ad{n00000 diff --git a/conf_db_prefix.yaml b/conf_db_prefix.yaml index 42cedea..c8a49af 100644 --- a/conf_db_prefix.yaml +++ b/conf_db_prefix.yaml @@ -1 +1 @@ -db_name_prefix: test +db_name_prefix: not_test diff --git a/controller_db.py b/controller_db.py index 1af807f..0639dc2 100644 --- a/controller_db.py +++ b/controller_db.py @@ -52,9 +52,10 @@ class ControllerDB: dct = {code: [product_code]} list_dct.append(dct) # list_dct = [{'140': ['1.4.5.1']}] - list_dct = [{'133': ['1.4.4.1']}] + # 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']}] # fill g_bom BomNodes = pd.read_csv('BomNodes.csv', index_col=0) diff --git a/firm.py b/firm.py index d726822..e0e8b45 100644 --- a/firm.py +++ b/firm.py @@ -44,8 +44,8 @@ class FirmAgent(ap.Agent): if self.model.nprandom.choice([True, False], p=[prod_remove, 1 - prod_remove]): - print(self.name, remove_product.code, 'affect', - customer.name) + # print(self.name, remove_product.code, 'affect', + # customer.name) if remove_product not in \ customer.a_lst_up_product_removed: customer.a_lst_up_product_removed.append( @@ -55,7 +55,7 @@ class FirmAgent(ap.Agent): def seek_alt_supply(self): for product in self.a_lst_up_product_removed: - print(f"{self.name} seek alt supply for {product.code}") + # print(f"{self.name} seek alt supply for {product.code}") if self.dct_n_trial_up_product_removed[ product] <= self.model.int_n_max_trial: # select a list of candidate firm that has the product @@ -73,9 +73,9 @@ class FirmAgent(ap.Agent): ] select_alt_supply = self.model.nprandom.choice( candidate_alt_supply, p=lst_prob) - print( - f"{self.name} selct alt supply for {product.code} from {select_alt_supply.name}" - ) + # print( + # f"{self.name} selct alt supply for {product.code} from {select_alt_supply.name}" + # ) assert product in select_alt_supply.a_lst_product, \ f"{select_alt_supply} \ does not produce requested product {product}" @@ -88,17 +88,17 @@ class FirmAgent(ap.Agent): select_alt_supply.dct_request_prod_from_firm[product] = [ self ] - print( - select_alt_supply.name, 'dct_request_prod_from_firm', { - key.code: [v.name for v in value] - for key, value in - select_alt_supply.dct_request_prod_from_firm.items() - }) + # print( + # select_alt_supply.name, 'dct_request_prod_from_firm', { + # key.code: [v.name for v in value] + # for key, value in + # select_alt_supply.dct_request_prod_from_firm.items() + # }) self.dct_n_trial_up_product_removed[product] += 1 def handle_request(self): - print(self.name, 'handle_request') + # print(self.name, 'handle_request') for product, lst_firm in self.dct_request_prod_from_firm.items(): if self.dct_prod_capacity[product] > 0: if len(lst_firm) == 0: @@ -117,7 +117,7 @@ class FirmAgent(ap.Agent): 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 += firm + lst_firm_connect.append(firm) if len(lst_firm_connect) == 0: # handling based on size lst_firm_size = [firm.revenue_log for firm in lst_firm] @@ -156,9 +156,9 @@ class FirmAgent(ap.Agent): self.dct_prod_capacity[product] -= 1 self.dct_request_prod_from_firm[product].remove(down_firm) down_firm.a_lst_up_product_removed.remove(product) - print( - f"{self.name} accept {product.code} request from {down_firm.name}" - ) + # print( + # f"{self.name} accept {product.code} request from {down_firm.name}" + # ) def clean_before_trial(self): self.dct_request_prod_from_firm = {} diff --git a/main.py b/main.py index d8227ce..04618b7 100644 --- a/main.py +++ b/main.py @@ -23,7 +23,8 @@ if __name__ == '__main__': parser = argparse.ArgumentParser(description='setting') parser.add_argument('--exp', type=str, default='test') parser.add_argument('--job', type=int, default='3') - parser.add_argument('--reset', type=int, default='0') + parser.add_argument('--reset_sample', type=int, default='0') + parser.add_argument('--reset_db', type=bool, default=False) args = parser.parse_args() assert args.job >= 1, 'Number of jobs should >= 1' @@ -35,11 +36,11 @@ if __name__ == '__main__': yaml.dump({'db_name_prefix': args.exp}, file) from controller_db import ControllerDB - controller_db = ControllerDB(args.exp, reset_flag=args.reset) + controller_db = ControllerDB(args.exp, reset_flag=args.reset_sample) # controller_db.reset_db() # force drop - controller_db.reset_db(force_drop=True) + controller_db.reset_db(force_drop=args.reset_db) controller_db.prepare_list_sample() diff --git a/model.py b/model.py index 2c2d14e..8015860 100644 --- a/model.py +++ b/model.py @@ -107,7 +107,6 @@ class Model(ap.Model): for product in firm_agent.a_lst_product: firm_agent.dct_prod_capacity[product] = self.nprandom.integers( firm_agent.revenue_log / 5, firm_agent.revenue_log / 5 + 2) - # print(firm_agent.name, firm_agent.dct_prod_capacity) self.firm_network.add_agents([firm_agent], [ag_node]) self.a_lst_total_firms = ap.AgentList(self, self.firm_network.agents) @@ -152,12 +151,12 @@ class Model(ap.Model): self.stop() def step(self): - print('\n', '=' * 20, 'step', self.t, '=' * 20) - print( - 'dct_list_remove_firm_prod', { - key.name: value.code - for key, value in self.dct_lst_remove_firm_prod.items() - }) + # print('\n', '=' * 20, 'step', self.t, '=' * 20) + # print( + # 'dct_list_remove_firm_prod', { + # key.name: value.code + # for key, value in self.dct_lst_remove_firm_prod.items() + # }) # remove_edge_to_cus_and_cus_up_prod for firm, a_lst_product in self.dct_lst_remove_firm_prod.items(): @@ -165,7 +164,7 @@ class Model(ap.Model): firm.remove_edge_to_cus_remove_cus_up_prod(product) for n_trial in range(self.int_n_max_trial): - print('=' * 10, 'trial', n_trial, '=' * 10) + # print('=' * 10, 'trial', n_trial, '=' * 10) # seek_alt_supply # shuffle self.a_lst_total_firms self.a_lst_total_firms = self.a_lst_total_firms.shuffle() @@ -192,9 +191,9 @@ class Model(ap.Model): self.dct_lst_disrupt_firm_prod = {} for firm in self.a_lst_total_firms: if len(firm.a_lst_up_product_removed) > 0: - print(firm.name, 'a_lst_up_product_removed', [ - product.code for product in firm.a_lst_up_product_removed - ]) + # print(firm.name, 'a_lst_up_product_removed', [ + # product.code for product in firm.a_lst_up_product_removed + # ]) for product in firm.a_lst_product: n_up_product_removed = 0 for up_product_removed in firm.a_lst_up_product_removed: @@ -232,24 +231,24 @@ class Model(ap.Model): firm] = ap.AgentList( self.model, [product]) - print( - 'dct_list_remove_firm_prod', { - key.name: value.code - for key, value in self.dct_lst_remove_firm_prod.items() - }) + # print( + # 'dct_list_remove_firm_prod', { + # key.name: value.code + # for key, value in self.dct_lst_remove_firm_prod.items() + # }) def end(self): - print('/' * 20, 'output', '/' * 20) - print('dct_list_remove_firm_prod') - for t, dct in self.lst_dct_lst_remove_firm_prod: - for firm, a_lst_product in dct.items(): - for product in a_lst_product: - print(t, firm.name, product.code) - print('dct_lst_disrupt_firm_prod') - for t, dct in self.lst_dct_lst_disrupt_firm_prod: - for firm, a_lst_product in dct.items(): - for product in a_lst_product: - print(t, firm.name, product.code) + # print('/' * 20, 'output', '/' * 20) + # print('dct_list_remove_firm_prod') + # for t, dct in self.lst_dct_lst_remove_firm_prod: + # for firm, a_lst_product in dct.items(): + # for product in a_lst_product: + # print(t, firm.name, product.code) + # print('dct_lst_disrupt_firm_prod') + # for t, dct in self.lst_dct_lst_disrupt_firm_prod: + # for firm, a_lst_product in dct.items(): + # for product in a_lst_product: + # print(t, firm.name, product.code) qry_result = db_session.query(Result).filter_by(s_id=self.sample.id) if qry_result.count() == 0: @@ -288,7 +287,6 @@ class Model(ap.Model): prog="twopi", args="") node_label = nx.get_node_attributes(self.firm_network.graph, 'Name') - # print(node_label) node_degree = dict(self.firm_network.graph.out_degree()) node_label = { key: f"{node_label[key]} {node_degree[key]}"