vrp-core 1.5.8

A core algorithms to solve a Vehicle Routing Problem
Documentation
#[cfg(test)]
#[path = "../../../tests/unit/solver/objectives/total_transport_cost_test.rs"]
mod total_transport_cost_test;

use super::*;
use crate::algorithms::nsga2::Objective;
use crate::utils::compare_floats;

/// An objective function for total cost minimization as a target.
pub struct TotalTransportCost {}

impl Default for TotalTransportCost {
    fn default() -> Self {
        Self {}
    }
}

impl Objective for TotalTransportCost {
    type Solution = InsertionContext;

    fn total_order(&self, a: &Self::Solution, b: &Self::Solution) -> Ordering {
        compare_floats(self.fitness(a), self.fitness(b))
    }

    fn distance(&self, a: &Self::Solution, b: &Self::Solution) -> f64 {
        self.fitness(a) - self.fitness(b)
    }

    fn fitness(&self, solution: &Self::Solution) -> f64 {
        solution.solution.get_total_cost()
    }
}