Skip to main content

RouteOptimizer

Struct RouteOptimizer 

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

Route optimizer for waste collection and logistics

Implementations§

Source§

impl RouteOptimizer

Source

pub fn new(nodes: Vec<Node>, edges: Vec<Edge>) -> Self

Create a new route optimizer with the given nodes and edges

§Arguments
  • nodes - List of geographic nodes (locations)
  • edges - List of edges (road segments) connecting nodes
§Example
use rmp_route_optimizer::{RouteOptimizer, Node, Edge, PickupSide};

let nodes = vec![
    Node::new(1, 40.7128, -74.0060),
    Node::new(2, 40.7138, -74.0070),
];

let edges = vec![
    Edge::new(1, 2, 100.0, false, PickupSide::Either),
];

let optimizer = RouteOptimizer::new(nodes, edges);
Source

pub fn optimize_eulerian( &self, start_node: i64, _enforce_right_side: bool, ) -> Result<EulerianCircuit>

Optimize route using Eulerian circuit algorithm

This method finds an optimal route that traverses all edges in the graph, starting and ending at the specified node. If the graph is not Eulerian, it will add augmenting edges to make it Eulerian.

§Arguments
  • start_node - ID of the starting node
  • enforce_right_side - Whether to enforce right-side pickup constraints
§Returns

An EulerianCircuit containing the optimized route

§Errors

Returns an error if:

  • The graph is empty
  • The start node doesn’t exist
  • The graph is disconnected
  • The graph cannot be made Eulerian
§Example
use rmp_route_optimizer::{RouteOptimizer, Node, Edge, PickupSide};

let nodes = vec![
    Node::new(1, 40.7128, -74.0060),
    Node::new(2, 40.7138, -74.0070),
    Node::new(3, 40.7148, -74.0080),
];

let edges = vec![
    Edge::new(1, 2, 100.0, false, PickupSide::Either),
    Edge::new(2, 3, 100.0, false, PickupSide::Either),
    Edge::new(3, 1, 100.0, false, PickupSide::Either),
];

let optimizer = RouteOptimizer::new(nodes, edges);
let circuit = optimizer.optimize_eulerian(1, false).unwrap();

assert_eq!(circuit.nodes.first(), circuit.nodes.last());
assert!(circuit.total_cost > 0.0);
Source

pub fn haversine_distance(node1: &Node, node2: &Node) -> f64

Calculate Haversine distance between two nodes

§Arguments
  • node1 - First node
  • node2 - Second node
§Returns

Distance in meters

Auto Trait Implementations§

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> 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, 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.