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)
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 126)
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 87)
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 98)
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}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 set_heuristic(self, heuristic: TargetHeuristic) -> Self
pub fn set_heuristic(self, heuristic: TargetHeuristic) -> Self
Sets TargetHeuristic to be used. By default, it is used what is returned by get_default_heuristic.
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)
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 126)
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 88)
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 99)
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}Auto Trait Implementations§
impl Freeze for VrpConfigBuilder
impl !RefUnwindSafe for VrpConfigBuilder
impl !Send for VrpConfigBuilder
impl !Sync for VrpConfigBuilder
impl Unpin for VrpConfigBuilder
impl UnsafeUnpin 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