pub struct EvolutionConfigBuilder<C, O, S, K>where
C: HeuristicContext<Objective = O, Solution = S> + Stateful<Key = K> + 'static,
O: HeuristicObjective<Solution = S> + 'static,
S: HeuristicSolution + 'static,
K: Hash + Eq + Clone + Send + Sync + 'static,{ /* private fields */ }
Expand description
Provides configurable way to build evolution configuration using fluent interface style.
Implementations§
Source§impl<C, O, S, K> EvolutionConfigBuilder<C, O, S, K>where
C: HeuristicContext<Objective = O, Solution = S> + Stateful<Key = K> + 'static,
O: HeuristicObjective<Solution = S> + 'static,
S: HeuristicSolution + 'static,
K: Hash + Eq + Clone + Send + Sync + 'static,
impl<C, O, S, K> EvolutionConfigBuilder<C, O, S, K>where
C: HeuristicContext<Objective = O, Solution = S> + Stateful<Key = K> + 'static,
O: HeuristicObjective<Solution = S> + 'static,
S: HeuristicSolution + 'static,
K: Hash + Eq + Clone + Send + Sync + 'static,
Sourcepub fn with_max_generations(
self,
limit: Option<usize>,
) -> EvolutionConfigBuilder<C, O, S, K>
pub fn with_max_generations( self, limit: Option<usize>, ) -> EvolutionConfigBuilder<C, O, S, K>
Sets max generations to be run by evolution. Default is 3000.
Examples found in repository?
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
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}
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}
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 with_max_time(
self,
limit: Option<usize>,
) -> EvolutionConfigBuilder<C, O, S, K>
pub fn with_max_time( self, limit: Option<usize>, ) -> EvolutionConfigBuilder<C, O, S, K>
Sets max running time limit for evolution. Default is 300 seconds.
Examples found in repository?
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}
More examples
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 with_min_cv(
self,
min_cv: Option<(String, usize, f64, bool)>,
key: K,
) -> EvolutionConfigBuilder<C, O, S, K>
pub fn with_min_cv( self, min_cv: Option<(String, usize, f64, bool)>, key: K, ) -> EvolutionConfigBuilder<C, O, S, K>
Sets variation coefficient termination criteria. Default is None.
Sourcepub fn with_target_proximity(
self,
target_proximity: Option<(Vec<f64>, f64)>,
) -> EvolutionConfigBuilder<C, O, S, K>
pub fn with_target_proximity( self, target_proximity: Option<(Vec<f64>, f64)>, ) -> EvolutionConfigBuilder<C, O, S, K>
Sets target fitness and distance threshold as termination criteria.
Sourcepub fn with_initial(
self,
max_size: usize,
quota: f64,
operators: Vec<(Box<dyn InitialOperator<Objective = O, Solution = S, Context = C> + Send + Sync>, usize)>,
) -> EvolutionConfigBuilder<C, O, S, K>
pub fn with_initial( self, max_size: usize, quota: f64, operators: Vec<(Box<dyn InitialOperator<Objective = O, Solution = S, Context = C> + Send + Sync>, usize)>, ) -> EvolutionConfigBuilder<C, O, S, K>
Sets initial parameters used to construct initial population.
Sourcepub fn with_processing(
self,
processing: ProcessingConfig<C, O, S>,
) -> EvolutionConfigBuilder<C, O, S, K>
pub fn with_processing( self, processing: ProcessingConfig<C, O, S>, ) -> EvolutionConfigBuilder<C, O, S, K>
Specifies processing configuration.
Sourcepub fn with_init_solutions(
self,
solutions: Vec<S>,
max_init_size: Option<usize>,
) -> EvolutionConfigBuilder<C, O, S, K>
pub fn with_init_solutions( self, solutions: Vec<S>, max_init_size: Option<usize>, ) -> EvolutionConfigBuilder<C, O, S, K>
Sets initial solutions in population. Default is no solutions in population.
Sourcepub fn with_objective(
self,
objective: Arc<dyn HeuristicObjective<Solution = S>>,
) -> EvolutionConfigBuilder<C, O, S, K>
pub fn with_objective( self, objective: Arc<dyn HeuristicObjective<Solution = S>>, ) -> EvolutionConfigBuilder<C, O, S, K>
Sets objective.
Sourcepub fn with_context(self, context: C) -> EvolutionConfigBuilder<C, O, S, K>
pub fn with_context(self, context: C) -> EvolutionConfigBuilder<C, O, S, K>
Sets heuristic context.
Sourcepub fn with_termination(
self,
termination: Box<dyn Termination<Context = C, Objective = O>>,
) -> EvolutionConfigBuilder<C, O, S, K>
pub fn with_termination( self, termination: Box<dyn Termination<Context = C, Objective = O>>, ) -> EvolutionConfigBuilder<C, O, S, K>
Sets termination.
Sourcepub fn with_heuristic(
self,
heuristic: Box<dyn HyperHeuristic<Objective = O, Solution = S, Context = C>>,
) -> EvolutionConfigBuilder<C, O, S, K>
pub fn with_heuristic( self, heuristic: Box<dyn HyperHeuristic<Objective = O, Solution = S, Context = C>>, ) -> EvolutionConfigBuilder<C, O, S, K>
Sets a different heuristic replacing initial.
Sourcepub fn with_strategy(
self,
strategy: Box<dyn EvolutionStrategy<Solution = S, Context = C, Objective = O>>,
) -> EvolutionConfigBuilder<C, O, S, K>
pub fn with_strategy( self, strategy: Box<dyn EvolutionStrategy<Solution = S, Context = C, Objective = O>>, ) -> EvolutionConfigBuilder<C, O, S, K>
Sets a different heuristic replacing initial.
Sourcepub fn with_search_operators(
self,
search_operators: Vec<(Arc<dyn HeuristicSearchOperator<Solution = S, Context = C, Objective = O> + Send + Sync>, String, f64)>,
) -> EvolutionConfigBuilder<C, O, S, K>
pub fn with_search_operators( self, search_operators: Vec<(Arc<dyn HeuristicSearchOperator<Solution = S, Context = C, Objective = O> + Send + Sync>, String, f64)>, ) -> EvolutionConfigBuilder<C, O, S, K>
Sets search operators for dynamic heuristic.
Sourcepub fn with_diversify_operators(
self,
diversify_operators: Vec<Arc<dyn HeuristicDiversifyOperator<Objective = O, Context = C, Solution = S> + Send + Sync>>,
) -> EvolutionConfigBuilder<C, O, S, K>
pub fn with_diversify_operators( self, diversify_operators: Vec<Arc<dyn HeuristicDiversifyOperator<Objective = O, Context = C, Solution = S> + Send + Sync>>, ) -> EvolutionConfigBuilder<C, O, S, K>
Sets diversify operators for dynamic heuristic.
Sourcepub fn build(self) -> Result<EvolutionConfig<C, O, S>, GenericError>
pub fn build(self) -> Result<EvolutionConfig<C, O, S>, GenericError>
Builds the evolution config.
Examples found in repository?
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
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}
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}
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<C, O, S, K> Default for EvolutionConfigBuilder<C, O, S, K>where
C: HeuristicContext<Objective = O, Solution = S> + Stateful<Key = K> + 'static,
O: HeuristicObjective<Solution = S> + 'static,
S: HeuristicSolution + 'static,
K: Hash + Eq + Clone + Send + Sync + 'static,
impl<C, O, S, K> Default for EvolutionConfigBuilder<C, O, S, K>where
C: HeuristicContext<Objective = O, Solution = S> + Stateful<Key = K> + 'static,
O: HeuristicObjective<Solution = S> + 'static,
S: HeuristicSolution + 'static,
K: Hash + Eq + Clone + Send + Sync + 'static,
Source§fn default() -> EvolutionConfigBuilder<C, O, S, K>
fn default() -> EvolutionConfigBuilder<C, O, S, K>
Auto Trait Implementations§
impl<C, O, S, K> Freeze for EvolutionConfigBuilder<C, O, S, K>
impl<C, O, S, K> !RefUnwindSafe for EvolutionConfigBuilder<C, O, S, K>
impl<C, O, S, K> !Send for EvolutionConfigBuilder<C, O, S, K>
impl<C, O, S, K> !Sync for EvolutionConfigBuilder<C, O, S, K>
impl<C, O, S, K> Unpin for EvolutionConfigBuilder<C, O, S, K>
impl<C, O, S, K> !UnwindSafe for EvolutionConfigBuilder<C, O, S, K>
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
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>
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>
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