diff --git a/__pycache__/controller_db.cpython-38.pyc b/__pycache__/controller_db.cpython-38.pyc index 3c0bb02..5c25c25 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 e66c462..a7484a1 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 95e447c..aeb2b87 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 d7e552a..4c7a771 100644 Binary files a/__pycache__/orm.cpython-38.pyc and b/__pycache__/orm.cpython-38.pyc differ diff --git a/firm.py b/firm.py index 5a30250..211caac 100644 --- a/firm.py +++ b/firm.py @@ -24,9 +24,9 @@ class FirmAgent(ap.Agent): # para self.flt_crit_supplier = float(self.p.crit_supplier) - self.flt_firm_req_prf_size = float(self.p.firm_req_prf_size) + self.is_firm_req_prf_size = bool(self.p.firm_req_prf_size) self.is_firm_req_prf_conn = bool(self.p.firm_req_prf_conn) - self.flt_firm_acc_prf_size = float(self.p.firm_acc_prf_size) + self.is_firm_acc_prf_size = bool(self.p.firm_acc_prf_size) self.is_firm_acc_prf_conn = bool(self.p.firm_acc_prf_conn) self.flt_diff_new_conn = float(self.p.diff_new_conn) @@ -97,27 +97,34 @@ class FirmAgent(ap.Agent): if self.code in lst_adj_firm: lst_firm_connect.append(firm) if len(lst_firm_connect) == 0: - # select based on size - lst_size_damp = \ - [size ** self.flt_firm_req_prf_size for size in - self.dct_cand_alt_supply_up_prod_removed[ - product].revenue_log] - lst_prob = [size_damp / sum(lst_size_damp) - for size_damp in lst_size_damp] - select_alt_supply = self.model.nprandom.choice( - self.dct_cand_alt_supply_up_prod_removed[product], - p=lst_prob) + # select based on size or not + if self.is_firm_req_prf_size: + lst_size = \ + [size for size in + self.dct_cand_alt_supply_up_prod_removed[ + product].revenue_log] + lst_prob = [size / sum(lst_size) + for size in lst_size] + select_alt_supply = self.model.nprandom.choice( + self.dct_cand_alt_supply_up_prod_removed[product], + p=lst_prob) + else: + select_alt_supply = self.model.nprandom.choice( + self.dct_cand_alt_supply_up_prod_removed[product]) elif len(lst_firm_connect) > 0: - # select based on size of firm that has connection - lst_firm_size_damp = \ - [firm.revenue_log ** self.flt_firm_acc_prf_size - for firm in lst_firm_connect] - lst_prob = \ - [size_damp / sum(lst_firm_size_damp) - for size_damp in lst_firm_size_damp] - select_alt_supply = \ - self.model.nprandom.choice(lst_firm_connect, - p=lst_prob) + # select based on size of connected firm or not + if self.is_firm_req_prf_size: + lst_firm_size = \ + [firm.revenue_log for firm in lst_firm_connect] + lst_prob = \ + [size / sum(lst_firm_size) + for size in lst_firm_size] + select_alt_supply = \ + self.model.nprandom.choice(lst_firm_connect, + p=lst_prob) + else: + select_alt_supply = \ + self.model.nprandom.choice(lst_firm_connect) # print( # f"{self.name} selct alt supply for {product.code} " # f"from {select_alt_supply.name}" @@ -174,27 +181,34 @@ class FirmAgent(ap.Agent): if self.code in lst_adj_firm: lst_firm_connect.append(firm) if len(lst_firm_connect) == 0: - # handling based on size - lst_firm_size_damp = \ - [firm.revenue_log ** self.flt_firm_acc_prf_size - for firm in lst_firm] - lst_prob = \ - [size_damp / sum(lst_firm_size_damp) - for size_damp in lst_firm_size_damp] - select_customer = \ - self.model.nprandom.choice(lst_firm, p=lst_prob) + # handling based on size or not + if self.is_firm_acc_prf_size: + lst_firm_size = \ + [firm.revenue_log for firm in lst_firm] + lst_prob = \ + [size / sum(lst_firm_size) + for size in lst_firm_size] + select_customer = \ + self.model.nprandom.choice(lst_firm, + p=lst_prob) + else: + select_customer = \ + self.model.nprandom.choice(lst_firm) self.accept_request(select_customer, product) elif len(lst_firm_connect) > 0: - # handling based on size of firm that has connection - lst_firm_size_damp = \ - [firm.revenue_log ** self.flt_firm_acc_prf_size - for firm in lst_firm_connect] - lst_prob = \ - [size_damp / sum(lst_firm_size_damp) - for size_damp in lst_firm_size_damp] - select_customer = \ - self.model.nprandom.choice(lst_firm_connect, - p=lst_prob) + # handling based on size of connected firm or not + if self.is_firm_acc_prf_size: + lst_firm_size = \ + [firm.revenue_log for firm in lst_firm_connect] + lst_prob = \ + [size / sum(lst_firm_size) + for size in lst_firm_size] + select_customer = \ + self.model.nprandom.choice(lst_firm_connect, + p=lst_prob) + else: + select_customer = \ + self.model.nprandom.choice(lst_firm_connect) self.accept_request(select_customer, product) def accept_request(self, down_firm, product): diff --git a/orm.py b/orm.py index b09be55..ff53deb 100644 --- a/orm.py +++ b/orm.py @@ -55,11 +55,11 @@ class Experiment(Base): g_bom = Column(Text(4294000000), nullable=False) n_max_trial = Column(Integer, nullable=False) - firm_req_prf_size = Column(DECIMAL(8, 4), nullable=False) + firm_req_prf_size = Column(Boolean, nullable=False) firm_req_prf_conn = Column(Boolean, nullable=False) cap_limit_prob_type = Column(String(16), nullable=False) cap_limit_level = Column(DECIMAL(8, 4), nullable=False) - firm_acc_prf_size = Column(DECIMAL(8, 4), nullable=False) + firm_acc_prf_size = Column(Boolean, nullable=False) firm_acc_prf_conn = Column(Boolean, nullable=False) diff_new_conn = Column(DECIMAL(8, 4), nullable=False) crit_supplier = Column(DECIMAL(8, 4), nullable=False) diff --git a/xv_with_exp.csv b/xv_with_exp.csv index 179456b..dc9bfa7 100644 --- a/xv_with_exp.csv +++ b/xv_with_exp.csv @@ -1,4 +1,4 @@ n_max_trial,firm_req_prf_size,firm_req_prf_conn,cap_limit_prob_type,cap_limit_level,firm_acc_prf_size,firm_acc_prf_conn,diff_new_conn,crit_supplier,diff_remove,proactive_ratio,netw_sply_prf_n,netw_sply_prf_size,netw_cust_prf_n,netw_cust_prf_size -15,2,TRUE,uniform,5,2,TRUE,0.3,2,0.5,0.4,3,TRUE,3,TRUE -10,1,FALSE,normal,10,1,FALSE,0.5,1,1,0.6,2,FALSE,2,FALSE -5,0.5,,,15,0.5,,0.7,0.5,2,0.8,1,,1, +15,TRUE,TRUE,uniform,5,TRUE,TRUE,0.3,2,0.5,0.4,3,TRUE,3,TRUE +10,FALSE,FALSE,normal,10,FALSE,FALSE,0.5,1,1,0.6,2,FALSE,2,FALSE +5,,,,15,,,0.7,0.5,2,0.8,1,,1, diff --git a/xv_without_exp.csv b/xv_without_exp.csv index d3b73b5..d521c6b 100644 --- a/xv_without_exp.csv +++ b/xv_without_exp.csv @@ -1,20 +1,2 @@ n_max_trial,firm_req_prf_size,firm_req_prf_conn,cap_limit_prob_type,cap_limit_level,firm_acc_prf_size,firm_acc_prf_conn,diff_new_conn,crit_supplier,diff_remove,proactive_ratio,netw_sply_prf_n,netw_sply_prf_size,netw_cust_prf_n,netw_cust_prf_size -10,1,TRUE,uniform,10,1,TRUE,0.7,1,1,0.9,2,TRUE,2,TRUE -,,,,,,,,,,,,,, -,,,,,,,,,,,,,, -,,,,,,,,,,,,,, -n_max_trial,,,,,,,,,,,,,, -firm_req_prf_size,,,,,,,,,,,,,, -firm_req_prf_conn,,,,,,,,,,,,,, -cap_limit_prob_type,,,,,,,,,,,,,, -cap_limit_level,,,,,,,,,,,,,, -firm_acc_prf_size,,,,,,,,,,,,,, -firm_acc_prf_conn,,,,,,,,,,,,,, -diff_new_conn,,,,,,,,,,,,,, -crit_supplier,,,,,,,,,,,,,, -diff_remove,,,,,,,,,,,,,, -proactive_ratio,,,,,,,,,,,,,, -netw_sply_prf_n,,,,,,,,,,,,,, -netw_sply_prf_size,,,,,,,,,,,,,, -netw_cust_prf_n,,,,,,,,,,,,,, -netw_cust_prf_size,,,,,,,,,,,,,, +10,TRUE,TRUE,uniform,10,TRUE,TRUE,0.7,1,1,0.9,2,TRUE,2,TRUE