From 586272c9231d0c12919d67a9d27c841c1c34e1f4 Mon Sep 17 00:00:00 2001 From: HaoYizhi Date: Tue, 7 Mar 2023 12:29:27 +0800 Subject: [PATCH] main --- .vscode/launch.json | 2 +- __pycache__/firm.cpython-38.pyc | Bin 4502 -> 4700 bytes firm.py | 6 +++- main.py | 52 ++++++++++++++++++++++++++++++++ model.py | 15 +++++++-- 5 files changed, 70 insertions(+), 5 deletions(-) create mode 100644 main.py diff --git a/.vscode/launch.json b/.vscode/launch.json index 92afbfc..fa990d4 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -8,7 +8,7 @@ "name": "Python: Current File", "type": "python", "request": "launch", - "program": "C:\\Users\\ASUS\\OneDrive\\Project\\ScrAbm\\Dissertation\\IIabm\\model.py", + // "program": "C:\\Users\\ASUS\\OneDrive\\Project\\ScrAbm\\Dissertation\\IIabm\\model.py", "console": "integratedTerminal", "justMyCode": true } diff --git a/__pycache__/firm.cpython-38.pyc b/__pycache__/firm.cpython-38.pyc index a00e0e1a9acdd3fd1b8419f7113b0bd28dc91b51..3b52083e5266e081ef1254ad21c8b76c0cab871f 100644 GIT binary patch delta 293 zcmbQHd`E>hl$V!_0SH((v8BA4$eYOMGBMwlCxx$tA&N7FKbS#NVB>~1CdNyX&6zbA zS4>V|E)l3<$l~i@$YM=luVK&PYi8N}fVqf?QDk#4n=u#T%E|2lLG{UuATyx=#AX3v zXCN+?0uq@FH4O0#C5#K0fJQN=Gb{ws@hm9}!3;&rKxs|ZA`u`}#1A3_KmnVTvSUtE$}&;yh#25DtrWMiySn7mg&f*U9a tmh;o(ntVsVjx7)nV4_O63n2= 1, 'Number of jobs should >= 1' + + # prefix_file_name = 'conf_db_prefix.yaml' + # if os.path.exists(prefix_file_name): + # os.remove(prefix_file_name) + # with open(prefix_file_name, 'w', encoding='utf-8') as file: + # yaml.dump({'db_name_prefix': args.exp}, file) + + # from controller_db import ControllerDB + # controller_db = ControllerDB(args.exp, reset_flag=args.reset) + # controller_db.reset_db() + + # controller_db.prepare_list_sample() + + # close_all_sessions() + + # process_list = [] + # for i in range(int(args.job)): + # p = Process(target=do_computation, args=(controller_db,)) + # p.start() + # process_list.append(p) + + # for i in process_list: + # i.join() diff --git a/model.py b/model.py index d83fdb6..e59a18f 100644 --- a/model.py +++ b/model.py @@ -8,9 +8,15 @@ from product import ProductAgent sample = 0 seed = 0 -n_iter = 3 +n_iter = 10 # dct_list_init_remove_firm_prod = {133: ['1.4.4.1'], 2: ['1.1.3']} +# dct_list_init_remove_firm_prod = { +# 135: ['1.3.2.1'], +# 133: ['1.4.4.1'], +# 2: ['1.1.3'] +# } dct_list_init_remove_firm_prod = { + 140: ['1.4.5.1'], 135: ['1.3.2.1'], 133: ['1.4.4.1'], 2: ['1.1.3'] @@ -177,6 +183,7 @@ class Model(ap.Model): self.draw_network() def update(self): + self.a_list_total_firms.clean_before_time_step() # stop simulation if reached terminal number of iteration if self.t == self.int_n_iter or len( self.dct_list_remove_firm_prod) == 0: @@ -232,6 +239,7 @@ class Model(ap.Model): self.dct_list_remove_firm_prod = {} for firm in self.a_list_total_firms: if len(firm.a_list_up_product_removed) > 0: + print(firm.name, 'a_list_up_product_removed', [product.code for product in firm.a_list_up_product_removed]) for product in firm.a_list_product: n_up_product_removed = 0 for up_product_removed in firm.a_list_up_product_removed: @@ -251,8 +259,9 @@ class Model(ap.Model): 1) / (max(list_revenue_log) - min(list_revenue_log) + 1) p_remove = 1 - std_size * (1 - lost_percent) - flag = self.nprandom.choice([1, 0], - p=[p_remove, 1 - p_remove]) + # flag = self.nprandom.choice([1, 0], + # p=[p_remove, 1 - p_remove]) + flag = 1 if flag == 1: firm.a_list_product_removed.append(product) # if firm in