Network Projection
A graph-based projection: agents are nodes, edges are typed relationships between pairs of agents. The third projection type in the agent layer's spatial abstraction (alongside ContinuousProjection and GridProjection).
Use this for relationships that aren't about position — friendship networks, contact graphs, communication links, organizational hierarchies. An agent can simultaneously be in a ContinuousProjection (its physical position) and a NetworkProjection (its social contacts) on the same AgentModel.Context, because both abstractions layer over the context's membership rather than owning it.
Directionality:
directed = false (default): connecting
atobis the same as connectingbtoa. neighborsOf returns both ends. edges returns each logical edge once with(from, to)in the order in which it was originally connected.directed = true: an edge has a direction. neighborsOf returns out-neighbors only; inNeighborsOf returns in-neighbors. To connect in both directions, call connect twice.
Weights:
Each edge has a
weight(default 1.0). The unweighted graph algorithms (shortestPath, reachableFrom) ignore weights. User code can read weights via weightOf for its own purposes.
Lifecycle:
Nodes are implicit: any agent in the context can be referenced by connect / disconnect / neighborsOf; no separate "add node" step is needed.
When an agent leaves the context, onAgentLeft drops every edge incident to that agent.
Constructors
Types
Mutable global defaults for NetworkProjection edges.
Properties
Number of nodes that currently have at least one incident edge. Note: an agent in the context with no edges is not counted here. Use AgentModel.Context.size for total membership.
Functions
Snapshot this network as a spatial-layer ksl.modeling.spatial.DistancesModel. The returned model contains one location per node currently in the network (any agent with at least one incident edge) and one distance entry per reachable ordered pair, computed via shortest path (Dijkstra) from each node.
In-degree of agent.
In-neighbors of agent: agents with an edge pointing to agent. For undirected networks this is identical to neighborsOf.
The largest strongly connected component, by size. Ties are broken by the order SCCs are emitted by stronglyConnectedComponents (reverse topological order of the condensation). Returns an empty set if the network has no edges.
All neighbors of agent. For a directed network this is out-neighbors only; for undirected it's all incident agents. Returns an empty set for an agent with no edges.
Called by the AgentModel.Context when agent leaves. Default no-op — projections that track per-agent state (positions, edges) typically override to drop their bookkeeping for the departing agent.
All agents reachable from start via outgoing edges (BFS). Includes start itself. For undirected networks this is the connected component containing start; for directed networks it's the forward-reachable set (also called "out-component"). To get a weakly-connected-component style answer for a directed graph, the caller can union with reachableFrom walking inEdges, or invert the graph.
The strongly connected component containing agent, or null if agent has no incident edges. Cheaper than calling stronglyConnectedComponents when only one SCC is needed, but still O(V + E) in the worst case.
Compute the strongly connected components of this network. A strongly connected component (SCC) is a maximal set of agents where every agent can reach every other agent via directed paths.