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
impl Solution
Sourcepub fn get_locations(
&self,
) -> impl Iterator<Item = impl Iterator<Item = Location> + '_> + '_
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
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
impl From<(InsertionContext, Option<TelemetryMetrics>)> for Solution
Source§fn from(value: (InsertionContext, Option<TelemetryMetrics>)) -> Self
fn from(value: (InsertionContext, Option<TelemetryMetrics>)) -> Self
Converts to this type from the input type.
Source§impl From<InsertionContext> for Solution
impl From<InsertionContext> for Solution
Source§fn from(insertion_ctx: InsertionContext) -> Self
fn from(insertion_ctx: InsertionContext) -> Self
Converts to this type from the input type.
Auto Trait Implementations§
impl Freeze for Solution
impl !RefUnwindSafe for Solution
impl Send for Solution
impl Sync for Solution
impl Unpin for Solution
impl !UnwindSafe for Solution
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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