Skip to main content

Graph

Struct Graph 

Source
pub struct Graph { /* private fields */ }
Expand description

A network graph for spatial analysis

Implementations§

Source§

impl Graph

Source

pub fn new() -> Self

Create a new empty directed graph

Source

pub fn with_type(graph_type: GraphType) -> Self

Create a new graph with specified type

Source

pub fn graph_type(&self) -> GraphType

Get the graph type

Source

pub fn add_node(&mut self, coordinate: Coordinate) -> NodeId

Add a node to the graph

Source

pub fn add_node_with_id( &mut self, id: NodeId, coordinate: Coordinate, ) -> Result<NodeId>

Add a node with a specific ID (useful for graph reconstruction)

Source

pub fn add_edge( &mut self, source: NodeId, target: NodeId, weight: f64, ) -> Result<EdgeId>

Add an edge to the graph

Source

pub fn add_weighted_edge( &mut self, source: NodeId, target: NodeId, multi_weight: EdgeWeight, ) -> Result<EdgeId>

Add an edge with multi-criteria weight

Source

pub fn remove_edge(&mut self, edge_id: EdgeId) -> Result<Edge>

Remove an edge from the graph

Source

pub fn remove_node(&mut self, node_id: NodeId) -> Result<Node>

Remove a node and all its incident edges from the graph

Source

pub fn get_node(&self, id: NodeId) -> Option<&Node>

Get a node by ID

Source

pub fn get_node_mut(&mut self, id: NodeId) -> Option<&mut Node>

Get a mutable reference to a node by ID

Source

pub fn get_edge(&self, id: EdgeId) -> Option<&Edge>

Get an edge by ID

Source

pub fn get_edge_mut(&mut self, id: EdgeId) -> Option<&mut Edge>

Get a mutable reference to an edge by ID

Source

pub fn outgoing_edges(&self, node: NodeId) -> &[EdgeId]

Get all outgoing edges from a node

Source

pub fn incoming_edges(&self, node: NodeId) -> &[EdgeId]

Get all incoming edges to a node

Source

pub fn neighbors(&self, node: NodeId) -> Vec<NodeId>

Get all neighbors of a node (targets of outgoing edges)

Source

pub fn neighbors_with_edges(&self, node: NodeId) -> Vec<(NodeId, EdgeId, f64)>

Get all neighbors with the connecting edge information

Source

pub fn num_nodes(&self) -> usize

Number of nodes in the graph

Source

pub fn num_edges(&self) -> usize

Number of edges in the graph

Source

pub fn is_empty(&self) -> bool

Check if the graph is empty

Source

pub fn node_ids(&self) -> Vec<NodeId>

Get all node IDs

Source

pub fn edge_ids(&self) -> Vec<EdgeId>

Get all edge IDs

Source

pub fn has_node(&self, id: NodeId) -> bool

Check if a node exists

Source

pub fn has_edge(&self, id: EdgeId) -> bool

Check if an edge exists

Source

pub fn find_edge(&self, source: NodeId, target: NodeId) -> Option<EdgeId>

Find an edge between two specific nodes

Source

pub fn find_edges(&self, source: NodeId, target: NodeId) -> Vec<EdgeId>

Find all edges between two specific nodes (multi-graph support)

Source

pub fn nearest_node(&self, coord: &Coordinate) -> Option<NodeId>

Find the nearest node to a given coordinate

Source

pub fn k_nearest_nodes( &self, coord: &Coordinate, k: usize, ) -> Vec<(NodeId, f64)>

Find the k nearest nodes to a given coordinate

Source

pub fn in_degree(&self, node: NodeId) -> usize

Compute the in-degree of a node

Source

pub fn out_degree(&self, node: NodeId) -> usize

Compute the out-degree of a node

Source

pub fn degree(&self, node: NodeId) -> usize

Compute the total degree of a node

Source

pub fn metrics(&self) -> GraphMetrics

Calculate graph metrics

Source

pub fn subgraph(&self, node_ids: &[NodeId]) -> Result<Graph>

Create a subgraph containing only the specified nodes and edges between them

Source

pub fn reverse(&self) -> Graph

Reverse all edge directions (only meaningful for directed graphs)

Source

pub fn nodes_iter(&self) -> impl Iterator<Item = (&NodeId, &Node)>

Access the nodes map directly (for iteration)

Source

pub fn edges_iter(&self) -> impl Iterator<Item = (&EdgeId, &Edge)>

Access the edges map directly (for iteration)

Source

pub fn sorted_node_ids(&self) -> Vec<NodeId>

Get sorted node IDs for deterministic iteration

Source§

impl Graph

Source

pub fn validate(&self) -> Result<()>

Comprehensive graph validation

Source

pub fn validate_detailed(&self) -> ValidationResult

Detailed graph validation returning all issues

Source

pub fn is_connected(&self) -> bool

Check if the graph is connected (weakly for directed graphs)

Source

pub fn connected_components(&self) -> Vec<ConnectedComponent>

Find all connected components (weakly connected for directed graphs)

Source

pub fn strongly_connected_components(&self) -> Vec<Vec<NodeId>>

Find strongly connected components using Tarjan’s algorithm (directed graphs only)

Source

pub fn remove_isolated_nodes(&mut self) -> Vec<NodeId>

Remove all isolated nodes (nodes with no edges)

Source

pub fn remove_self_loops(&mut self) -> Vec<EdgeId>

Remove self-loops

Source

pub fn remove_parallel_edges(&mut self) -> Vec<EdgeId>

Remove duplicate (parallel) edges, keeping the one with minimum weight

Source

pub fn contract_degree2_nodes(&mut self) -> usize

Contract degree-2 nodes (nodes with exactly one incoming and one outgoing edge)

Source

pub fn snap_nodes(&mut self, tolerance: f64) -> usize

Snap close nodes together within a tolerance

Source

pub fn clean_topology(&mut self, tolerance: f64) -> TopologyCleanResult

Clean topology by performing multiple operations

Trait Implementations§

Source§

impl Clone for Graph

Source§

fn clone(&self) -> Graph

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Graph

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Graph

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl Freeze for Graph

§

impl RefUnwindSafe for Graph

§

impl Send for Graph

§

impl Sync for Graph

§

impl Unpin for Graph

§

impl UnsafeUnpin for Graph

§

impl UnwindSafe for Graph

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.