Environments
Environment implementations for AMBER framework. Supports different types of spatial and network topologies.
- class ambr.environments.Environment(model)[source]
Bases:
ABCBase class for all environments.
- property df: DataFrame
The model’s current agent DataFrame (always fresh).
- abstractmethod get_distance(agent1_id: int, agent2_id: int) float[source]
Calculate distance between two agents.
- class ambr.environments.GridEnvironment(model, size: int | Tuple[int, ...], torus: bool = False)[source]
Bases:
EnvironmentN-dimensional grid environment with discrete positions.
- get_distance(pos1_or_agent1, pos2_or_agent2) float[source]
Calculate Manhattan distance between two positions or agents.
- get_neighbors(position_or_agent_id, include_diagonal=False, distance=1)[source]
Get neighboring positions or agents.
- Parameters:
position_or_agent_id – Either a position tuple or agent ID
include_diagonal – Whether to include diagonal neighbors
distance – Maximum distance for neighbors
- property height
Get grid height (second dimension if it exists).
- move_agent(agent_id: int, new_position: Position) None[source]
Move an agent to a new grid position.
- property positions
Get all possible positions in the grid.
- property width
Get grid width (first dimension).
- class ambr.environments.NetworkEnvironment(model, graph: Graph | None = None)[source]
Bases:
EnvironmentGraph-based network environment.
- add_edge(node1_or_agent1, node2_or_agent2, **attr) None[source]
Add an edge between two nodes or agents.
- property edges
Get all edges in the network.
- get_clustering(node_or_agent_id=None)[source]
Get clustering coefficient for a node, agent, or the entire network.
- get_distance(node1_or_agent1, node2_or_agent2) float[source]
Calculate shortest path distance between two nodes or agents.
- move_agent(agent_id: int, new_position: Position) None[source]
Move an agent to a new node in the network.
- property nodes
Get all nodes in the network.
- class ambr.environments.Position(coordinates: Tuple[float, ...], topology_type: str)[source]
Bases:
objectRepresents a position in any topology.
- class ambr.environments.SpaceEnvironment(model, bounds: List[Tuple[float, float]], torus: bool = False)[source]
Bases:
EnvironmentN-dimensional continuous space environment.
- get_distance(pos1_or_agent1, pos2_or_agent2) float[source]
Calculate Euclidean distance between two positions or agents.
- get_neighbors(pos_or_agent_id, radius: float) List[int][source]
Get neighboring agents within radius.
AMBER provides several built-in environment types for different spatial and network topologies.
Grid Environment
- class ambr.GridEnvironment(model, size: int | Tuple[int, ...], torus: bool = False)[source]
Bases:
EnvironmentN-dimensional grid environment with discrete positions.
- get_distance(pos1_or_agent1, pos2_or_agent2) float[source]
Calculate Manhattan distance between two positions or agents.
- get_neighbors(position_or_agent_id, include_diagonal=False, distance=1)[source]
Get neighboring positions or agents.
- Parameters:
position_or_agent_id – Either a position tuple or agent ID
include_diagonal – Whether to include diagonal neighbors
distance – Maximum distance for neighbors
- property height
Get grid height (second dimension if it exists).
- move_agent(agent_id: int, new_position: Position) None[source]
Move an agent to a new grid position.
- property positions
Get all possible positions in the grid.
- property width
Get grid width (first dimension).
The GridEnvironment provides a 2D grid-based space where agents can be positioned and move around.
Usage:
# Create a 10x10 grid
grid = am.GridEnvironment(model, size=(10, 10))
# Place an agent
position = grid.random_position()
agent.position = position
# Get neighbors
neighbors = grid.get_neighbors(position)
Space Environment
- class ambr.SpaceEnvironment(model, bounds: List[Tuple[float, float]], torus: bool = False)[source]
Bases:
EnvironmentN-dimensional continuous space environment.
- get_distance(pos1_or_agent1, pos2_or_agent2) float[source]
Calculate Euclidean distance between two positions or agents.
- get_neighbors(pos_or_agent_id, radius: float) List[int][source]
Get neighboring agents within radius.
The SpaceEnvironment provides continuous 2D space with configurable boundaries.
Usage:
# Create continuous space
space = am.SpaceEnvironment(model, bounds=[(0, 100), (0, 100)])
# Place an agent
position = (25.5, 37.2)
agent.position = position
# Get neighbors within radius
neighbors = space.get_neighbors(position, radius=5.0)
Network Environment
- class ambr.NetworkEnvironment(model, graph: Graph | None = None)[source]
Bases:
EnvironmentGraph-based network environment.
- add_edge(node1_or_agent1, node2_or_agent2, **attr) None[source]
Add an edge between two nodes or agents.
- property edges
Get all edges in the network.
- get_clustering(node_or_agent_id=None)[source]
Get clustering coefficient for a node, agent, or the entire network.
- get_distance(node1_or_agent1, node2_or_agent2) float[source]
Calculate shortest path distance between two nodes or agents.
- move_agent(agent_id: int, new_position: Position) None[source]
Move an agent to a new node in the network.
- property nodes
Get all nodes in the network.
The NetworkEnvironment provides graph-based topology for agent interactions.
Usage:
import networkx as nx
# Create network from NetworkX graph
G = nx.erdos_renyi_graph(100, 0.1)
network = am.NetworkEnvironment(model, G)
# Place agent on node
agent.node = 42
# Get connected neighbors
neighbors = network.get_neighbors(42)