Movement of actors¶
In progress
This document is a work in progress if you see any errors, or exclusions or have any problems, please get in touch with us.
In [1]:
Copied!
from abses import Actor, MainModel
# create a testing model
model = MainModel(name="actor_example", base="tests")
layer = model.nature.create_module(how="from_resolution", shape=(3, 3))
actor = model.agents.new(Actor, singleton=True)
from abses import Actor, MainModel
# create a testing model
model = MainModel(name="actor_example", base="tests")
layer = model.nature.create_module(how="from_resolution", shape=(3, 3))
actor = model.agents.new(Actor, singleton=True)
In [2]:
Copied!
# however, we can let it settle down on a specific position of the earth.
pos = (1, 1)
settled = actor.move.to(pos=pos, layer=layer)
actor.pos # position of the actor now: (4, 4)
actor.on_earth # True
# however, we can let it settle down on a specific position of the earth.
pos = (1, 1)
settled = actor.move.to(pos=pos, layer=layer)
actor.pos # position of the actor now: (4, 4)
actor.on_earth # True
Out[2]:
True
Let's see where the actor is located at...
layer.apply
is a useful method when you want to apply a function to all the cells in a layer. As all the cells have a method agents.has()
to show how many agents are in the cell, we can use this method to count the number of agents in the layer.
In [3]:
Copied!
import matplotlib.pyplot as plt
def show_position():
_, ax = plt.subplots(figsize=(2, 2))
ax.imshow(layer.apply(lambda c: c.agents.has()))
plt.show()
show_position()
import matplotlib.pyplot as plt
def show_position():
_, ax = plt.subplots(figsize=(2, 2))
ax.imshow(layer.apply(lambda c: c.agents.has()))
plt.show()
show_position()
Now, we can move the actor to a new location.
Good movement!
Now, let's move the actor to a new location randomly, with a keyword arg radius=2
.
As you see! The single agent can be moved very easily to a new location.