Struct Solution

Source
pub struct Solution {
    pub cost: Cost,
    pub registry: Registry,
    pub routes: Vec<Route>,
    pub unassigned: Vec<(Job, UnassignmentInfo)>,
    pub telemetry: Option<TelemetryMetrics>,
}
Expand description

Represents a VRP solution.

Fields§

§cost: Cost

A total solution cost. Definition of the cost depends on VRP variant.

§registry: Registry

Actor’s registry.

§routes: Vec<Route>

List of assigned routes.

§unassigned: Vec<(Job, UnassignmentInfo)>

List of unassigned jobs within reason code.

§telemetry: Option<TelemetryMetrics>

An optional telemetry metrics if available.

Implementations§

Source§

impl Solution

Source

pub fn get_locations( &self, ) -> impl Iterator<Item = impl Iterator<Item = Location> + '_> + '_

Iterates through all tours and returns locations of each activity in the order they are visited.

Examples found in repository?
examples/custom_objective.rs (line 151)
137fn main() -> GenericResult<()> {
138    let transport = Arc::new(define_routing_data()?);
139
140    let goal = define_goal(transport.clone())?;
141    let problem = Arc::new(define_problem(goal, transport)?);
142
143    let config = VrpConfigBuilder::new(problem.clone()).prebuild()?.with_max_generations(Some(10)).build()?;
144
145    // run the VRP solver and get the best known solution
146    let solution = Solver::new(problem, config).solve()?;
147
148    assert_eq!(solution.unassigned.len(), 2, "expected two assigned jobs due to capacity constraint");
149    assert_eq!(solution.routes.len(), 1, "only one tour should be there");
150    assert_eq!(
151        solution.get_locations().map(Iterator::collect::<Vec<_>>).collect::<Vec<_>>(),
152        vec![vec![0, 2, 4]],
153        "tour doesn't serve only top-prio jobs"
154    );
155    assert_eq!(solution.cost, 545., "unexpected cost - closest to depot jobs should be assigned");
156
157    Ok(())
158}
More examples
Hide additional examples
examples/custom_constraint.rs (line 142)
120fn main() -> GenericResult<()> {
121    let transport = Arc::new(define_routing_data()?);
122
123    let goal = define_goal(transport.clone())?;
124    let problem = Arc::new(define_problem(goal, transport)?);
125
126    let config = VrpConfigBuilder::new(problem.clone()).prebuild()?.with_max_generations(Some(10)).build()?;
127
128    // run the VRP solver and get the best known solution
129    let solution = Solver::new(problem, config).solve()?;
130
131    assert_eq!(
132        solution.unassigned.len(),
133        2,
134        "expected two assigned jobs due to hardware requirement and capacity constraints"
135    );
136    assert_eq!(solution.routes.len(), 1, "only one tour should be there: second vehicle cannot serve hardware jobs");
137    assert_eq!(solution.cost, 1050., "unexpected cost - closest to depot jobs should be assigned");
138
139    // simple way to explore the solution, more advanced are available too
140    println!(
141        "\nIn solution, locations are visited in the following order:\n{:?}\n",
142        solution.get_locations().map(Iterator::collect::<Vec<_>>).collect::<Vec<_>>()
143    );
144
145    Ok(())
146}
examples/cvrp.rs (line 103)
78fn main() -> GenericResult<()> {
79    // get routing data, see `./common/routing.rs` for details
80    let transport = Arc::new(define_routing_data()?);
81
82    // specify CVRP variant as problem definition and the goal of optimization
83    let goal = define_goal(transport.clone())?;
84    let problem = Arc::new(define_problem(goal, transport)?);
85
86    // build a solver config with the predefined settings to run 5 secs or 10 generations at most
87    let config = VrpConfigBuilder::new(problem.clone())
88        .prebuild()?
89        .with_max_time(Some(5))
90        .with_max_generations(Some(10))
91        .build()?;
92
93    // run the VRP solver and get the best known solution
94    let solution = Solver::new(problem, config).solve()?;
95
96    assert!(solution.unassigned.is_empty(), "has unassigned jobs, but all jobs must be assigned");
97    assert_eq!(solution.routes.len(), 2, "two tours are expected");
98    assert_eq!(solution.cost, 2135., "unexpected cost (total distance traveled)");
99
100    // simple way to explore the solution, more advanced are available too
101    println!(
102        "\nIn solution, locations are visited in the following order:\n{:?}\n",
103        solution.get_locations().map(Iterator::collect::<Vec<_>>).collect::<Vec<_>>()
104    );
105
106    Ok(())
107}
examples/pdptw.rs (line 114)
89fn main() -> GenericResult<()> {
90    // get routing data, see `./common/routing.rs` for details
91    let transport = Arc::new(define_routing_data()?);
92
93    // specify PDPTW variant as problem definition and the goal of optimization
94    let goal = define_goal(transport.clone())?;
95    let problem = Arc::new(define_problem(goal, transport)?);
96
97    // build a solver config with the predefined settings to run 5 secs or 10 generations at most
98    let config = VrpConfigBuilder::new(problem.clone())
99        .prebuild()?
100        .with_max_time(Some(5))
101        .with_max_generations(Some(10))
102        .build()?;
103
104    // run the VRP solver and get the best known solution
105    let solution = Solver::new(problem, config).solve()?;
106
107    assert!(solution.unassigned.is_empty(), "has unassigned jobs, but all jobs must be assigned");
108    assert_eq!(solution.routes.len(), 1, "one tour should be there");
109    assert_eq!(solution.cost, 1105., "unexpected cost (total distance traveled)");
110
111    // simple way to explore the solution, more advanced are available too
112    println!(
113        "\nIn solution, locations are visited in the following order:\n{:?}\n",
114        solution.get_locations().map(Iterator::collect::<Vec<_>>).collect::<Vec<_>>()
115    );
116
117    Ok(())
118}

Trait Implementations§

Source§

impl From<(InsertionContext, Option<TelemetryMetrics>)> for Solution

Source§

fn from(value: (InsertionContext, Option<TelemetryMetrics>)) -> Self

Converts to this type from the input type.
Source§

impl From<InsertionContext> for Solution

Source§

fn from(insertion_ctx: InsertionContext) -> Self

Converts to this type from the input type.

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. 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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V