first normal run
This commit is contained in:
parent
1072d4e2b0
commit
6489ecff90
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -1 +1 @@
|
|||
db_name_prefix: test
|
||||
db_name_prefix: not_test
|
||||
|
|
|
@ -52,9 +52,10 @@ class ControllerDB:
|
|||
dct = {code: [product_code]}
|
||||
list_dct.append(dct)
|
||||
# list_dct = [{'140': ['1.4.5.1']}]
|
||||
list_dct = [{'133': ['1.4.4.1']}]
|
||||
# list_dct = [{'133': ['1.4.4.1']}]
|
||||
# list_dct = [{'2': ['1.1.3']}]
|
||||
# list_dct = [{'135': ['1.3.2.1']}]
|
||||
# list_dct = [{'79': ['2.1.3.4']}]
|
||||
|
||||
# fill g_bom
|
||||
BomNodes = pd.read_csv('BomNodes.csv', index_col=0)
|
||||
|
|
34
firm.py
34
firm.py
|
@ -44,8 +44,8 @@ class FirmAgent(ap.Agent):
|
|||
if self.model.nprandom.choice([True, False],
|
||||
p=[prod_remove,
|
||||
1 - prod_remove]):
|
||||
print(self.name, remove_product.code, 'affect',
|
||||
customer.name)
|
||||
# print(self.name, remove_product.code, 'affect',
|
||||
# customer.name)
|
||||
if remove_product not in \
|
||||
customer.a_lst_up_product_removed:
|
||||
customer.a_lst_up_product_removed.append(
|
||||
|
@ -55,7 +55,7 @@ class FirmAgent(ap.Agent):
|
|||
|
||||
def seek_alt_supply(self):
|
||||
for product in self.a_lst_up_product_removed:
|
||||
print(f"{self.name} seek alt supply for {product.code}")
|
||||
# print(f"{self.name} seek alt supply for {product.code}")
|
||||
if self.dct_n_trial_up_product_removed[
|
||||
product] <= self.model.int_n_max_trial:
|
||||
# select a list of candidate firm that has the product
|
||||
|
@ -73,9 +73,9 @@ class FirmAgent(ap.Agent):
|
|||
]
|
||||
select_alt_supply = self.model.nprandom.choice(
|
||||
candidate_alt_supply, p=lst_prob)
|
||||
print(
|
||||
f"{self.name} selct alt supply for {product.code} from {select_alt_supply.name}"
|
||||
)
|
||||
# print(
|
||||
# f"{self.name} selct alt supply for {product.code} from {select_alt_supply.name}"
|
||||
# )
|
||||
assert product in select_alt_supply.a_lst_product, \
|
||||
f"{select_alt_supply} \
|
||||
does not produce requested product {product}"
|
||||
|
@ -88,17 +88,17 @@ class FirmAgent(ap.Agent):
|
|||
select_alt_supply.dct_request_prod_from_firm[product] = [
|
||||
self
|
||||
]
|
||||
print(
|
||||
select_alt_supply.name, 'dct_request_prod_from_firm', {
|
||||
key.code: [v.name for v in value]
|
||||
for key, value in
|
||||
select_alt_supply.dct_request_prod_from_firm.items()
|
||||
})
|
||||
# print(
|
||||
# select_alt_supply.name, 'dct_request_prod_from_firm', {
|
||||
# key.code: [v.name for v in value]
|
||||
# for key, value in
|
||||
# select_alt_supply.dct_request_prod_from_firm.items()
|
||||
# })
|
||||
|
||||
self.dct_n_trial_up_product_removed[product] += 1
|
||||
|
||||
def handle_request(self):
|
||||
print(self.name, 'handle_request')
|
||||
# print(self.name, 'handle_request')
|
||||
for product, lst_firm in self.dct_request_prod_from_firm.items():
|
||||
if self.dct_prod_capacity[product] > 0:
|
||||
if len(lst_firm) == 0:
|
||||
|
@ -117,7 +117,7 @@ class FirmAgent(ap.Agent):
|
|||
lst_adj_firm += [ap.AgentIter(self.model, edge[1]).to_list()[0].code for edge in out_edges]
|
||||
lst_adj_firm += [ap.AgentIter(self.model, edge[0]).to_list()[0].code for edge in in_edges]
|
||||
if self.code in lst_adj_firm:
|
||||
lst_firm_connect += firm
|
||||
lst_firm_connect.append(firm)
|
||||
if len(lst_firm_connect) == 0:
|
||||
# handling based on size
|
||||
lst_firm_size = [firm.revenue_log for firm in lst_firm]
|
||||
|
@ -156,9 +156,9 @@ class FirmAgent(ap.Agent):
|
|||
self.dct_prod_capacity[product] -= 1
|
||||
self.dct_request_prod_from_firm[product].remove(down_firm)
|
||||
down_firm.a_lst_up_product_removed.remove(product)
|
||||
print(
|
||||
f"{self.name} accept {product.code} request from {down_firm.name}"
|
||||
)
|
||||
# print(
|
||||
# f"{self.name} accept {product.code} request from {down_firm.name}"
|
||||
# )
|
||||
|
||||
def clean_before_trial(self):
|
||||
self.dct_request_prod_from_firm = {}
|
||||
|
|
7
main.py
7
main.py
|
@ -23,7 +23,8 @@ if __name__ == '__main__':
|
|||
parser = argparse.ArgumentParser(description='setting')
|
||||
parser.add_argument('--exp', type=str, default='test')
|
||||
parser.add_argument('--job', type=int, default='3')
|
||||
parser.add_argument('--reset', type=int, default='0')
|
||||
parser.add_argument('--reset_sample', type=int, default='0')
|
||||
parser.add_argument('--reset_db', type=bool, default=False)
|
||||
|
||||
args = parser.parse_args()
|
||||
assert args.job >= 1, 'Number of jobs should >= 1'
|
||||
|
@ -35,11 +36,11 @@ if __name__ == '__main__':
|
|||
yaml.dump({'db_name_prefix': args.exp}, file)
|
||||
|
||||
from controller_db import ControllerDB
|
||||
controller_db = ControllerDB(args.exp, reset_flag=args.reset)
|
||||
controller_db = ControllerDB(args.exp, reset_flag=args.reset_sample)
|
||||
# controller_db.reset_db()
|
||||
|
||||
# force drop
|
||||
controller_db.reset_db(force_drop=True)
|
||||
controller_db.reset_db(force_drop=args.reset_db)
|
||||
|
||||
controller_db.prepare_list_sample()
|
||||
|
||||
|
|
54
model.py
54
model.py
|
@ -107,7 +107,6 @@ class Model(ap.Model):
|
|||
for product in firm_agent.a_lst_product:
|
||||
firm_agent.dct_prod_capacity[product] = self.nprandom.integers(
|
||||
firm_agent.revenue_log / 5, firm_agent.revenue_log / 5 + 2)
|
||||
# print(firm_agent.name, firm_agent.dct_prod_capacity)
|
||||
|
||||
self.firm_network.add_agents([firm_agent], [ag_node])
|
||||
self.a_lst_total_firms = ap.AgentList(self, self.firm_network.agents)
|
||||
|
@ -152,12 +151,12 @@ class Model(ap.Model):
|
|||
self.stop()
|
||||
|
||||
def step(self):
|
||||
print('\n', '=' * 20, 'step', self.t, '=' * 20)
|
||||
print(
|
||||
'dct_list_remove_firm_prod', {
|
||||
key.name: value.code
|
||||
for key, value in self.dct_lst_remove_firm_prod.items()
|
||||
})
|
||||
# print('\n', '=' * 20, 'step', self.t, '=' * 20)
|
||||
# print(
|
||||
# 'dct_list_remove_firm_prod', {
|
||||
# key.name: value.code
|
||||
# for key, value in self.dct_lst_remove_firm_prod.items()
|
||||
# })
|
||||
|
||||
# remove_edge_to_cus_and_cus_up_prod
|
||||
for firm, a_lst_product in self.dct_lst_remove_firm_prod.items():
|
||||
|
@ -165,7 +164,7 @@ class Model(ap.Model):
|
|||
firm.remove_edge_to_cus_remove_cus_up_prod(product)
|
||||
|
||||
for n_trial in range(self.int_n_max_trial):
|
||||
print('=' * 10, 'trial', n_trial, '=' * 10)
|
||||
# print('=' * 10, 'trial', n_trial, '=' * 10)
|
||||
# seek_alt_supply
|
||||
# shuffle self.a_lst_total_firms
|
||||
self.a_lst_total_firms = self.a_lst_total_firms.shuffle()
|
||||
|
@ -192,9 +191,9 @@ class Model(ap.Model):
|
|||
self.dct_lst_disrupt_firm_prod = {}
|
||||
for firm in self.a_lst_total_firms:
|
||||
if len(firm.a_lst_up_product_removed) > 0:
|
||||
print(firm.name, 'a_lst_up_product_removed', [
|
||||
product.code for product in firm.a_lst_up_product_removed
|
||||
])
|
||||
# print(firm.name, 'a_lst_up_product_removed', [
|
||||
# product.code for product in firm.a_lst_up_product_removed
|
||||
# ])
|
||||
for product in firm.a_lst_product:
|
||||
n_up_product_removed = 0
|
||||
for up_product_removed in firm.a_lst_up_product_removed:
|
||||
|
@ -232,24 +231,24 @@ class Model(ap.Model):
|
|||
firm] = ap.AgentList(
|
||||
self.model, [product])
|
||||
|
||||
print(
|
||||
'dct_list_remove_firm_prod', {
|
||||
key.name: value.code
|
||||
for key, value in self.dct_lst_remove_firm_prod.items()
|
||||
})
|
||||
# print(
|
||||
# 'dct_list_remove_firm_prod', {
|
||||
# key.name: value.code
|
||||
# for key, value in self.dct_lst_remove_firm_prod.items()
|
||||
# })
|
||||
|
||||
def end(self):
|
||||
print('/' * 20, 'output', '/' * 20)
|
||||
print('dct_list_remove_firm_prod')
|
||||
for t, dct in self.lst_dct_lst_remove_firm_prod:
|
||||
for firm, a_lst_product in dct.items():
|
||||
for product in a_lst_product:
|
||||
print(t, firm.name, product.code)
|
||||
print('dct_lst_disrupt_firm_prod')
|
||||
for t, dct in self.lst_dct_lst_disrupt_firm_prod:
|
||||
for firm, a_lst_product in dct.items():
|
||||
for product in a_lst_product:
|
||||
print(t, firm.name, product.code)
|
||||
# print('/' * 20, 'output', '/' * 20)
|
||||
# print('dct_list_remove_firm_prod')
|
||||
# for t, dct in self.lst_dct_lst_remove_firm_prod:
|
||||
# for firm, a_lst_product in dct.items():
|
||||
# for product in a_lst_product:
|
||||
# print(t, firm.name, product.code)
|
||||
# print('dct_lst_disrupt_firm_prod')
|
||||
# for t, dct in self.lst_dct_lst_disrupt_firm_prod:
|
||||
# for firm, a_lst_product in dct.items():
|
||||
# for product in a_lst_product:
|
||||
# print(t, firm.name, product.code)
|
||||
|
||||
qry_result = db_session.query(Result).filter_by(s_id=self.sample.id)
|
||||
if qry_result.count() == 0:
|
||||
|
@ -288,7 +287,6 @@ class Model(ap.Model):
|
|||
prog="twopi",
|
||||
args="")
|
||||
node_label = nx.get_node_attributes(self.firm_network.graph, 'Name')
|
||||
# print(node_label)
|
||||
node_degree = dict(self.firm_network.graph.out_degree())
|
||||
node_label = {
|
||||
key: f"{node_label[key]} {node_degree[key]}"
|
||||
|
|
Loading…
Reference in New Issue