pub struct Config {
pub strategy: Strategy,
pub spacing: f64,
pub margin: f64,
pub time_limit_ms: u64,
pub target_utilization: Option<f64>,
pub threads: usize,
pub population_size: Option<usize>,
pub max_generations: Option<u32>,
pub crossover_rate: f64,
pub mutation_rate: f64,
pub elite_count: usize,
pub seed: Option<u64>,
}Expand description
Common configuration for solvers.
Fields§
§strategy: StrategyOptimization strategy.
spacing: f64Minimum distance between any two placed geometries. It does not apply
between a geometry and the boundary — that is margin.
margin: f64Minimum distance between any placed geometry and the boundary edge.
time_limit_ms: u64Maximum 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.
threads: usizeNumber of threads to use (0 = auto).
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.
crossover_rate: f64Crossover rate for GA (0.0 - 1.0).
mutation_rate: f64Mutation rate for GA (0.0 - 1.0).
elite_count: usizeElite 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. In 2D a
search keeps a time budget of its own even when time_limit_ms is 0
(15 s for GA and BRKGA, 10 s for SA, GDRR and ALNS), so a large 2D
request can reach it.
Implementations§
Source§impl Config
impl Config
Sourcepub fn validate(&self) -> Result<()>
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.
Sourcepub fn with_strategy(self, strategy: Strategy) -> Self
pub fn with_strategy(self, strategy: Strategy) -> Self
Sets the optimization strategy.
Sourcepub fn with_spacing(self, spacing: f64) -> Self
pub fn with_spacing(self, spacing: f64) -> Self
Sets the spacing between geometries.
Sourcepub fn with_margin(self, margin: f64) -> Self
pub fn with_margin(self, margin: f64) -> Self
Sets the margin from boundary edges.
Sourcepub fn with_time_limit(self, ms: u64) -> Self
pub fn with_time_limit(self, ms: u64) -> Self
Sets the time limit in milliseconds.
Sourcepub fn with_target_utilization(self, util: f64) -> Self
pub fn with_target_utilization(self, util: f64) -> Self
Sets the target utilization.
Sourcepub fn with_seed(self, seed: u64) -> Self
pub fn with_seed(self, seed: u64) -> Self
Sets the RNG seed for reproducible stochastic runs (see Config::seed).
Sourcepub fn with_population_size(self, size: usize) -> Self
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).
Sourcepub fn with_max_generations(self, generations: u32) -> Self
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).
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Config
impl RefUnwindSafe for Config
impl Send for Config
impl Sync for Config
impl Unpin for Config
impl UnsafeUnpin for Config
impl UnwindSafe for Config
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.