diff --git a/__pycache__/controller_db.cpython-38.pyc b/__pycache__/controller_db.cpython-38.pyc index 7682b7f..c779c07 100644 Binary files a/__pycache__/controller_db.cpython-38.pyc and b/__pycache__/controller_db.cpython-38.pyc differ diff --git a/__pycache__/firm.cpython-38.pyc b/__pycache__/firm.cpython-38.pyc index 0d7dc9d..ebcd157 100644 Binary files a/__pycache__/firm.cpython-38.pyc and b/__pycache__/firm.cpython-38.pyc differ diff --git a/__pycache__/model.cpython-38.pyc b/__pycache__/model.cpython-38.pyc index 233a5eb..d65f2ac 100644 Binary files a/__pycache__/model.cpython-38.pyc and b/__pycache__/model.cpython-38.pyc differ diff --git a/__pycache__/orm.cpython-38.pyc b/__pycache__/orm.cpython-38.pyc index 81fd881..cada252 100644 Binary files a/__pycache__/orm.cpython-38.pyc and b/__pycache__/orm.cpython-38.pyc differ diff --git a/controller_db.py b/controller_db.py index 69a6d4a..8c258ac 100644 --- a/controller_db.py +++ b/controller_db.py @@ -129,7 +129,7 @@ class ControllerDB: n_max_trial, prf_size, prf_conn, cap_limit_prob_type, cap_limit_level, diff_new_conn, crit_supplier, diff_remove, - proactive_ratio, netw_prf_n): + proactive_ratio, drop_t, netw_prf_n): e = Experiment( idx_scenario=idx_scenario, idx_init_removal=idx_init_removal, @@ -146,6 +146,7 @@ class ControllerDB: crit_supplier=crit_supplier, diff_remove=diff_remove, proactive_ratio=proactive_ratio, + drop_t=drop_t, netw_prf_n=netw_prf_n ) db_session.add(e) diff --git a/firm.py b/firm.py index 7ddfebc..ba91572 100644 --- a/firm.py +++ b/firm.py @@ -12,7 +12,7 @@ class FirmAgent(ap.Agent): self.type_region = type_region self.revenue_log = revenue_log self.a_lst_product = a_lst_product - self.dct_prod_capacity = dict.fromkeys(self.a_lst_product) + self.dct_prod_capacity = {} # self.a_lst_up_product_removed = ap.AgentList(self.model, []) # self.a_lst_product_disrupted = ap.AgentList(self.model, []) @@ -35,9 +35,32 @@ class FirmAgent(ap.Agent): # para self.is_prf_size = self.model.is_prf_size self.is_prf_conn = bool(self.p.prf_conn) + self.str_cap_limit_prob_type = str(self.p.cap_limit_prob_type) + self.flt_cap_limit_level = float(self.p.cap_limit_level) self.flt_diff_new_conn = float(self.p.diff_new_conn) self.flt_crit_supplier = float(self.p.crit_supplier) + # init extra capacity + for product in self.a_lst_product: + # init extra capacity based on discrete uniform distribution + assert self.str_cap_limit_prob_type in ['uniform', 'normal'], \ + "cap_limit_prob_type other than uniform, normal" + if self.str_cap_limit_prob_type == 'uniform': + extra_cap_mean = \ + self.revenue_log / self.flt_cap_limit_level + extra_cap = self.model.nprandom.integers(extra_cap_mean-2, + extra_cap_mean+2) + extra_cap = 0 if round(extra_cap) < 0 else round(extra_cap) + # print(firm_agent.name, extra_cap) + self.dct_prod_capacity[product] = extra_cap + elif self.str_cap_limit_prob_type == 'normal': + extra_cap_mean = \ + self.revenue_log / self.flt_cap_limit_level + extra_cap = self.model.nprandom.normal(extra_cap_mean, 1) + extra_cap = 0 if round(extra_cap) < 0 else round(extra_cap) + # print(firm_agent.name, extra_cap) + self.dct_prod_capacity[product] = extra_cap + def remove_edge_to_cus_remove_cus_up_prod(self, remove_product): lst_out_edge = list( self.firm_network.graph.out_edges( diff --git a/model.py b/model.py index a0b48fe..6c42b76 100644 --- a/model.py +++ b/model.py @@ -18,10 +18,9 @@ class Model(ap.Model): self.int_n_max_trial = int(self.p.n_max_trial) self.is_prf_size = bool(self.p.prf_size) - self.str_cap_limit_prob_type = str(self.p.cap_limit_prob_type) - self.flt_cap_limit_level = float(self.p.cap_limit_level) self.flt_diff_remove = float(self.p.diff_remove) self.proactive_ratio = float(self.p.proactive_ratio) + self.drop_t = int(self.p.drop_t) self.int_netw_prf_n = int(self.p.netw_prf_n) # init graph bom @@ -203,25 +202,6 @@ class Model(ap.Model): code in attr['Product_Code'] for code in self.a_lst_total_products.code ])) - for product in firm_agent.a_lst_product: - # init extra capacity based on discrete uniform distribution - assert self.str_cap_limit_prob_type in ['uniform', 'normal'], \ - "cap_limit_prob_type other than uniform, normal" - if self.str_cap_limit_prob_type == 'uniform': - extra_cap_mean = \ - firm_agent.revenue_log / self.flt_cap_limit_level - extra_cap = self.nprandom.integers(extra_cap_mean-2, - extra_cap_mean+2) - extra_cap = 0 if round(extra_cap) < 0 else round(extra_cap) - # print(firm_agent.name, extra_cap) - firm_agent.dct_prod_capacity[product] = extra_cap - elif self.str_cap_limit_prob_type == 'normal': - extra_cap_mean = \ - firm_agent.revenue_log / self.flt_cap_limit_level - extra_cap = self.nprandom.normal(extra_cap_mean, 1) - extra_cap = 0 if round(extra_cap) < 0 else round(extra_cap) - # print(firm_agent.name, extra_cap) - firm_agent.dct_prod_capacity[product] = extra_cap self.firm_network.add_agents([firm_agent], [ag_node]) self.a_lst_total_firms = ap.AgentList(self, self.firm_network.agents) @@ -406,6 +386,7 @@ class Model(ap.Model): # seek_alt_supply # shuffle self.a_lst_total_firms self.a_lst_total_firms = self.a_lst_total_firms.shuffle() + is_stop_trial = True for firm in self.a_lst_total_firms: # if len(firm.a_lst_up_product_removed) > 0: # firm.seek_alt_supply() @@ -420,8 +401,12 @@ class Model(ap.Model): lst_seek_prod.append(supply) # commmon supply only seek once lst_seek_prod = list(set(lst_seek_prod)) + if len(lst_seek_prod) > 0: + is_stop_trial = False for supply in lst_seek_prod: firm.seek_alt_supply(supply) + if is_stop_trial: + break # handle_request # shuffle self.a_lst_total_firms diff --git a/oa_without_exp.csv b/oa_without_exp.csv index 66c1886..fcb75bf 100644 --- a/oa_without_exp.csv +++ b/oa_without_exp.csv @@ -1,2 +1,2 @@ -X1,X2,X3,X4,X5,X6,X7,X8,X9,X10 -0,0,0,0,0,0,0,0,0,0 +X1,X2,X3,X4,X5,X6,X7,X8,X9,X10,X11 +0,0,0,0,0,0,0,0,0,0,0 diff --git a/orm.py b/orm.py index c3a25ac..ef29dcf 100644 --- a/orm.py +++ b/orm.py @@ -63,6 +63,7 @@ class Experiment(Base): crit_supplier = Column(DECIMAL(8, 4), nullable=False) diff_remove = Column(DECIMAL(8, 4), nullable=False) proactive_ratio = Column(DECIMAL(8, 4), nullable=False) + drop_t = Column(Integer, nullable=False) netw_prf_n = Column(Integer, nullable=False) sample = relationship( diff --git a/xv_with_exp.csv b/xv_with_exp.csv index 5451536..cae89dc 100644 --- a/xv_with_exp.csv +++ b/xv_with_exp.csv @@ -1,4 +1,4 @@ -n_max_trial,prf_size,prf_conn,cap_limit_prob_type,cap_limit_level,diff_new_conn,crit_supplier,diff_remove,proactive_ratio,netw_prf_n -15,TRUE,TRUE,uniform,5,0.3,2,0.5,0.3,3 -10,FALSE,FALSE,normal,10,0.5,1,1,0.5,2 -5,,,,15,0.7,0.5,2,0.7,1 +n_max_trial,prf_size,prf_conn,cap_limit_prob_type,cap_limit_level,diff_new_conn,crit_supplier,diff_remove,proactive_ratio,drop_t,netw_prf_n +15,TRUE,TRUE,uniform,5,0.3,2,0.5,0.3,3,3 +10,FALSE,FALSE,normal,10,0.5,1,1,0.5,5,2 +5,,,,15,0.7,0.5,2,0.7,7,1 diff --git a/xv_without_exp.csv b/xv_without_exp.csv index 008c91b..4c5fda0 100644 --- a/xv_without_exp.csv +++ b/xv_without_exp.csv @@ -1,2 +1,2 @@ -n_max_trial,prf_size,prf_conn,cap_limit_prob_type,cap_limit_level,diff_new_conn,crit_supplier,diff_remove,proactive_ratio,netw_prf_n -10,TRUE,TRUE,uniform,10,0.1,1,0.01,0,2 +n_max_trial,prf_size,prf_conn,cap_limit_prob_type,cap_limit_level,diff_new_conn,crit_supplier,diff_remove,proactive_ratio,drop_t,netw_prf_n +10,TRUE,TRUE,uniform,10,0.1,1,0.01,0,5,2