You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm not sure if this is necessarily a bug, but I've found that when I'm using ipysimulate to visualize multiple types of agents, color coding is assigned to agents not by their ID, but by the order they appear in self.agents. In other words, if the order of agents in the model's self.agents does not match the order they were initialized in, then the color of an agent is associated with an entirely different agent's attributes.
It's entirely possible that this was intentional and just could use some more documentation, but it was confusing to me at first so I thought I'd point it out. (I'm also not sure whether this is more of an agentpy or an ipysimulate thing.)
In case there's any confusion, I should note that I also posted about this model in the discussion forums (#22). I've since implemented your suggestions for splitting my agents into multiple spaces, and have been able to get the visualization working using the code you provided. However, I noticed the same color-coding issue I've described happening there too. The code below is from the version of my model where agents are in a single space- at the end I've included some notes on what specifically happened with multiple spaces.
Local setup
OS Catalina 10.15.5, using jupyter notebooks
agentpy version 0.1.2
ipysimulate version 0.2.0
Context:
Below is a part of my model class. The resources, the hive, and the bees are all different types of agents, but they all have a self.state.
class ForagingModel(ap.Model):
"""
ABM simulating a very simplified version of bee foraging behavior
"""
def setup(self):
# Create ground
self.space = ap.Space(self, shape=[self.p.land_size]*2, Torus = False)
# Create flowering plants
self.resources = ap.AgentList(self, self.p.n_resources, Resource)
self.space.add_agents(self.resources, random=True) # Scatter them randomly
self.resources.setup_pos(self.space)
# Create hive
self.hive= ap.AgentList(self, 1, Hive)
self.space.add_agents(self.hive, [(self.p.land_size/2,self.p.land_size/2)], random=False)
# Create bees
self.bees = ap.AgentList(self, self.p.population, Bee)
# Place them at the hive
self.space.add_agents(self.bees, [[self.p.land_size/2,self.p.land_size/2]]*self.p.population , random=False)
self.bees.setup_pos(self.space)
self.agents = self.resources + self.hive + self.bees
I visualized the positions and movement of the agents using
In my model, the bees change their state (ex. inactive, searching, returning), but the hive and the resources do not.
Issue (with agents in one space)
In the above code, the order agents are added to self.agents: self.agents = self.resources + self.hive + self.bees
matches the order they're created, so everything works as expected. The bees change color when they switch between states (ex. when they switch from foraging to returning to the hive), and both the hive and resource agents stay the same color.
However, if I replace this line with: self.agents = self.bees + self.hive + self.resources
then suddenly the resources are changing their colors instead of the bees. If I have more bees than resources, then all the resources change color and a couple of the bees do too. However, those bees have their colors determined by other bees' states (ex. bee 150 might have its color determined by the state of bee 20).
Issue (with agents in two spaces)
As you recommended in the discussion forum, I've since changed my code so that resource and bee agents are placed in separate spaces. Following the code you provided, I've changed my visualization code to include:
I encountered the same type of issue- because I initialize the plants before I create the bees, in the visualization the plants change color according to the states of the bees.
Let me know if any other details or code would be helpful. Thank you so much!
The text was updated successfully, but these errors were encountered:
Indeed, the two inputs for scatterplot simply go through the returned iterators.
If the two iterators don't have the same order of agents, the output will be false.
I'm not sure if this is necessarily a bug, but I've found that when I'm using
ipysimulate
to visualize multiple types of agents, color coding is assigned to agents not by their ID, but by the order they appear in self.agents. In other words, if the order of agents in the model'sself.agents
does not match the order they were initialized in, then the color of an agent is associated with an entirely different agent's attributes.It's entirely possible that this was intentional and just could use some more documentation, but it was confusing to me at first so I thought I'd point it out. (I'm also not sure whether this is more of an
agentpy
or anipysimulate
thing.)In case there's any confusion, I should note that I also posted about this model in the discussion forums (#22). I've since implemented your suggestions for splitting my agents into multiple spaces, and have been able to get the visualization working using the code you provided. However, I noticed the same color-coding issue I've described happening there too. The code below is from the version of my model where agents are in a single space- at the end I've included some notes on what specifically happened with multiple spaces.
Local setup
OS Catalina 10.15.5, using jupyter notebooks
agentpy version 0.1.2
ipysimulate version 0.2.0
Context:
Below is a part of my model class. The resources, the hive, and the bees are all different types of agents, but they all have a
self.state
.I visualized the positions and movement of the agents using
In my model, the bees change their state (ex. inactive, searching, returning), but the hive and the resources do not.
Issue (with agents in one space)
In the above code, the order agents are added to
self.agents
:self.agents = self.resources + self.hive + self.bees
matches the order they're created, so everything works as expected. The bees change color when they switch between states (ex. when they switch from foraging to returning to the hive), and both the hive and resource agents stay the same color.
However, if I replace this line with:
self.agents = self.bees + self.hive + self.resources
then suddenly the resources are changing their colors instead of the bees. If I have more bees than resources, then all the resources change color and a couple of the bees do too. However, those bees have their colors determined by other bees' states (ex. bee 150 might have its color determined by the state of bee 20).
Issue (with agents in two spaces)
As you recommended in the discussion forum, I've since changed my code so that resource and bee agents are placed in separate spaces. Following the code you provided, I've changed my visualization code to include:
I noticed that if I switched the order of
i1
andi2
like:I encountered the same type of issue- because I initialize the plants before I create the bees, in the visualization the plants change color according to the states of the bees.
Let me know if any other details or code would be helpful. Thank you so much!
The text was updated successfully, but these errors were encountered: