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