diff -r 9738b51d90d7 -r 4f468d35fa29 src/tolerance.rs --- a/src/tolerance.rs Sun Apr 27 15:03:51 2025 -0500 +++ b/src/tolerance.rs Thu Feb 26 11:38:43 2026 -0500 @@ -1,33 +1,33 @@ //! Tolerance update schemes for subproblem solution quality -use serde::{Serialize, Deserialize}; +use crate::types::*; use numeric_literals::replace_float_literals; -use crate::types::*; +use serde::{Deserialize, Serialize}; /// Update style for optimality system solution tolerance #[derive(Clone, Copy, Eq, PartialEq, Serialize, Deserialize, Debug)] #[allow(dead_code)] -pub enum Tolerance { +pub enum Tolerance { /// $ε_k = εθ^k$ for the `factor` $θ$ and initial tolerance $ε$. - Exponential{ factor : F, initial : F }, + Exponential { factor: F, initial: F }, /// $ε_k = ε/(1+θk)^p$ for the `factor` $θ$, `exponent` $p$, and initial tolerance $ε$. - Power{ factor : F, exponent : F, initial : F}, + Power { factor: F, exponent: F, initial: F }, /// $ε_k = εθ^{⌊k^p⌋}$ for the `factor` $θ$, initial tolerance $ε$, and exponent $p$. - SlowExp{ factor : F, exponent : F, initial : F } + SlowExp { factor: F, exponent: F, initial: F }, } #[replace_float_literals(F::cast_from(literal))] -impl Default for Tolerance { +impl Default for Tolerance { fn default() -> Self { Tolerance::Power { - initial : 0.5, - factor : 0.2, - exponent : 1.4 // 1.5 works but is already slower in practise on our examples. + initial: 0.5, + factor: 0.2, + exponent: 1.4, // 1.5 works but is already slower in practise on our examples. } } } #[replace_float_literals(F::cast_from(literal))] -impl Tolerance { +impl Tolerance { /// Get the initial tolerance pub fn initial(&self) -> F { match self { @@ -47,21 +47,19 @@ } /// Set the initial tolerance - pub fn set_initial(&mut self, set : F) { + pub fn set_initial(&mut self, set: F) { *self.initial_mut() = set; } /// Update `tolerance` for iteration `iter`. /// `tolerance` may or may not be used depending on the specific /// update scheme. - pub fn update(&self, tolerance : F, iter : usize) -> F { + pub fn update(&self, tolerance: F, iter: usize) -> F { match self { - &Tolerance::Exponential { factor, .. } => { - tolerance * factor - }, + &Tolerance::Exponential { factor, .. } => tolerance * factor, &Tolerance::Power { factor, exponent, initial } => { - initial /(1.0 + factor * F::cast_from(iter)).powf(exponent) - }, + initial / (1.0 + factor * F::cast_from(iter)).powf(exponent) + } &Tolerance::SlowExp { factor, exponent, initial } => { // let m = (speed // * factor.powi(-(iter as i32)) @@ -69,20 +67,20 @@ // ).floor().as_(); let m = F::cast_from(iter).powf(exponent).floor().as_(); initial * factor.powi(m) - }, + } } } } impl std::ops::MulAssign for Tolerance { - fn mul_assign(&mut self, factor : F) { + fn mul_assign(&mut self, factor: F) { *self.initial_mut() *= factor; } } impl std::ops::Mul for Tolerance { type Output = Tolerance; - fn mul(mut self, factor : F) -> Self::Output { + fn mul(mut self, factor: F) -> Self::Output { *self.initial_mut() *= factor; self }