cap prob type and level

This commit is contained in:
HaoYizhi 2023-06-10 21:26:35 +08:00
parent 7a08a52f3f
commit 3b9252d93d
9 changed files with 35 additions and 16 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -116,7 +116,8 @@ class ControllerDB:
n_max_trial, crit_supplier, n_max_trial, crit_supplier,
firm_req_prf_size, firm_req_prf_conn, firm_req_prf_size, firm_req_prf_conn,
firm_acc_prf_size, firm_acc_prf_conn, firm_acc_prf_size, firm_acc_prf_conn,
netw_sply_prf_n, netw_sply_prf_size, cap_limit, netw_sply_prf_n, netw_sply_prf_size,
cap_limit_prob_type, cap_limit_level,
diff_new_conn, diff_remove, proactive_ratio): diff_new_conn, diff_remove, proactive_ratio):
e = Experiment( e = Experiment(
idx_scenario=idx_scenario, idx_scenario=idx_scenario,
@ -133,7 +134,8 @@ class ControllerDB:
firm_acc_prf_conn=firm_acc_prf_conn, firm_acc_prf_conn=firm_acc_prf_conn,
netw_sply_prf_n=netw_sply_prf_n, netw_sply_prf_n=netw_sply_prf_n,
netw_sply_prf_size=netw_sply_prf_size, netw_sply_prf_size=netw_sply_prf_size,
cap_limit=cap_limit, cap_limit_prob_type=cap_limit_prob_type,
cap_limit_level=cap_limit_level,
diff_new_conn=diff_new_conn, diff_new_conn=diff_new_conn,
diff_remove=diff_remove, diff_remove=diff_remove,
proactive_ratio=proactive_ratio proactive_ratio=proactive_ratio

View File

@ -21,7 +21,8 @@ class Model(ap.Model):
self.int_n_max_trial = int(self.p.n_max_trial) self.int_n_max_trial = int(self.p.n_max_trial)
self.flt_netw_sply_prf_n = float(self.p.netw_sply_prf_n) self.flt_netw_sply_prf_n = float(self.p.netw_sply_prf_n)
self.flt_netw_sply_prf_size = float(self.p.netw_sply_prf_size) self.flt_netw_sply_prf_size = float(self.p.netw_sply_prf_size)
self.flt_cap_limit = int(self.p.cap_limit) 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.flt_diff_remove = float(self.p.diff_remove)
self.proactive_ratio = float(self.p.proactive_ratio) self.proactive_ratio = float(self.p.proactive_ratio)
@ -143,12 +144,25 @@ class Model(ap.Model):
code in attr['Product_Code'] code in attr['Product_Code']
for code in self.a_lst_total_products.code for code in self.a_lst_total_products.code
])) ]))
# init extra capacity based on discrete uniform distribution
for product in firm_agent.a_lst_product: for product in firm_agent.a_lst_product:
firm_agent.dct_prod_capacity[product] = \ # init extra capacity based on discrete uniform distribution
self.nprandom.integers(firm_agent.revenue_log / 5, assert self.str_cap_limit_prob_type in ['uniform', 'normal'], \
firm_agent.revenue_log / 5 + "cap_limit_prob_type other than uniform, normal"
self.flt_cap_limit) 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.firm_network.add_agents([firm_agent], [ag_node])
self.a_lst_total_firms = ap.AgentList(self, self.firm_network.agents) self.a_lst_total_firms = ap.AgentList(self, self.firm_network.agents)
@ -277,7 +291,7 @@ class Model(ap.Model):
break 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()

3
orm.py
View File

@ -62,7 +62,8 @@ class Experiment(Base):
firm_acc_prf_conn = Column(Boolean, nullable=False) firm_acc_prf_conn = Column(Boolean, nullable=False)
netw_sply_prf_n = Column(DECIMAL(8, 4), nullable=False) netw_sply_prf_n = Column(DECIMAL(8, 4), nullable=False)
netw_sply_prf_size = Column(DECIMAL(8, 4), nullable=False) netw_sply_prf_size = Column(DECIMAL(8, 4), nullable=False)
cap_limit = Column(Integer, nullable=False) cap_limit_prob_type = Column(String(16), nullable=False)
cap_limit_level = Column(DECIMAL(8, 4), 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) proactive_ratio = Column(DECIMAL(8, 4), nullable=False)

View File

@ -1,4 +1,4 @@
n_max_trial,crit_supplier,firm_req_prf_size,firm_req_prf_conn,firm_acc_prf_size,firm_acc_prf_conn,netw_sply_prf_size,netw_pref_supp_size,cap_limit,diff_new_conn,diff_remove,proactive_ratio n_max_trial,crit_supplier,firm_req_prf_size,firm_req_prf_conn,firm_acc_prf_size,firm_acc_prf_conn,netw_sply_prf_size,netw_pref_supp_size,cap_limit_prob_type,cap_limit_level,diff_new_conn,diff_remove,proactive_ratio
15,2,2,True,2,True,0.5,2,4,0.5,0.5,0.4 15,2,2,True,2,True,0.5,2,uniform,5,0.5,0.5,0.4
10,1,1,False,1,False,1,1,2,1,1,0.6 10,1,1,False,1,False,1,1,normal,10,1,1,0.6
5,0.5,0.5,,0.5,,2,0.5,1,2,2,0.8 5,0.5,0.5,,0.5,,2,0.5,,15,2,2,0.8

1 n_max_trial crit_supplier firm_req_prf_size firm_req_prf_conn firm_acc_prf_size firm_acc_prf_conn netw_sply_prf_size netw_pref_supp_size cap_limit cap_limit_prob_type cap_limit_level diff_new_conn diff_remove proactive_ratio
2 15 2 2 True 2 True 0.5 2 4 uniform 5 0.5 0.5 0.4
3 10 1 1 False 1 False 1 1 2 normal 10 1 1 0.6
4 5 0.5 0.5 0.5 2 0.5 1 15 2 2 0.8

View File

@ -1,2 +1,4 @@
n_max_trial,crit_supplier,firm_req_prf_size,firm_req_prf_conn,firm_acc_prf_size,firm_acc_prf_conn,netw_sply_prf_n,netw_sply_prf_size,cap_limit,diff_new_conn,diff_remove,proactive_ratio n_max_trial,crit_supplier,firm_req_prf_size,firm_req_prf_conn,firm_acc_prf_size,firm_acc_prf_conn,netw_sply_prf_n,netw_sply_prf_size,cap_limit_prob_type,cap_limit_level,diff_new_conn,diff_remove,proactive_ratio
10,1,1,True,1,True,1,1,2,1,1,0.2 10,1,1,True,1,True,1,1,normal,10,1,1,0.2
,,,,,,,,,,,,
,,,,,,,,,,,,

1 n_max_trial crit_supplier firm_req_prf_size firm_req_prf_conn firm_acc_prf_size firm_acc_prf_conn netw_sply_prf_n netw_sply_prf_size cap_limit cap_limit_prob_type cap_limit_level diff_new_conn diff_remove proactive_ratio
2 10 1 1 True 1 True 1 1 2 normal 10 1 1 0.2
3
4