Networks

Base and Factory

class terrarium.networks.base.CommunicationNetwork(graph, consolidate_channels_enabled=False)[source]

Bases: object

A NetworkX-backed communication network.

Convention used across Terrarium:

  • Nodes are agent names (strings).

  • Edges are potential pairwise connections; blackboard channels are derived from this graph via channel_groups().

Parameters:
  • graph (Graph)

  • consolidate_channels_enabled (bool)

channel_groups()[source]

Return communication channel groups (blackboard participants) for this network.

Return type:

List[List[str]]

consolidate_channels()[source]

Return a greedy clique-based channel cover as communication channels.

Example: A complete graph with n nodes/agents –> one channel/blackboard with all n agents.

Algorithm:

  • Repeatedly find a clique (size >= 3), create a multi-participant channel for it, remove those nodes, and repeat.

  • When no cliques (size >= 3) remain, create one channel per remaining edge.

  • Finally, ensure the resulting channel graph is connected by adding a small number of pairwise channels that connect otherwise-disconnected channel components (preferring edges that existed in the original graph).

Notes:

  • This is an NP-hard problem, so finding an optimal solution is not feasible.

  • This algorithm may dominate computation time for large graphs.

  • Clique selection is greedy: pick the largest clique each iteration.

  • Clique channels are vertex-disjoint, but connectivity edges added at the end may cause some agents to participate in multiple channels.

Return type:

List[List[str]]

save_plot(path, *, seed=None)[source]

Save a PNG visualization of this network graph to the given path.

Parameters:
Return type:

Path

validate_agents(agent_names)[source]

Validate that the network nodes match the given agent names.

Parameters:

agent_names (Sequence[str])

Return type:

None

terrarium.networks.factory.build_communication_network(agent_names, config)[source]

Build a CommunicationNetwork from config.

Supported config keys:

  • communication_network.topology (required) Values: complete | path | star | erdos_renyi | watts_strogatz | barabasi_albert

  • communication_network.consolidate_channels (optional bool; default false)

  • communication_network.center (only for star; agent name or integer index)

  • communication_network.edge_prob (erdos_renyi; float in [0, 1])

  • communication_network.k (watts_strogatz; even int < num_agents)

  • communication_network.rewire_prob (watts_strogatz; float in [0, 1])

  • communication_network.m (barabasi_albert; int in [1, num_agents-1])

  • random graph seed is taken from simulation.seed for random graph families

Parameters:
Return type:

CommunicationNetwork

Topologies

class terrarium.networks.complete.CompleteNetwork(agent_names, *, consolidate_channels=False)[source]

Bases: CommunicationNetwork

Fully-connected (clique) communication network.

Parameters:
  • agent_names (Sequence[str])

  • consolidate_channels (bool)

class terrarium.networks.path.PathNetwork(agent_names, *, consolidate_channels=False)[source]

Bases: CommunicationNetwork

Path topology where each agent connects to its immediate neighbours.

Parameters:
  • agent_names (Sequence[str])

  • consolidate_channels (bool)

class terrarium.networks.star.StarNetwork(agent_names, *, center=None, consolidate_channels=False)[source]

Bases: CommunicationNetwork

Star topology with a single hub connected to all other agents.

Parameters:
  • agent_names (Sequence[str])

  • center (Optional[str])

  • consolidate_channels (bool)

class terrarium.networks.erdos_renyi.ErdosRenyiNetwork(agent_names, *, edge_prob, seed=None, consolidate_channels=False)[source]

Bases: CommunicationNetwork

Erdos-Renyi G(n, p) random communication network.

Parameters:
  • agent_names (Sequence[str])

  • edge_prob (float)

  • seed (Optional[int])

  • consolidate_channels (bool)

class terrarium.networks.watts_strogatz.WattsStrogatzNetwork(agent_names, *, k, rewire_prob, seed=None, consolidate_channels=False)[source]

Bases: CommunicationNetwork

Watts-Strogatz small-world communication network.

Parameters:
  • agent_names (Sequence[str])

  • k (int)

  • rewire_prob (float)

  • seed (Optional[int])

  • consolidate_channels (bool)

class terrarium.networks.barabasi_albert.BarabasiAlbertNetwork(agent_names, *, m, seed=None, consolidate_channels=False)[source]

Bases: CommunicationNetwork

Barabasi-Albert preferential attachment communication network.

Parameters:
  • agent_names (Sequence[str])

  • m (int)

  • seed (Optional[int])

  • consolidate_channels (bool)