pub struct GraphSpace { /* private fields */ }Expand description
A graph-based discrete space mirroring Julia Agents.jl GraphSpace.
Each node can hold an arbitrary number of agents. Agents move between nodes along edges. Distance is measured in graph hops.
Supports both directed and undirected graphs. Edges and vertices can be added/removed dynamically at runtime.
§Example: building floor graph
[Floor1-RoomA] --edge-- [Floor1-Corridor] --edge-- [Floor1-RoomB]
|
(stairs)
|
[Floor2-RoomA] --edge-- [Floor2-Corridor] --edge-- [Floor2-RoomB]Each room/corridor/stairwell is a node. Edges connect adjacent spaces.
Implementations§
Source§impl GraphSpace
impl GraphSpace
Sourcepub fn new_directed(n: usize, directed: bool) -> Self
pub fn new_directed(n: usize, directed: bool) -> Self
Create a graph with n nodes. If directed is true, edges are one-way.
Sourcepub fn num_vertices(&self) -> usize
pub fn num_vertices(&self) -> usize
Number of nodes in the graph.
Sourcepub fn num_edges(&self) -> usize
pub fn num_edges(&self) -> usize
Number of edges in the graph.
For undirected graphs, each edge is counted once (not twice).
Sourcepub fn is_directed(&self) -> bool
pub fn is_directed(&self) -> bool
Whether the graph is directed.
Sourcepub fn add_vertex(&mut self) -> GraphPos
pub fn add_vertex(&mut self) -> GraphPos
Add a new vertex and return its index.
Sourcepub fn rem_vertex(&mut self, n: GraphPos) -> bool
pub fn rem_vertex(&mut self, n: GraphPos) -> bool
Remove a vertex by swapping with the last vertex (matches Graphs.jl behavior). All agents at the removed vertex must be removed beforehand. Returns true if successful.
Sourcepub fn add_edge(&mut self, a: GraphPos, b: GraphPos) -> bool
pub fn add_edge(&mut self, a: GraphPos, b: GraphPos) -> bool
Add an edge from a to b. For undirected graphs, also adds b to a.
Sourcepub fn neighbors_out(&self, n: GraphPos) -> &[GraphPos] ⓘ
pub fn neighbors_out(&self, n: GraphPos) -> &[GraphPos] ⓘ
Outgoing neighbors of a node (slice reference, no allocation).
Sourcepub fn neighbors_in(&self, n: GraphPos) -> &[GraphPos] ⓘ
pub fn neighbors_in(&self, n: GraphPos) -> &[GraphPos] ⓘ
Incoming neighbors of a node (slice reference, no allocation).
Sourcepub fn neighbors_all(&self, n: GraphPos) -> Vec<GraphPos> ⓘ
pub fn neighbors_all(&self, n: GraphPos) -> Vec<GraphPos> ⓘ
All neighbors (union of incoming and outgoing), deduplicated.
Sourcepub fn neighbors(&self, n: GraphPos, kind: NeighborType) -> Vec<GraphPos> ⓘ
pub fn neighbors(&self, n: GraphPos, kind: NeighborType) -> Vec<GraphPos> ⓘ
Get neighbors according to a NeighborType selector.
Sourcepub fn ids_in_position(&self, n: GraphPos) -> &[AgentId] ⓘ
pub fn ids_in_position(&self, n: GraphPos) -> &[AgentId] ⓘ
Agent IDs stored at a given node.
Sourcepub fn nearby_positions(
&self,
pos: GraphPos,
r: usize,
kind: NeighborType,
) -> Vec<GraphPos> ⓘ
pub fn nearby_positions( &self, pos: GraphPos, r: usize, kind: NeighborType, ) -> Vec<GraphPos> ⓘ
Find all node indices reachable within r hops via BFS, excluding the origin.
Sourcepub fn nearby_agent_ids(
&self,
pos: GraphPos,
r: usize,
kind: NeighborType,
) -> Vec<AgentId> ⓘ
pub fn nearby_agent_ids( &self, pos: GraphPos, r: usize, kind: NeighborType, ) -> Vec<AgentId> ⓘ
Find all agent IDs within r hops, including agents at the origin node.
Trait Implementations§
Source§impl Clone for GraphSpace
impl Clone for GraphSpace
Source§fn clone(&self) -> GraphSpace
fn clone(&self) -> GraphSpace
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more