handling request based on connection
This commit is contained in:
parent
082864814b
commit
1072d4e2b0
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
40
firm.py
40
firm.py
|
@ -107,15 +107,37 @@ class FirmAgent(ap.Agent):
|
||||||
self.accept_request(lst_firm[0], product)
|
self.accept_request(lst_firm[0], product)
|
||||||
elif len(lst_firm) > 1:
|
elif len(lst_firm) > 1:
|
||||||
# handling based on connection
|
# handling based on connection
|
||||||
# TBC
|
lst_firm_connect = []
|
||||||
# handling based on size
|
for firm in lst_firm:
|
||||||
lst_firm_size = [firm.revenue_log for firm in lst_firm]
|
out_edges = self.model.firm_network.graph.out_edges(
|
||||||
lst_prob = [
|
self.model.firm_network.positions[firm], keys=True)
|
||||||
size / sum(lst_firm_size) for size in lst_firm_size
|
in_edges = self.model.firm_network.graph.in_edges(
|
||||||
]
|
self.model.firm_network.positions[firm], keys=True)
|
||||||
select_customer = self.model.nprandom.choice(lst_firm,
|
lst_adj_firm = []
|
||||||
p=lst_prob)
|
lst_adj_firm += [ap.AgentIter(self.model, edge[1]).to_list()[0].code for edge in out_edges]
|
||||||
self.accept_request(select_customer, product)
|
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
|
||||||
|
if len(lst_firm_connect) == 0:
|
||||||
|
# handling based on 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)
|
||||||
|
self.accept_request(select_customer, product)
|
||||||
|
elif len(lst_firm_connect) == 1:
|
||||||
|
self.accept_request(lst_firm_connect[0], product)
|
||||||
|
elif len(lst_firm_connect) > 1:
|
||||||
|
# handling based on size of firm that has connection
|
||||||
|
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)
|
||||||
|
self.accept_request(select_customer, product)
|
||||||
|
|
||||||
def accept_request(self, down_firm, product):
|
def accept_request(self, down_firm, product):
|
||||||
lst_firm_size = [
|
lst_firm_size = [
|
||||||
|
|
2
main.py
2
main.py
|
@ -37,6 +37,8 @@ if __name__ == '__main__':
|
||||||
from controller_db import ControllerDB
|
from controller_db import ControllerDB
|
||||||
controller_db = ControllerDB(args.exp, reset_flag=args.reset)
|
controller_db = ControllerDB(args.exp, reset_flag=args.reset)
|
||||||
# controller_db.reset_db()
|
# controller_db.reset_db()
|
||||||
|
|
||||||
|
# force drop
|
||||||
controller_db.reset_db(force_drop=True)
|
controller_db.reset_db(force_drop=True)
|
||||||
|
|
||||||
controller_db.prepare_list_sample()
|
controller_db.prepare_list_sample()
|
||||||
|
|
4
model.py
4
model.py
|
@ -137,10 +137,6 @@ class Model(ap.Model):
|
||||||
# draw network
|
# draw network
|
||||||
# self.draw_network()
|
# self.draw_network()
|
||||||
|
|
||||||
out_file = open("myfile.json", "w")
|
|
||||||
json.dump(nx.adjacency_data(G_Firm), out_file)
|
|
||||||
out_file.close()
|
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
self.a_lst_total_firms.clean_before_time_step()
|
self.a_lst_total_firms.clean_before_time_step()
|
||||||
# output
|
# output
|
||||||
|
|
File diff suppressed because one or more lines are too long
BIN
network.png
BIN
network.png
Binary file not shown.
Before Width: | Height: | Size: 3.0 MiB After Width: | Height: | Size: 3.0 MiB |
Loading…
Reference in New Issue