model+firm
This commit is contained in:
parent
9449550c2d
commit
2941f020e4
Binary file not shown.
13
firm.py
13
firm.py
|
@ -1,6 +1,15 @@
|
||||||
import agentpy as ap
|
import agentpy as ap
|
||||||
|
|
||||||
|
|
||||||
class Firm(ap.Agent):
|
class FirmAgent(ap.Agent):
|
||||||
def setup(self):
|
def setup(self, code, name, type_region, revenue_log):
|
||||||
self.firm_network = self.model.firm_network
|
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
|
||||||
|
|
||||||
|
|
52
model.py
52
model.py
|
@ -2,16 +2,25 @@ import agentpy as ap
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import networkx as nx
|
import networkx as nx
|
||||||
|
from firm import FirmAgent
|
||||||
|
|
||||||
sample = 0
|
sample = 0
|
||||||
sample = 0
|
seed = 0
|
||||||
dct_sample_para = {'sample': sample, 'seed': sample}
|
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):
|
class Model(ap.Model):
|
||||||
def setup(self):
|
def setup(self):
|
||||||
self.sample = self.p.sample
|
self.sample = self.p.sample
|
||||||
self.nprandom = np.random.default_rng(self.p.seed)
|
self.nprandom = np.random.default_rng(self.p.seed)
|
||||||
|
self.int_n_iter = int(self.p.n_iter)
|
||||||
|
|
||||||
# init graph bom
|
# init graph bom
|
||||||
BomNodes = pd.read_csv('BomNodes.csv', index_col=0)
|
BomNodes = pd.read_csv('BomNodes.csv', index_col=0)
|
||||||
|
@ -79,6 +88,43 @@ class Model(ap.Model):
|
||||||
# print('-'*20)
|
# print('-'*20)
|
||||||
|
|
||||||
self.firm_network = ap.Network(self, G_Firm)
|
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):
|
def draw_network(self):
|
||||||
import matplotlib.pyplot as plt
|
import matplotlib.pyplot as plt
|
||||||
|
@ -102,4 +148,4 @@ class Model(ap.Model):
|
||||||
|
|
||||||
model = Model(dct_sample_para)
|
model = Model(dct_sample_para)
|
||||||
model.setup()
|
model.setup()
|
||||||
model.draw_network()
|
# model.draw_network()
|
||||||
|
|
BIN
network.png
BIN
network.png
Binary file not shown.
Before Width: | Height: | Size: 4.3 MiB After Width: | Height: | Size: 4.3 MiB |
Loading…
Reference in New Issue