Skip to content
6 changes: 3 additions & 3 deletions examples/bundle_processing/bundle_processing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use a_sabr::distance::sabr::SABR;
use a_sabr::node_manager::none::NoManagement;
use a_sabr::node_manager::NodeManager;
use a_sabr::parsing::coerce_nm;
use a_sabr::parsing::NodeMarkerMap;
use a_sabr::parsing::{DispatchParser, Dispatcher, Lexer, Parser, ParsingState};
use a_sabr::parsing::{DispatchParser, Lexer, Parser, ParsingState};
use a_sabr::parsing::{NodeMarkerMap, StaticMarkerMap};
use a_sabr::pathfinding::hybrid_parenting::HybridParentingPath;
use a_sabr::pathfinding::Pathfinding;
use a_sabr::types::Date;
Expand Down Expand Up @@ -93,7 +93,7 @@ impl Parser<Compressing> for Compressing {
fn edge_case_example<NM: NodeManager + Parser<NM> + DispatchParser<NM>>(
cp_path: &str,
bundle_priority: Priority,
node_marker_map: Option<&Dispatcher<'_, fn(&mut dyn Lexer) -> ParsingState<NM>>>,
node_marker_map: Option<&StaticMarkerMap<NM>>,
) {
let bundle = Bundle {
source: 0,
Expand Down
4 changes: 2 additions & 2 deletions examples/satellite_constellation/satellite_constellation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use a_sabr::node_manager::none::NoManagement;
use a_sabr::node_manager::NodeManager;
use a_sabr::parsing::coerce_nm;
use a_sabr::parsing::NodeMarkerMap;
use a_sabr::parsing::{DispatchParser, Dispatcher, Lexer, Parser, ParsingState};
use a_sabr::parsing::{DispatchParser, Lexer, Parser, ParsingState, StaticMarkerMap};
use a_sabr::pathfinding::hybrid_parenting::HybridParentingPath;
use a_sabr::pathfinding::Pathfinding;
use a_sabr::types::Date;
Expand Down Expand Up @@ -84,7 +84,7 @@ impl Parser<NoRetention> for NoRetention {

fn edge_case_example<NM: NodeManager + Parser<NM> + DispatchParser<NM>>(
cp_path: &str,
node_marker_map: Option<&Dispatcher<'_, fn(&mut dyn Lexer) -> ParsingState<NM>>>,
node_marker_map: Option<&StaticMarkerMap<NM>>,
) {
let bundle = Bundle {
source: 0,
Expand Down
8 changes: 2 additions & 6 deletions src/contact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,10 @@ use crate::contact_manager::ContactManager;
use crate::node_manager::NodeManager;
use crate::parsing::{Lexer, Parser, ParsingState};
#[cfg(feature = "contact_work_area")]
use crate::route_stage::RouteStage;
use crate::route_stage::SharedRouteStage;
use crate::types::{Date, NodeID, Token};
#[cfg(feature = "contact_work_area")]
use std::cell::RefCell;
use std::cmp::Ordering;
use std::marker::PhantomData;
#[cfg(feature = "contact_work_area")]
use std::rc::Rc;

/// Represents basic information about a contact between two nodes.
#[derive(Clone, Copy)]
Expand Down Expand Up @@ -70,7 +66,7 @@ pub struct Contact<NM: NodeManager, CM: ContactManager> {
pub manager: CM,
#[cfg(feature = "contact_work_area")]
/// The work area for managing path construction stages (compilation option).
pub work_area: Option<Rc<RefCell<RouteStage<NM, CM>>>>,
pub work_area: Option<SharedRouteStage<NM, CM>>,
#[cfg(feature = "contact_suppression")]
/// Suppression option for path construction (compilation option).
pub suppressed: bool,
Expand Down
13 changes: 7 additions & 6 deletions src/contact_plan/from_asabr_lexer.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use crate::{
contact::{Contact, ContactInfo},
contact_manager::ContactManager,
contact_plan::ContactPlan,
node::{Node, NodeInfo},
parsing::{Dispatcher, Parser},
parsing::{Parser, StaticMarkerMap},
types::{NodeID, NodeName},
};
use crate::{
Expand Down Expand Up @@ -64,10 +65,10 @@ impl ASABRContactPlan {
let node_name = node.get_node_name();

if known_node_ids.contains(&node_id) {
return Err(format!("Two nodes have the same id ({})", node_id));
return Err(format!("Two nodes have the same id ({node_id})"));
}
if known_node_names.contains(&node_name) {
return Err(format!("Two nodes have the same id ({})", node_name));
return Err(format!("Two nodes have the same id ({node_name})"));
}
let value = max(node.get_node_id(), node.get_node_id());
*max_node_in_in_nodes = max(*max_node_in_in_nodes, value.into());
Expand Down Expand Up @@ -106,9 +107,9 @@ impl ASABRContactPlan {
CM: ContactManager + DispatchParser<CM> + Parser<CM>,
>(
lexer: &mut dyn Lexer,
node_marker_map: Option<&Dispatcher<fn(&mut dyn Lexer) -> ParsingState<NM>>>,
contact_marker_map: Option<&Dispatcher<fn(&mut dyn Lexer) -> ParsingState<CM>>>,
) -> Result<(Vec<Node<NM>>, Vec<Contact<NM, CM>>), String> {
node_marker_map: Option<&StaticMarkerMap<NM>>,
contact_marker_map: Option<&StaticMarkerMap<CM>>,
) -> Result<ContactPlan<NM, NM, CM>, String> {
let mut contacts: Vec<Contact<NM, CM>> = Vec::new();
let mut nodes: Vec<Node<NM>> = Vec::new();

Expand Down
3 changes: 2 additions & 1 deletion src/contact_plan/from_ion_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use crate::{
seg::{Segment, SegmentationManager},
ContactManager,
},
contact_plan::ContactPlan,
node::{Node, NodeInfo},
node_manager::{none::NoManagement, NodeManager},
types::{DataRate, Date, Duration, NodeID},
Expand Down Expand Up @@ -163,7 +164,7 @@ fn get_confidence(vec: &[String]) -> f32 {
impl IONContactPlan {
pub fn parse<NM: NodeManager, CM: FromIONContactData<NM, CM> + ContactManager>(
filename: &str,
) -> io::Result<(Vec<Node<NoManagement>>, Vec<Contact<NM, CM>>)> {
) -> io::Result<ContactPlan<NoManagement, NM, CM>> {
let file = File::open(filename)?;
let mut reader = BufReader::new(file);
let mut map_id_map: HashMap<String, NodeID> = HashMap::new();
Expand Down
3 changes: 2 additions & 1 deletion src/contact_plan/from_tvgutil_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use crate::{
seg::{Segment, SegmentationManager},
ContactManager,
},
contact_plan::ContactPlan,
node::{Node, NodeInfo},
node_manager::{none::NoManagement, NodeManager},
types::{DataRate, Date, Duration, NodeID},
Expand Down Expand Up @@ -81,7 +82,7 @@ pub struct TVGUtilContactPlan {}
impl TVGUtilContactPlan {
pub fn parse<NM: NodeManager, CM: FromTVGUtilContactData<NM, CM> + ContactManager>(
filename: &str,
) -> io::Result<(Vec<Node<NoManagement>>, Vec<Contact<NM, CM>>)> {
) -> io::Result<ContactPlan<NoManagement, NM, CM>> {
let mut nodes: Vec<Node<NoManagement>> = Vec::new();
let mut contacts: Vec<Contact<NM, CM>> = Vec::new();

Expand Down
5 changes: 5 additions & 0 deletions src/contact_plan/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
use crate::contact::Contact;
use crate::node::Node;

pub mod asabr_file_lexer;
pub mod from_asabr_lexer;
pub mod from_ion_file;
pub mod from_tvgutil_file;

type ContactPlan<NNM, CNM, CCM> = (Vec<Node<NNM>>, Vec<Contact<CNM, CCM>>);
4 changes: 2 additions & 2 deletions src/node_manager/none.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub struct NoManagement {}
impl NodeManager for NoManagement {
#[cfg(feature = "node_proc")]
fn dry_run_process(&self, at_time: Date, _bundle: &mut Bundle) -> Date {
return at_time;
at_time
}
#[cfg(feature = "node_tx")]
fn dry_run_tx(&self, _waiting_since: Date, _start: Date, _end: Date, _bundle: &Bundle) -> bool {
Expand All @@ -25,7 +25,7 @@ impl NodeManager for NoManagement {
}
#[cfg(feature = "node_proc")]
fn schedule_process(&self, at_time: Date, _bundle: &mut Bundle) -> Date {
return at_time;
at_time
}
#[cfg(feature = "node_tx")]
fn schedule_tx(
Expand Down
13 changes: 11 additions & 2 deletions src/parsing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ pub type NodeMarkerMap<'a> = Dispatcher<'a, NodeDispatcher>;
pub type ContactDispatcher = fn(&mut dyn Lexer) -> ParsingState<Box<dyn ContactManager>>;
pub type NodeDispatcher = fn(&mut dyn Lexer) -> ParsingState<Box<dyn NodeManager>>;

pub type StaticMarkerMap<'a, M> = Dispatcher<'a, StaticDispatcher<M>>;
pub type StaticDispatcher<M> = fn(&mut dyn Lexer) -> ParsingState<M>;

/// Wrapper object to a marker -> coercion function map for contacts or nodes versions (T)
///
/// # Type Parameters
Expand All @@ -16,6 +19,12 @@ pub struct Dispatcher<'a, T> {
/// A hashmap that stores the coercion functions with their associated markers.
map: HashMap<&'a str, T>,
}
impl<'a, T> Default for Dispatcher<'a, T> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

used somewhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clippy recommends implementing Default for types that have a new() method, because "The user might expect to be able to use Default as the type can be constructed without arguments."

Since RoutingTable is part of the public API of a-sabr, it would be used by users of a-sabr to fill all or some of the struct fields automatically with Default::default() for convenience.

Reference: https://rust-lang.github.io/rust-clippy/rust-1.91.0/index.html#new_without_default

However if this is not particularly convenient or important at the moment, just tell me to and I'll remove the commit.

fn default() -> Self {
Self::new()
}
}

impl<'a, T> Dispatcher<'a, T> {
/// Creates a new, empty `Dispatcher`.
pub fn new() -> Self {
Expand Down Expand Up @@ -115,7 +124,7 @@ implement_parser!(ContactManager);
/// * `ParsingState<(INFO, MANAGER)>` - The parsing state containing either the parsed components or an error.
pub fn parse_components<INFO: Parser<INFO>, MANAGER: DispatchParser<MANAGER> + Parser<MANAGER>>(
lexer: &mut dyn Lexer,
dispatch_map: Option<&Dispatcher<fn(&mut dyn Lexer) -> ParsingState<MANAGER>>>,
dispatch_map: Option<&StaticMarkerMap<MANAGER>>,
) -> ParsingState<(INFO, MANAGER)> {
let info: INFO;
let manager: MANAGER;
Expand Down Expand Up @@ -170,7 +179,7 @@ pub trait DispatchParser<T: Parser<T>> {
/// - `EOF` - Indicates the end of the input stream, suggesting that parsing cannot continue.
fn parse_dispatch(
lexer: &mut dyn Lexer,
_marker_map: Option<&Dispatcher<fn(&mut dyn Lexer) -> ParsingState<T>>>,
_marker_map: Option<&StaticMarkerMap<T>>,
) -> ParsingState<T> {
T::parse(lexer)
}
Expand Down
16 changes: 8 additions & 8 deletions src/pathfinding/hybrid_parenting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::{
distance::{Distance, DistanceWrapper},
multigraph::Multigraph,
node_manager::NodeManager,
route_stage::RouteStage,
route_stage::{RouteStage, SharedRouteStage},
types::{Date, NodeID},
};

Expand Down Expand Up @@ -66,13 +66,13 @@ struct HybridParentingWorkArea<NM: NodeManager, CM: ContactManager> {
/// The bundle associated with this work area.
pub bundle: Bundle,
/// The source route stage, representing the starting point for routing.
pub source: Rc<RefCell<RouteStage<NM, CM>>>,
pub source: SharedRouteStage<NM, CM>,
/// A sorted list of node IDs to be excluded from routing paths.
pub excluded_nodes_sorted: Vec<NodeID>,
/// A vector containing vectors of route stages, grouped by destination.
/// Each inner vector represents possible routes to a specific destination,
/// sorted in order of preference.
pub by_destination: Vec<Vec<Rc<RefCell<RouteStage<NM, CM>>>>>,
pub by_destination: Vec<Vec<SharedRouteStage<NM, CM>>>,
}

impl<NM: NodeManager, CM: ContactManager> HybridParentingWorkArea<NM, CM> {
Expand All @@ -81,15 +81,15 @@ impl<NM: NodeManager, CM: ContactManager> HybridParentingWorkArea<NM, CM> {
///
/// # Parameters
/// - `bundle`: A reference to the `Bundle` representing the data payload for routing.
/// - `source`: An `Rc<RefCell<RouteStage<NM, CM>>>` reference to the initial route stage.
/// - `source`: A `SharedRouteStage<NM, CM>` reference to the initial route stage.
/// - `excluded_nodes_sorted`: A reference to a sorted vector of `NodeID`s to be excluded from routing paths.
/// - `node_count`: The number of destination nodes, which determines the size of `by_destination`.
///
/// # Returns
/// A new instance of `HybridParentingWorkArea` initialized with the provided parameters.
pub fn new(
bundle: &Bundle,
source: Rc<RefCell<RouteStage<NM, CM>>>,
source: SharedRouteStage<NM, CM>,
excluded_nodes_sorted: &[NodeID],
node_count: usize,
) -> Self {
Expand Down Expand Up @@ -146,7 +146,7 @@ use super::{try_make_hop, PathFindingOutput, Pathfinding};
///
/// # Returns
///
/// * `Option<Rc<RefCell<RouteStage<NM, CM>>>>` - Returns an `Option` containing a reference to the
/// * `Option<SharedRouteStage<NM, CM>>` - Returns an `Option` containing a reference to the
/// newly inserted route if the insertion was successful; otherwise, returns `None`.
fn try_insert<
NM: NodeManager,
Expand All @@ -155,7 +155,7 @@ fn try_insert<
>(
proposition: RouteStage<NM, CM>,
tree: &mut HybridParentingWorkArea<NM, CM>,
) -> Option<Rc<RefCell<RouteStage<NM, CM>>>> {
) -> Option<SharedRouteStage<NM, CM>> {
let routes_for_rx_node = &mut tree.by_destination[proposition.to_node as usize];
// if D::can_retain sets insert to true, but the next element does not trigger insert_index =idx, insert at the end
let mut insert_index: usize = routes_for_rx_node.len();
Expand Down Expand Up @@ -290,7 +290,7 @@ macro_rules! define_mpt {
if $with_exclusions {
graph.prepare_for_exclusions_sorted(excluded_nodes_sorted);
}
let source_route: Rc<RefCell<RouteStage<NM, CM>>> =
let source_route: SharedRouteStage<NM, CM> =
Rc::new(RefCell::new(RouteStage::new(
current_time,
source,
Expand Down
2 changes: 1 addition & 1 deletion src/pathfinding/limiting_contact/first_depleted.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ fn had_less_volume_than<NM: NodeManager, CM: ContactManager>(
a: &Contact<NM, CM>,
b: &Contact<NM, CM>,
) -> bool {
return a.manager.get_original_volume() < b.manager.get_original_volume();
a.manager.get_original_volume() < b.manager.get_original_volume()
}

create_new_alternative_path_variant!(FirstDepleted, had_less_volume_than);
2 changes: 1 addition & 1 deletion src/pathfinding/limiting_contact/first_ending.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ fn ends_earlier_than<NM: NodeManager, CM: ContactManager>(
a: &Contact<NM, CM>,
b: &Contact<NM, CM>,
) -> bool {
return a.info.end < b.info.end;
a.info.end < b.info.end
}

create_new_alternative_path_variant!(FirstEnding, ends_earlier_than);
4 changes: 2 additions & 2 deletions src/pathfinding/limiting_contact/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::contact::Contact;
use crate::contact_manager::ContactManager;
use crate::node_manager::NodeManager;
use crate::route_stage::RouteStage;
use crate::route_stage::SharedRouteStage;
use std::cell::RefCell;
use std::rc::Rc;

Expand Down Expand Up @@ -32,7 +32,7 @@ pub use first_ending::FirstEnding;
/// is found; otherwise, `None`.
#[cfg(feature = "contact_suppression")]
pub fn get_next_to_suppress<NM: NodeManager, CM: ContactManager>(
route: Rc<RefCell<RouteStage<NM, CM>>>,
route: SharedRouteStage<NM, CM>,
better_for_suppression_than_fn: fn(&Contact<NM, CM>, &Contact<NM, CM>) -> bool,
) -> Option<Rc<RefCell<Contact<NM, CM>>>> {
let mut to_suppress_opt: Option<Rc<RefCell<Contact<NM, CM>>>> = None;
Expand Down
15 changes: 9 additions & 6 deletions src/pathfinding/mod.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
use crate::bundle::Bundle;
use crate::contact::Contact;
use crate::contact_manager::{ContactManager, ContactManagerTxData};
use crate::multigraph::Multigraph;
use crate::node::Node;
use crate::node_manager::NodeManager;
use crate::route_stage::ViaHop;
use crate::route_stage::{RouteStage, SharedRouteStage};
use crate::types::{Date, NodeID};
use crate::{bundle::Bundle, route_stage::RouteStage};
use std::cell::RefCell;
use std::rc::Rc;

Expand All @@ -29,13 +30,15 @@ pub struct PathFindingOutput<NM: NodeManager, CM: ContactManager> {
/// The `Bundle` for which the pathfinding is being performed.
pub bundle: Bundle,
/// The `source` RouteStage from which the pathfinding is being performed.
pub source: Rc<RefCell<RouteStage<NM, CM>>>,
pub source: SharedRouteStage<NM, CM>,
/// A list of `NodeID`s representing nodes that should be excluded from the pathfinding.
pub excluded_nodes_sorted: Vec<NodeID>,
/// A vector that contains a `RouteStage`s for a specific destination node ID as the index.
pub by_destination: Vec<Option<Rc<RefCell<RouteStage<NM, CM>>>>>,
pub by_destination: Vec<Option<SharedRouteStage<NM, CM>>>,
}

pub type SharedPathFindingOutput<NM, CM> = Rc<RefCell<PathFindingOutput<NM, CM>>>;

impl<NM: NodeManager, CM: ContactManager> PathFindingOutput<NM, CM> {
/// Creates a new `PathfindingOutput` instance, initializing the `by_destination` vector
/// with empty vectors for each destination node and sorting the excluded nodes.
Expand All @@ -52,7 +55,7 @@ impl<NM: NodeManager, CM: ContactManager> PathFindingOutput<NM, CM> {
/// A new `PathfindingOutput` instance.
pub fn new(
bundle: &Bundle,
source: Rc<RefCell<RouteStage<NM, CM>>>,
source: SharedRouteStage<NM, CM>,
excluded_nodes_sorted: &[NodeID],
node_count: usize,
) -> Self {
Expand All @@ -65,7 +68,7 @@ impl<NM: NodeManager, CM: ContactManager> PathFindingOutput<NM, CM> {
}
}

pub fn get_source_route(&self) -> Rc<RefCell<RouteStage<NM, CM>>> {
pub fn get_source_route(&self) -> SharedRouteStage<NM, CM> {
self.source.clone()
}

Expand Down Expand Up @@ -148,7 +151,7 @@ pub trait Pathfinding<NM: NodeManager, CM: ContactManager> {
/// An `Option` containing a `RouteStage` if a suitable hop is found, or `None` if no valid hop is available.
fn try_make_hop<NM: NodeManager, CM: ContactManager>(
first_contact_index: usize,
sndr_route: &Rc<RefCell<RouteStage<NM, CM>>>,
sndr_route: &SharedRouteStage<NM, CM>,
_bundle: &Bundle,
contacts: &[Rc<RefCell<Contact<NM, CM>>>],
tx_node: &Rc<RefCell<Node<NM>>>,
Expand Down
Loading