Skip to main content

transit_grid/operations/
mod.rs

1//! This module provides abstractions and implementations for modifying a transit network. A transit network is represented as a graph,
2//! where each node is a `TransitNode` (a point in the transit network where a vehicle can stop) and each edge represents a path
3//! (`TransitEdge`) between two transit nodes. The main trait provided by this module is `TransitNetworkModifier`.
4//!
5//! ## `TransitNetworkModifier`
6//!
7//! The `TransitNetworkModifier` trait provides an interface for modifying the network. This includes adding nodes and edges to the network.
8//! Implementors of this trait can be used to add `TransitNode` and `TransitEdge` instances to a network.
9//!
10//! For instance, an implementor might add a `TransitNode` to an internal data structure upon invocation of the `add_node` method.
11//! Similarly, the `add_edge` and `add_edge_with_accessibility` methods are used to add `TransitEdge` instances to the network.
12//! The `add_edge_with_accessibility` method also allows specifying the accessibility of the edge, represented by the `Accessability` enum.
13//!
14
15use crate::core::{Accessability, NodeId, TransitEdge, TransitNode};
16use geo::{Coord, CoordNum, Distance, Euclidean};
17
18/// Trait providing methods for modifying a transit network.
19///
20/// This trait provides an abstraction for modifying a transit network, which is represented as a graph with `TransitNode` instances as nodes and `TransitEdge` instances as edges.
21pub trait TransitNetworkModifier<R, T: CoordNum> {
22    /// Adds a `TransitNode` to the network.
23    ///
24    /// # Arguments
25    ///
26    /// * `node` - The `TransitNode` to be added to the network.
27    ///
28    /// # Returns
29    ///
30    /// * `NodeId` - The ID of the added node.
31    fn add_node(&mut self, node: TransitNode<R>) -> NodeId;
32
33    /// Adds a `TransitEdge` to the network.
34    ///
35    /// # Arguments
36    ///
37    /// * `edge` - The `TransitEdge` to be added to the network.
38    fn add_edge(&mut self, edge: TransitEdge<T>);
39
40    /// Adds a `TransitEdge` to the network with a given accessibility.
41    ///
42    /// # Arguments
43    ///
44    /// * `edge` - The `TransitEdge` to be added to the network.
45    /// * `accessibility` - The `Accessability` of the edge.
46    fn add_edge_with_accessibility(&mut self, edge: TransitEdge<T>, accessibility: Accessability);
47}
48
49/// A trait for repairing transit networks, particularly for ensuring that all edges in the network are in the correct direction.
50///
51/// This trait provides two methods:
52///
53/// * `repair_edge`: Repairs a specific edge between two nodes.
54/// * `repair`: Repairs the entire network.
55///
56/// The trait is generic over two parameters:
57///
58/// * `R`, for which `Euclidean` must implement the `Distance` trait, used for calculating distances between nodes.
59/// * `T`, which must implement the `CoordNum` trait, representing the type of the coordinates of nodes in the network.
60///
61/// # Types
62///
63/// * `R`: A type that can be used to calculate Euclidean distances.
64/// * `T`: A type that represents the coordinate system used by the nodes in the network.
65///
66pub trait TransitNetworkRepairer<R, T: CoordNum>
67where
68    Euclidean: Distance<T, R, Coord<T>>,
69{
70    /// Repairs the edge between two nodes in the network.
71    ///
72    /// If the edge is not in the correct direction (according to some
73    /// network-specific criterion), this method will modify the network
74    /// to correct the edge's direction.
75    ///
76    /// # Arguments
77    ///
78    /// * `node1` - The ID of the first node connected by the edge to be repaired.
79    /// * `node2` - The ID of the second node connected by the edge to be repaired.
80    ///
81    fn repair_edge(&mut self, node1: NodeId, node2: NodeId);
82
83    /// Repairs the entire network.
84    ///
85    /// This method will iterate over all the edges in the network and
86    /// repair them using the same criterion as `repair_edge`.
87    ///
88    fn repair(&mut self);
89}