diff --git a/__pycache__/computation.cpython-38.pyc b/__pycache__/computation.cpython-38.pyc index a9c3639..b3f66d9 100644 Binary files a/__pycache__/computation.cpython-38.pyc and b/__pycache__/computation.cpython-38.pyc differ diff --git a/__pycache__/controller_db.cpython-38.pyc b/__pycache__/controller_db.cpython-38.pyc index e923c1b..526c82d 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 6edc95e..46f7a84 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 2d9380b..ddceffa 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 9097824..2005766 100644 Binary files a/__pycache__/orm.cpython-38.pyc and b/__pycache__/orm.cpython-38.pyc differ diff --git a/conf_experiment.yaml b/conf_experiment.yaml index 5e04018..0137445 100644 --- a/conf_experiment.yaml +++ b/conf_experiment.yaml @@ -6,9 +6,7 @@ meta_seed: 0 test: # only for test scenarios n_sample: 1 n_iter: 20 - n_max_trial: 10 not_test: # normal scenarios n_sample: 50 n_iter: 20 - n_max_trial: 10 diff --git a/controller_db.py b/controller_db.py index 0f4052a..4931aa7 100644 --- a/controller_db.py +++ b/controller_db.py @@ -72,20 +72,34 @@ class ControllerDB: g_product_js = json.dumps(nx.adjacency_data(g_bom)) # insert exp - for idx_exp, dct in enumerate(list_dct): - self.add_experiment_1(idx_exp, self.dct_parameter['n_max_trial'], - dct, g_product_js) # same g_bom for all exp - print(f'Inserted experiment for exp {idx_exp}!') + df_xv = pd.read_csv("xv.csv", index_col=None) + # read the OA table + df_oa = pd.read_fwf("oa.csv", index_col=None) + for idx_scenario, row in df_oa.iterrows(): + dct_exp_para = {} + for idx_col, para_level in enumerate(row): + dct_exp_para[df_xv.columns[idx_col]] = \ + df_xv.iloc[para_level, idx_col] + # different initial removal + for idx_init_removal, dct_init_removal in enumerate(list_dct): + self.add_experiment_1(idx_scenario, + idx_init_removal, + dct_init_removal, + g_product_js, + **dct_exp_para) + print(f"Inserted experiment for scenario {idx_scenario}, " + f"init_removal {idx_init_removal}!") - def add_experiment_1(self, idx_exp, n_max_trial, - dct_lst_init_remove_firm_prod, g_bom): + def add_experiment_1(self, idx_scenario, idx_init_removal, + dct_lst_init_remove_firm_prod, g_bom, n_max_trial): e = Experiment( - idx_exp=idx_exp, + idx_scenario=idx_scenario, + idx_init_removal=idx_init_removal, n_sample=int(self.dct_parameter['n_sample']), n_iter=int(self.dct_parameter['n_iter']), - n_max_trial=n_max_trial, dct_lst_init_remove_firm_prod=dct_lst_init_remove_firm_prod, - g_bom=g_bom) + g_bom=g_bom, + n_max_trial=n_max_trial) db_session.add(e) db_session.commit() diff --git a/firm.py b/firm.py index bb4f4e3..05c0b7e 100644 --- a/firm.py +++ b/firm.py @@ -157,6 +157,7 @@ class FirmAgent(ap.Agent): lst_firm_size = [ firm.revenue_log for firm in self.model.a_lst_total_firms if product in firm.a_lst_product + and product not in firm.a_lst_product_removed ] prod_accept = self.revenue_log / sum(lst_firm_size) if self.model.nprandom.choice([True, False], diff --git a/model.py b/model.py index fc6754f..1c47f75 100644 --- a/model.py +++ b/model.py @@ -220,6 +220,10 @@ class Model(ap.Model): lost_percent = n_up_product_removed / len( product.a_predecessors()) lst_size = self.a_lst_total_firms.revenue_log + lst_size = [firm.revenue_log for firm in self.a_lst_total_firms + if product in firm.a_lst_product + and product not in firm.a_lst_product_removed + ] std_size = (firm.revenue_log - min(lst_size) + 1) / (max(lst_size) - min(lst_size) + 1) prod_remove = 1 - std_size * (1 - lost_percent) diff --git a/oa.csv b/oa.csv new file mode 100644 index 0000000..f2b804b --- /dev/null +++ b/oa.csv @@ -0,0 +1,3 @@ +X1 +0 +1 diff --git a/orm.py b/orm.py index 9779f80..3b90e57 100644 --- a/orm.py +++ b/orm.py @@ -43,16 +43,17 @@ class Experiment(Base): __tablename__ = f"{db_name_prefix}_experiment" id = Column(Integer, primary_key=True, autoincrement=True) - idx_exp = Column(Integer, nullable=False) + idx_scenario = Column(Integer, nullable=False) + idx_init_removal = Column(Integer, nullable=False) # fixed parameters n_sample = Column(Integer, nullable=False) n_iter = Column(Integer, nullable=False) # variables - n_max_trial = Column(Integer, nullable=False) dct_lst_init_remove_firm_prod = Column(PickleType, nullable=False) g_bom = Column(Text(4294000000), nullable=False) + n_max_trial = Column(Integer, nullable=False) sample = relationship( 'Sample', back_populates='experiment', lazy='dynamic') diff --git a/xv.csv b/xv.csv new file mode 100644 index 0000000..1459667 --- /dev/null +++ b/xv.csv @@ -0,0 +1,3 @@ +n_max_trial +5 +10