ysights.models.Agents

class ysights.models.Agents[source]

A container class for managing a collection of Agent objects.

This class provides methods to add agents to the collection and retrieve the list of agents. It serves as a convenient way to group and manipulate multiple agents from a YSocial simulation.

Variables:

agents (list) – Internal list storing all Agent objects

Example

Managing a collection of agents:

from ysights import YDataHandler
from ysights.models.Agents import Agents, Agent

# Create an agents collection
agents = Agents()

# Add agents to the collection
row1 = (1, 'alice', None, None, 'user', 'left', 25, 0.7, 0.6, 0.8, 0.5, 0.4,
        0.5, 'en', None, 'college', 0, 0.5, 'female', 'USA', 0.1, False,
        None, 3.5, 'teacher')
agent1 = Agent(row1)
agents.add_agent(agent1)

# Or retrieve from database
ydh = YDataHandler('path/to/database.db')
all_agents = ydh.agents()

# Get list of all agents
agent_list = all_agents.get_agents()
print(f"Total agents: {len(agent_list)}")

# Iterate through agents
for agent in agent_list:
    print(f"{agent.username}: {agent.role}")

See also

Agent: Individual agent class ysights.models.YDataHandler.YDataHandler.agents(): Retrieve agents from database

__init__()[source]

Initialize an empty Agents collection.

Methods

__init__()

Initialize an empty Agents collection.

add_agent(agent)

Add an agent to the collection.

get_agents()

Retrieve the list of all agents in the collection.

__init__()[source]

Initialize an empty Agents collection.

add_agent(agent)[source]

Add an agent to the collection.

Parameters:

agent (Agent) – The Agent object to add to the collection

Example:

agents = Agents()
agent = Agent(row_data)
agents.add_agent(agent)
get_agents()[source]

Retrieve the list of all agents in the collection.

Returns:

List of all Agent objects in this collection

Return type:

list[Agent]

Example:

agents = Agents()
# ... add agents ...
agent_list = agents.get_agents()
for agent in agent_list:
    print(agent.username)