diff --git a/__pycache__/firm.cpython-38.pyc b/__pycache__/firm.cpython-38.pyc new file mode 100644 index 0000000..dfa9a61 Binary files /dev/null and b/__pycache__/firm.cpython-38.pyc differ diff --git a/firm.py b/firm.py index 01dd8b0..2165b14 100644 --- a/firm.py +++ b/firm.py @@ -1,6 +1,15 @@ import agentpy as ap -class Firm(ap.Agent): - def setup(self): +class FirmAgent(ap.Agent): + def setup(self, code, name, type_region, revenue_log): self.firm_network = self.model.firm_network + + self.code = code + self.name = name + self.type_region = type_region + self.revenue_log = revenue_log + + self.is_disrupted = False + + \ No newline at end of file diff --git a/model.py b/model.py index 62c589b..d99882b 100644 --- a/model.py +++ b/model.py @@ -2,16 +2,25 @@ import agentpy as ap import pandas as pd import numpy as np import networkx as nx +from firm import FirmAgent sample = 0 -sample = 0 -dct_sample_para = {'sample': sample, 'seed': sample} +seed = 0 +n_iter = 3 +list_init_remove_firm_code = [0, 2] +dct_sample_para = { + 'sample': sample, + 'seed': seed, + 'n_iter': n_iter, + 'list_init_remove_firm_code': list_init_remove_firm_code +} class Model(ap.Model): def setup(self): self.sample = self.p.sample self.nprandom = np.random.default_rng(self.p.seed) + self.int_n_iter = int(self.p.n_iter) # init graph bom BomNodes = pd.read_csv('BomNodes.csv', index_col=0) @@ -79,6 +88,43 @@ class Model(ap.Model): # print('-'*20) self.firm_network = ap.Network(self, G_Firm) + # print([node.label for node in self.firm_network.nodes]) + # print([list(self.firm_network.graph.predecessors(node)) for node in self.firm_network.nodes]) + # print([self.firm_network.graph.nodes[node.label]['Name'] for node in self.firm_network.nodes]) + # print([v for v in self.firm_network.graph.nodes(data=True)]) + + # init firm + for ag_node, attr in self.firm_network.graph.nodes(data=True): + firm_agent = FirmAgent(self, + code=attr['Code'], + name=attr['Name'], + type_region=attr['Type_Region'], + revenue_log=attr['Revenue_Log']) + self.firm_network.add_agents([firm_agent], [ag_node]) + a_list_total_firms = ap.AgentList(self, self.firm_network.agents) + # set the initial firm that is removed + list_b_is_removed = list( + map(lambda x: x in self.p.list_init_remove_firm_code, + self.firm_network.agents.code)) + self.a_list_firms_removed = a_list_total_firms.select( + list_b_is_removed) + self.a_list_firms_removed.is_removed = True + + def update(self): + # Update list of unhappy people + # self.agents.update_happiness() + # self.unhappy = self.agents.select(self.agents.happy == False) + + # Stop simulation if reached terminal number of iteration + if self.t == self.int_n_iter: + self.stop() + + def step(self): + # Move unhappy people to new location + self.unhappy.find_new_home() + + def end(self): + pass def draw_network(self): import matplotlib.pyplot as plt @@ -102,4 +148,4 @@ class Model(ap.Model): model = Model(dct_sample_para) model.setup() -model.draw_network() +# model.draw_network() diff --git a/network.png b/network.png index 0976a58..0df1efa 100644 Binary files a/network.png and b/network.png differ