Skip to content

RandomActivation scheduler not working after upgrade 2.1 -> 2.2.3 #2006

@profConradi

Description

@profConradi

I upgraded 2.1 to 2.2.3 and in this simple test model RandomActivation scheduler does not work anymore: agent activation is done sequentially.
Furthermore if I not call super().init() in the model class, the first agent is not added to the scheduler. Is this a bug or a mistake on my part?

    class CognitiveAgent(mesa.Agent):
        """Agents make decisions using automatic (e.g., reflexive) versus controlled (e.g., deliberative) cognition,
        interact with each other, and influence the environment (i.e., game payoffs)."""
    
        def __init__(self, unique_id, model):
            # Pass the parameters to the parent class.
            super().__init__(unique_id, model)
    
            # Each agent is defined by a single parameter x that represents its probability of controlled processing
            self.xdx = np.random.uniform(0., 1.)
    
        def step(self):
            # The agent's step will go here.
            # For demonstration purposes we will print the agent's unique_id
            other_agent = self.random.choice(self.model.schedule.agents)
            print(f"I'm {self.unique_id} and I choose {other_agent.unique_id}")
            
    class CognitiveModel(mesa.Model):
        """A model with some number of agents."""
    
        def __init__(self, N):
            super().__init__()
            self.num_agents = N
            self.schedule = mesa.time.RandomActivation(self)
            # Create agents
            for i in range(self.num_agents):
                a = CognitiveAgent(i, self)
                # Add the agent to the scheduler
                print(a,i)
                self.schedule.add(a)
    
        def step(self):
            """Advance the model by one step."""
            # The model's step will go here for now this will call the step method of each agent and print the agent's unique_id
            self.schedule.step() 

Metadata

Metadata

Assignees

Labels

bugRelease notes label

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions