diff --git a/SQL_check_num_dis_firm_in_ts.sql b/SQL_check_num_dis_firm_in_ts.sql new file mode 100644 index 0000000..a944a04 --- /dev/null +++ b/SQL_check_num_dis_firm_in_ts.sql @@ -0,0 +1,20 @@ +select * from +(select s_id, ts, count(id) as num_dis_firm from +iiabmdb.with_exp_result +where ts > 0 +group by s_id, ts) as a +where a.num_dis_firm > 3; + +select * from +iiabmdb.with_exp_result +where s_id = '54170'; + +SELECT * FROM iiabmdb.with_exp_sample where id='54170'; +SELECT max(id) FROM iiabmdb.with_exp_sample; + +select * from +(select s_id, id_firm, id_product, ts, count(id) as num_dup from +iiabmdb.with_exp_result +where ts > 0 +group by s_id, id_firm, id_product, ts) as a +where a.num_dup > 1; \ No newline at end of file diff --git a/__pycache__/controller_db.cpython-38.pyc b/__pycache__/controller_db.cpython-38.pyc index 0c0cc3f..ade8257 100644 Binary files a/__pycache__/controller_db.cpython-38.pyc and b/__pycache__/controller_db.cpython-38.pyc differ diff --git a/__pycache__/model.cpython-38.pyc b/__pycache__/model.cpython-38.pyc index bfd7b5b..2255dbb 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 a8311bc..dab8f28 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 b33be48..ad1a454 100644 --- a/controller_db.py +++ b/controller_db.py @@ -91,10 +91,10 @@ class ControllerDB: g_product_js = json.dumps(nx.adjacency_data(g_bom)) # insert exp - df_xv = pd.read_csv("xv.csv", index_col=None) + df_xv = pd.read_csv("xv_without_exp.csv", index_col=None) # read the OA table df_oa = pd.read_csv("oa_without_exp.csv", index_col=None) - df_oa = df_oa.iloc[:, 0:9] + df_oa = df_oa.iloc[:, 0:10] for idx_scenario, row in df_oa.iterrows(): dct_exp_para = {} for idx_col, para_level in enumerate(row): @@ -115,7 +115,7 @@ class ControllerDB: n_max_trial, crit_supplier, firm_pref_request, firm_pref_accept, netw_pref_cust_n, netw_pref_cust_size, cap_limit, diff_new_conn, - diff_remove,): + diff_remove, proactive_ratio): e = Experiment( idx_scenario=idx_scenario, idx_init_removal=idx_init_removal, @@ -132,6 +132,7 @@ class ControllerDB: cap_limit=cap_limit, diff_new_conn=diff_new_conn, diff_remove=diff_remove, + proactive_ratio=proactive_ratio ) db_session.add(e) db_session.commit() diff --git a/model.py b/model.py index ecc181c..90a27d4 100644 --- a/model.py +++ b/model.py @@ -25,6 +25,7 @@ class Model(ap.Model): self.flt_netw_pref_cust_size = float(self.p.netw_pref_cust_size) self.flt_cap_limit = int(self.p.cap_limit) self.flt_diff_remove = float(self.p.diff_remove) + self.proactive_ratio = float(self.p.proactive_ratio) # init graph bom G_bom = nx.adjacency_graph(json.loads(self.p.g_bom)) @@ -172,7 +173,6 @@ class Model(ap.Model): firm.a_lst_product_removed.append(product) # proactive strategy - proactive_ratio = 1.0 # get all the firm prod affected for firm, a_lst_product in self.dct_lst_remove_firm_prod.items(): for product in a_lst_product: @@ -198,7 +198,7 @@ class Model(ap.Model): [lst_affected[i] for i in self.nprandom.choice(range(len(lst_affected)), round(len(lst_affected) * - proactive_ratio))] + self.proactive_ratio))] for firm_code, prod_code in lst_firm_proactive: pro_firm_prod_code = \ @@ -266,11 +266,15 @@ class Model(ap.Model): 'Product': di_supp_prod.code }) ]) + # print(f"proactive add {select_cand.code} to " + # f"{pro_firm.code} " + # f"for {di_supp_code} {di_supp_prod.code}") # change capacity select_cand.dct_prod_capacity[di_supp_prod] -= 1 + break # draw network - self.draw_network() + # self.draw_network() def update(self): self.a_lst_total_firms.clean_before_time_step() diff --git a/network.png b/network.png index 14b92b2..9d6ea41 100644 Binary files a/network.png and b/network.png differ diff --git a/oa_without_exp.csv b/oa_without_exp.csv index a70f612..d810132 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,X11,X12,X13 -1,1,1,1,1,1,1,1,1,1,1,1,1 +0,0,0,0,0,0,0,0,0,0,0,0,0 diff --git a/orm.py b/orm.py index 0d2697e..ee721c8 100644 --- a/orm.py +++ b/orm.py @@ -63,6 +63,7 @@ class Experiment(Base): cap_limit = Column(Integer, nullable=False) diff_new_conn = Column(DECIMAL(8, 4), nullable=False) diff_remove = Column(DECIMAL(8, 4), nullable=False) + proactive_ratio = Column(DECIMAL(8, 4), nullable=False) sample = relationship( 'Sample', back_populates='experiment', lazy='dynamic') diff --git a/xv_with_exp.csv b/xv_with_exp.csv new file mode 100644 index 0000000..43afc2d --- /dev/null +++ b/xv_with_exp.csv @@ -0,0 +1,4 @@ +n_max_trial,crit_supplier,firm_pref_request,firm_pref_accept,netw_pref_cust_n,netw_pref_cust_size,cap_limit,diff_new_conn,diff_remove,proactive_ratio +15,2,2,2,0.5,2,4,0.5,0.5,0.4 +10,1,1,1,1,1,2,1,1,0.6 +5,0.5,0.5,0.5,2,0.5,1,2,2,0.8 diff --git a/xv.csv b/xv_without_exp.csv similarity index 61% rename from xv.csv rename to xv_without_exp.csv index de72a3f..7e20aa7 100644 --- a/xv.csv +++ b/xv_without_exp.csv @@ -1,4 +1,2 @@ -n_max_trial,crit_supplier,firm_pref_request,firm_pref_accept,netw_pref_cust_n,netw_pref_cust_size,cap_limit,diff_new_conn,diff_remove -15,2,2,2,0.5,2,4,0.5,0.5 -10,1,1,1,1,1,2,1,1 -5,0.5,0.5,0.5,2,0.5,1,2,2 +n_max_trial,crit_supplier,firm_pref_request,firm_pref_accept,netw_pref_cust_n,netw_pref_cust_size,cap_limit,diff_new_conn,diff_remove,proactive_ratio +10,1,1,1,1,1,2,1,1,0