main
This commit is contained in:
parent
b291578889
commit
586272c923
|
@ -8,7 +8,7 @@
|
||||||
"name": "Python: Current File",
|
"name": "Python: Current File",
|
||||||
"type": "python",
|
"type": "python",
|
||||||
"request": "launch",
|
"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",
|
"console": "integratedTerminal",
|
||||||
"justMyCode": true
|
"justMyCode": true
|
||||||
}
|
}
|
||||||
|
|
Binary file not shown.
6
firm.py
6
firm.py
|
@ -41,7 +41,7 @@ class FirmAgent(ap.Agent):
|
||||||
]
|
]
|
||||||
# print(select_edges)
|
# print(select_edges)
|
||||||
if len(select_edges) == 0:
|
if len(select_edges) == 0:
|
||||||
print('affect', customer.name, remove_product.code)
|
print(self.name, remove_product.code, 'affect', customer.name)
|
||||||
if remove_product not in \
|
if remove_product not in \
|
||||||
customer.a_list_up_product_removed:
|
customer.a_list_up_product_removed:
|
||||||
customer.a_list_up_product_removed.append(
|
customer.a_list_up_product_removed.append(
|
||||||
|
@ -136,3 +136,7 @@ class FirmAgent(ap.Agent):
|
||||||
|
|
||||||
def clean_before_trial(self):
|
def clean_before_trial(self):
|
||||||
self.dct_request_prod_from_firm = {}
|
self.dct_request_prod_from_firm = {}
|
||||||
|
|
||||||
|
def clean_before_time_step(self):
|
||||||
|
self.dct_num_trial_up_product_removed = {}
|
||||||
|
self.a_list_up_product_removed = ap.AgentList(self.model, [])
|
||||||
|
|
|
@ -0,0 +1,52 @@
|
||||||
|
import os
|
||||||
|
import random
|
||||||
|
import time
|
||||||
|
from multiprocessing import Process
|
||||||
|
import argparse
|
||||||
|
from computation import Computation
|
||||||
|
from sqlalchemy.orm import close_all_sessions
|
||||||
|
|
||||||
|
import yaml
|
||||||
|
|
||||||
|
|
||||||
|
def do_computation(c_db):
|
||||||
|
exp = Computation(c_db)
|
||||||
|
|
||||||
|
while 1:
|
||||||
|
time.sleep(random.uniform(0, 10))
|
||||||
|
is_all_done = exp.run()
|
||||||
|
if is_all_done:
|
||||||
|
break
|
||||||
|
|
||||||
|
|
||||||
|
# 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')
|
||||||
|
|
||||||
|
# args = parser.parse_args()
|
||||||
|
# assert args.job >= 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()
|
15
model.py
15
model.py
|
@ -8,9 +8,15 @@ from product import ProductAgent
|
||||||
|
|
||||||
sample = 0
|
sample = 0
|
||||||
seed = 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 = {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 = {
|
dct_list_init_remove_firm_prod = {
|
||||||
|
140: ['1.4.5.1'],
|
||||||
135: ['1.3.2.1'],
|
135: ['1.3.2.1'],
|
||||||
133: ['1.4.4.1'],
|
133: ['1.4.4.1'],
|
||||||
2: ['1.1.3']
|
2: ['1.1.3']
|
||||||
|
@ -177,6 +183,7 @@ class Model(ap.Model):
|
||||||
self.draw_network()
|
self.draw_network()
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
|
self.a_list_total_firms.clean_before_time_step()
|
||||||
# stop simulation if reached terminal number of iteration
|
# stop simulation if reached terminal number of iteration
|
||||||
if self.t == self.int_n_iter or len(
|
if self.t == self.int_n_iter or len(
|
||||||
self.dct_list_remove_firm_prod) == 0:
|
self.dct_list_remove_firm_prod) == 0:
|
||||||
|
@ -232,6 +239,7 @@ class Model(ap.Model):
|
||||||
self.dct_list_remove_firm_prod = {}
|
self.dct_list_remove_firm_prod = {}
|
||||||
for firm in self.a_list_total_firms:
|
for firm in self.a_list_total_firms:
|
||||||
if len(firm.a_list_up_product_removed) > 0:
|
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:
|
for product in firm.a_list_product:
|
||||||
n_up_product_removed = 0
|
n_up_product_removed = 0
|
||||||
for up_product_removed in firm.a_list_up_product_removed:
|
for up_product_removed in firm.a_list_up_product_removed:
|
||||||
|
@ -251,8 +259,9 @@ class Model(ap.Model):
|
||||||
1) / (max(list_revenue_log) -
|
1) / (max(list_revenue_log) -
|
||||||
min(list_revenue_log) + 1)
|
min(list_revenue_log) + 1)
|
||||||
p_remove = 1 - std_size * (1 - lost_percent)
|
p_remove = 1 - std_size * (1 - lost_percent)
|
||||||
flag = self.nprandom.choice([1, 0],
|
# flag = self.nprandom.choice([1, 0],
|
||||||
p=[p_remove, 1 - p_remove])
|
# p=[p_remove, 1 - p_remove])
|
||||||
|
flag = 1
|
||||||
if flag == 1:
|
if flag == 1:
|
||||||
firm.a_list_product_removed.append(product)
|
firm.a_list_product_removed.append(product)
|
||||||
# if firm in
|
# if firm in
|
||||||
|
|
Loading…
Reference in New Issue