Skip to main content

Config

Struct Config 

Source
pub struct Config {
    pub strategy: Strategy,
    pub spacing: f64,
    pub margin: f64,
    pub time_limit_ms: u64,
    pub target_utilization: Option<f64>,
    pub population_size: Option<usize>,
    pub max_generations: Option<u32>,
    pub max_iterations: Option<u64>,
    pub crossover_rate: f64,
    pub mutation_rate: f64,
    pub elite_count: usize,
    pub seed: Option<u64>,
}
Expand description

Common configuration for solvers.

It holds no thread count: a build with the parallel feature runs its parallel work on the rayon pool the solve is called from, so rayon::ThreadPool::install around the solve (or RAYON_NUM_THREADS) bounds it; without the feature a solve runs on the calling thread.

Fields§

§strategy: Strategy

Optimization strategy.

§spacing: f64

Minimum distance between any two placed geometries. It does not apply between a geometry and the boundary — that is margin.

§margin: f64

Minimum distance between any placed geometry and the boundary edge.

§time_limit_ms: u64

Maximum computation time in milliseconds (0 = unlimited).

The search strategies check it between individual placements, so a solve returns within the limit plus the time of the greedy bottom-left pass it is compared against. The layout returned is the best one found in that time.

§target_utilization: Option<f64>

Target utilization (0.0 - 1.0). Solver stops if reached.

§population_size: Option<usize>

Population size for the population-based strategies (GA, BRKGA).

None runs each strategy with the size it is tuned for – 2D GA and BRKGA 30, 3D GA 100, 3D BRKGA 50; Some(n) runs it with n, at least 2. The other strategies have no population and do not read it.

§max_generations: Option<u32>

Generation budget for the population-based strategies (GA, BRKGA).

None runs each strategy with the budget it is tuned for – 2D GA and BRKGA 50, 3D GA 500, 3D BRKGA 100; Some(n) allows n generations (0 evaluates the first population only). A run also ends on the time limit, on cancellation and when the best layout stops improving.

§max_iterations: Option<u64>

Iteration budget for the single-solution searches (SA, GDRR, ALNS).

None runs each with the budget it is tuned for – 2D SA 500, GDRR and ALNS 1000, 3D SA 10000; Some(n) allows n iterations (at least one). A seeded run that ends on this budget, not on the clock, is reproduced exactly (see Config::seed). A run also ends on the time limit and on cancellation, and SA when it has cooled.

§crossover_rate: f64

Crossover rate for GA (0.0 - 1.0).

§mutation_rate: f64

Mutation rate for GA (0.0 - 1.0).

§elite_count: usize

Elite count for GA.

§seed: Option<u64>

Optional RNG seed for reproducible runs of the stochastic strategies (GA, BRKGA, SA, GDRR, ALNS – 2D and 3D). None seeds from system entropy (non-deterministic).

A seeded run draws every random choice from the seed, so the same request with the same seed returns the same layout when the run ends on its own budget – the generation or iteration count, convergence, or the target utilization. A run cut short by the clock is not reproduced: how far a search gets before time_limit_ms (or a cancellation) stops it depends on the machine and its load. With time_limit_ms 0 a search runs to its own budget (max_generations, max_iterations), so a seeded unlimited run is always reproduced.

Implementations§

Source§

impl Config

Source

pub fn new() -> Self

Creates a new configuration with default values.

Source

pub fn validate(&self) -> Result<()>

Checks the fields a caller sets against their ranges – the builders store what they are given, and every solver calls this before it runs.

§Errors

ConfigError naming the first field out of range: spacing or margin negative or not finite, crossover_rate/mutation_rate or target_utilization outside [0, 1], a population_size set below 2, a max_iterations set to 0.

Source

pub fn with_strategy(self, strategy: Strategy) -> Self

Sets the optimization strategy.

Source

pub fn with_spacing(self, spacing: f64) -> Self

Sets the spacing between geometries.

Source

pub fn with_margin(self, margin: f64) -> Self

Sets the margin from boundary edges.

Source

pub fn with_time_limit(self, ms: u64) -> Self

Sets the time limit in milliseconds.

Source

pub fn with_target_utilization(self, util: f64) -> Self

Sets the target utilization.

Source

pub fn with_seed(self, seed: u64) -> Self

Sets the RNG seed for reproducible stochastic runs (see Config::seed).

Source

pub fn with_population_size(self, size: usize) -> Self

Sets the population size of the population-based strategies, in place of each strategy’s own (see Config::population_size).

Source

pub fn with_max_generations(self, generations: u32) -> Self

Sets the generation budget of the population-based strategies, in place of each strategy’s own (see Config::max_generations).

Source

pub fn with_max_iterations(self, iterations: u64) -> Self

Sets the iteration budget of the single-solution searches, in place of each strategy’s own (see Config::max_iterations).

Trait Implementations§

Source§

impl Clone for Config

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Config

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Config

Source§

fn default() -> Self

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

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.