babylon.engine.systems.community

Community hypergraph system (Feature 022).

Manages the XGI hypergraph layer for n-ary community membership. Provides builder, query, and overlap matrix operations used by the CommunitySystem tick handler.

See also

babylon.models.entities.community: Data models. babylon.formulas.community: Community formulas. Constitution II.7: Edges vs Hyperedges (NetworkX + XGI).

Functions

build_community_hypergraph(memberships, ...)

Build XGI hypergraph where communities are hyperedges.

communities_spanning_axis(H, contradiction)

Find institutional exclusion communities that bridge a contradiction axis.

community_overlap_matrix(H)

Compute pairwise community overlap matrix for all agents.

designate_community(state[, heat_increase])

State designates community — escalates legal status and raises heat.

disrupt_infrastructure(state[, ...])

State disrupts community infrastructure.

infiltrate_community(state[, cohesion_reduction])

State infiltrates community — reduces cohesion.

legal_status_escalate(state)

Escalate legal status by one step (one-way ratchet).

shared_communities(H, agent_a, agent_b)

Return community IDs (hyperedge IDs) shared by both agents.

Classes

CommunitySystem()

Hypergraph community system (Feature 022).

babylon.engine.systems.community.build_community_hypergraph(memberships, community_states)[source]

Build XGI hypergraph where communities are hyperedges.

Each community with at least one member becomes a hyperedge connecting all its member agent IDs. Community state attributes are stored as hyperedge attributes.

Parameters:
Return type:

Hypergraph

Returns:

XGI Hypergraph with agents as nodes and communities as hyperedges.

babylon.engine.systems.community.shared_communities(H, agent_a, agent_b)[source]

Return community IDs (hyperedge IDs) shared by both agents.

Parameters:
  • H (Hypergraph) – Community hypergraph.

  • agent_a (str) – First agent ID.

  • agent_b (str) – Second agent ID.

Return type:

set[Any]

Returns:

Set of community type value strings shared by both agents.

babylon.engine.systems.community.communities_spanning_axis(H, contradiction)[source]

Find institutional exclusion communities that bridge a contradiction axis.

A community spans an axis if it contains members who also belong to communities on both the hegemonic and marginalized sides of that axis.

Parameters:
  • H (Hypergraph) – Community hypergraph.

  • contradiction (Contradiction) – The contradiction to check bridging for.

Return type:

list[CommunityType]

Returns:

List of CommunityType values that bridge the axis.

babylon.engine.systems.community.community_overlap_matrix(H)[source]

Compute pairwise community overlap matrix for all agents.

O[i,j] = number of communities containing both agent_i and agent_j. O[i,i] = degree of agent_i (number of communities they belong to).

Parameters:

H (Hypergraph) – Community hypergraph.

Return type:

tuple[Any, dict[str, int]]

Returns:

Tuple of (overlap_matrix as dense ndarray, node_index mapping agent_id → matrix row/column index).

babylon.engine.systems.community.legal_status_escalate(state)[source]

Escalate legal status by one step (one-way ratchet).

Parameters:

state (CommunityState) – Current community state.

Return type:

CommunityState

Returns:

New CommunityState with legal_status advanced one step. Returns unchanged if already at CRIMINALIZED.

babylon.engine.systems.community.designate_community(state, heat_increase=0.3)[source]

State designates community — escalates legal status and raises heat.

Parameters:
  • state (CommunityState) – Current community state.

  • heat_increase (float) – Amount to add to heat.

Return type:

CommunityState

Returns:

New CommunityState with escalated legal status and increased heat.

babylon.engine.systems.community.infiltrate_community(state, cohesion_reduction=0.2)[source]

State infiltrates community — reduces cohesion.

Parameters:
  • state (CommunityState) – Current community state.

  • cohesion_reduction (float) – Amount to subtract from cohesion.

Return type:

CommunityState

Returns:

New CommunityState with reduced cohesion.

babylon.engine.systems.community.disrupt_infrastructure(state, infrastructure_reduction=0.4)[source]

State disrupts community infrastructure.

Parameters:
  • state (CommunityState) – Current community state.

  • infrastructure_reduction (float) – Amount to subtract from infrastructure.

Return type:

CommunityState

Returns:

New CommunityState with reduced infrastructure.

class babylon.engine.systems.community.CommunitySystem[source]

Bases: object

Hypergraph community system (Feature 022).

Manages alpha-smoothed community state decay, solidarity potential computation from community overlap, threat score aggregation, and reproduction cost modification. Runs before SolidaritySystem in the engine pipeline (position 6).

name = 'community'
step(graph, services, _context)[source]

Execute community system for one tick.

Parameters:
  • graph (nx.DiGraph[str] | Any)

  • services (Any)

  • _context (Any)

Return type:

None