Struct EvolutionConfigBuilder

Source
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,

Source

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?
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
Hide additional 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 90)
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 101)
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}
Source

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?
examples/cvrp.rs (line 89)
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
Hide additional examples
examples/pdptw.rs (line 100)
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}
Source

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.

Source

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.

Source

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.

Source

pub fn with_processing( self, processing: ProcessingConfig<C, O, S>, ) -> EvolutionConfigBuilder<C, O, S, K>

Specifies processing configuration.

Source

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.

Source

pub fn with_objective( self, objective: Arc<dyn HeuristicObjective<Solution = S>>, ) -> EvolutionConfigBuilder<C, O, S, K>

Sets objective.

Source

pub fn with_context(self, context: C) -> EvolutionConfigBuilder<C, O, S, K>

Sets heuristic context.

Source

pub fn with_termination( self, termination: Box<dyn Termination<Context = C, Objective = O>>, ) -> EvolutionConfigBuilder<C, O, S, K>

Sets termination.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn build(self) -> Result<EvolutionConfig<C, O, S>, GenericError>

Builds the evolution config.

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
Hide additional 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 91)
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 102)
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,

Source§

fn default() -> EvolutionConfigBuilder<C, O, S, K>

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<C, O, S, K> Freeze for EvolutionConfigBuilder<C, O, S, K>
where C: Freeze, K: Freeze,

§

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>
where C: Unpin, K: Unpin, S: Unpin,

§

impl<C, O, S, K> !UnwindSafe for EvolutionConfigBuilder<C, O, S, K>

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