proactive strategy exp
This commit is contained in:
parent
bc3c600be0
commit
b55a313c95
|
@ -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;
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -91,10 +91,10 @@ class ControllerDB:
|
||||||
g_product_js = json.dumps(nx.adjacency_data(g_bom))
|
g_product_js = json.dumps(nx.adjacency_data(g_bom))
|
||||||
|
|
||||||
# insert exp
|
# 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
|
# read the OA table
|
||||||
df_oa = pd.read_csv("oa_without_exp.csv", index_col=None)
|
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():
|
for idx_scenario, row in df_oa.iterrows():
|
||||||
dct_exp_para = {}
|
dct_exp_para = {}
|
||||||
for idx_col, para_level in enumerate(row):
|
for idx_col, para_level in enumerate(row):
|
||||||
|
@ -115,7 +115,7 @@ class ControllerDB:
|
||||||
n_max_trial, crit_supplier, firm_pref_request,
|
n_max_trial, crit_supplier, firm_pref_request,
|
||||||
firm_pref_accept, netw_pref_cust_n,
|
firm_pref_accept, netw_pref_cust_n,
|
||||||
netw_pref_cust_size, cap_limit, diff_new_conn,
|
netw_pref_cust_size, cap_limit, diff_new_conn,
|
||||||
diff_remove,):
|
diff_remove, proactive_ratio):
|
||||||
e = Experiment(
|
e = Experiment(
|
||||||
idx_scenario=idx_scenario,
|
idx_scenario=idx_scenario,
|
||||||
idx_init_removal=idx_init_removal,
|
idx_init_removal=idx_init_removal,
|
||||||
|
@ -132,6 +132,7 @@ class ControllerDB:
|
||||||
cap_limit=cap_limit,
|
cap_limit=cap_limit,
|
||||||
diff_new_conn=diff_new_conn,
|
diff_new_conn=diff_new_conn,
|
||||||
diff_remove=diff_remove,
|
diff_remove=diff_remove,
|
||||||
|
proactive_ratio=proactive_ratio
|
||||||
)
|
)
|
||||||
db_session.add(e)
|
db_session.add(e)
|
||||||
db_session.commit()
|
db_session.commit()
|
||||||
|
|
10
model.py
10
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_netw_pref_cust_size = float(self.p.netw_pref_cust_size)
|
||||||
self.flt_cap_limit = int(self.p.cap_limit)
|
self.flt_cap_limit = int(self.p.cap_limit)
|
||||||
self.flt_diff_remove = float(self.p.diff_remove)
|
self.flt_diff_remove = float(self.p.diff_remove)
|
||||||
|
self.proactive_ratio = float(self.p.proactive_ratio)
|
||||||
|
|
||||||
# init graph bom
|
# init graph bom
|
||||||
G_bom = nx.adjacency_graph(json.loads(self.p.g_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)
|
firm.a_lst_product_removed.append(product)
|
||||||
|
|
||||||
# proactive strategy
|
# proactive strategy
|
||||||
proactive_ratio = 1.0
|
|
||||||
# get all the firm prod affected
|
# get all the firm prod affected
|
||||||
for firm, a_lst_product in self.dct_lst_remove_firm_prod.items():
|
for firm, a_lst_product in self.dct_lst_remove_firm_prod.items():
|
||||||
for product in a_lst_product:
|
for product in a_lst_product:
|
||||||
|
@ -198,7 +198,7 @@ class Model(ap.Model):
|
||||||
[lst_affected[i] for i in
|
[lst_affected[i] for i in
|
||||||
self.nprandom.choice(range(len(lst_affected)),
|
self.nprandom.choice(range(len(lst_affected)),
|
||||||
round(len(lst_affected) *
|
round(len(lst_affected) *
|
||||||
proactive_ratio))]
|
self.proactive_ratio))]
|
||||||
|
|
||||||
for firm_code, prod_code in lst_firm_proactive:
|
for firm_code, prod_code in lst_firm_proactive:
|
||||||
pro_firm_prod_code = \
|
pro_firm_prod_code = \
|
||||||
|
@ -266,11 +266,15 @@ class Model(ap.Model):
|
||||||
'Product': di_supp_prod.code
|
'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
|
# change capacity
|
||||||
select_cand.dct_prod_capacity[di_supp_prod] -= 1
|
select_cand.dct_prod_capacity[di_supp_prod] -= 1
|
||||||
|
break
|
||||||
|
|
||||||
# draw network
|
# draw network
|
||||||
self.draw_network()
|
# self.draw_network()
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
self.a_lst_total_firms.clean_before_time_step()
|
self.a_lst_total_firms.clean_before_time_step()
|
||||||
|
|
BIN
network.png
BIN
network.png
Binary file not shown.
Before Width: | Height: | Size: 2.8 MiB After Width: | Height: | Size: 3.6 MiB |
|
@ -1,2 +1,2 @@
|
||||||
X1,X2,X3,X4,X5,X6,X7,X8,X9,X10,X11,X12,X13
|
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
|
||||||
|
|
|
1
orm.py
1
orm.py
|
@ -63,6 +63,7 @@ class Experiment(Base):
|
||||||
cap_limit = Column(Integer, nullable=False)
|
cap_limit = Column(Integer, nullable=False)
|
||||||
diff_new_conn = Column(DECIMAL(8, 4), nullable=False)
|
diff_new_conn = Column(DECIMAL(8, 4), nullable=False)
|
||||||
diff_remove = 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 = relationship(
|
||||||
'Sample', back_populates='experiment', lazy='dynamic')
|
'Sample', back_populates='experiment', lazy='dynamic')
|
||||||
|
|
|
@ -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
|
|
|
@ -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
|
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
|
10,1,1,1,1,1,2,1,1,0
|
||||||
10,1,1,1,1,1,2,1,1
|
|
||||||
5,0.5,0.5,0.5,2,0.5,1,2,2
|
|
|
Loading…
Reference in New Issue