Network of links between actors¶
This tutorial will show you how to work with social-ecological network with ABSESpy
.
In [1]:
Copied!
from abses import MainModel
model = MainModel()
agents = model.agents.new(num=10)
agents
from abses import MainModel
model = MainModel()
agents = model.agents.new(num=10)
agents
Out[1]:
<ActorsList: (10)Actor>
Import Graph to create agents¶
In [3]:
Copied!
import numpy as np
import networkx as nx
rng = np.random.default_rng()
a = rng.integers(low=0, high=2, size=(10, 10))
DG = nx.from_numpy_array(a, create_using=nx.DiGraph)
nx.draw(DG, arrows=True)
import numpy as np
import networkx as nx
rng = np.random.default_rng()
a = rng.integers(low=0, high=2, size=(10, 10))
DG = nx.from_numpy_array(a, create_using=nx.DiGraph)
nx.draw(DG, arrows=True)
In [4]:
Copied!
nx.to_dict_of_lists(DG)
nx.to_dict_of_lists(DG)
Out[4]:
{0: [5, 7], 1: [0, 1, 9], 2: [0, 2, 3, 7, 8, 9], 3: [0, 2, 6, 8], 4: [0, 1, 3, 7, 8], 5: [4, 5, 9], 6: [1, 5, 7, 8, 9], 7: [0, 1, 2, 5, 6, 8], 8: [0, 1, 4, 5, 7], 9: [2, 3, 6, 8]}
In [5]:
Copied!
from abses import Actor
class NodeActor(Actor):
marker = "^"
nodes = model.agents.new_from_graph(DG, "imported", actor_cls=NodeActor)
nodes
from abses import Actor
class NodeActor(Actor):
marker = "^"
nodes = model.agents.new_from_graph(DG, "imported", actor_cls=NodeActor)
nodes
Out[5]:
<ActorsList: (10)NodeActor>