diff --git a/crates/argmin/src/core/executor.rs b/crates/argmin/src/core/executor.rs index 0bdec8e28..f64bb652b 100644 --- a/crates/argmin/src/core/executor.rs +++ b/crates/argmin/src/core/executor.rs @@ -179,7 +179,8 @@ where let kv = kv.unwrap_or(kv![]); // Observe after init - self.observers.observe_init(S::NAME, &state, &kv)?; + self.observers + .observe_init(self.solver.name(), &state, &kv)?; } state.func_counts(&self.problem); @@ -680,7 +681,9 @@ mod tests { P: Clone, F: ArgminFloat, { - const NAME: &'static str = "OptimizationAlgorithm"; + fn name(&self) -> &str { + "OptimizationAlgorithm" + } // Only resets internal_state to 1 fn init( diff --git a/crates/argmin/src/core/result.rs b/crates/argmin/src/core/result.rs index 10eb309ef..359857382 100644 --- a/crates/argmin/src/core/result.rs +++ b/crates/argmin/src/core/result.rs @@ -124,7 +124,7 @@ where { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { writeln!(f, "OptimizationResult:")?; - writeln!(f, " Solver: {}", S::NAME)?; + writeln!(f, " Solver: {}", self.solver.name())?; writeln!( f, " param (best): {}", diff --git a/crates/argmin/src/core/solver.rs b/crates/argmin/src/core/solver.rs index c0eea88e7..86ba727cf 100644 --- a/crates/argmin/src/core/solver.rs +++ b/crates/argmin/src/core/solver.rs @@ -33,7 +33,7 @@ use crate::core::{Error, Problem, State, TerminationReason, TerminationStatus, K /// P: Clone, /// F: ArgminFloat /// { -/// const NAME: &'static str = "OptimizationAlgorithm"; +/// fn name(&self) -> &str { "OptimizationAlgorithm" } /// /// fn init( /// &mut self, @@ -64,7 +64,7 @@ use crate::core::{Error, Problem, State, TerminationReason, TerminationStatus, K /// ``` pub trait Solver { /// Name of the solver. Mainly used in [Observers](`crate::core::observers::Observe`). - const NAME: &'static str; + fn name(&self) -> &str; /// Initializes the algorithm. /// diff --git a/crates/argmin/src/core/test_utils.rs b/crates/argmin/src/core/test_utils.rs index b73ca1252..1803025e4 100644 --- a/crates/argmin/src/core/test_utils.rs +++ b/crates/argmin/src/core/test_utils.rs @@ -327,7 +327,9 @@ impl TestSolver { } impl Solver, (), (), (), (), f64>> for TestSolver { - const NAME: &'static str = "TestSolver"; + fn name(&self) -> &str { + "TestSolver" + } fn next_iter( &mut self, diff --git a/crates/argmin/src/solver/brent/brentopt.rs b/crates/argmin/src/solver/brent/brentopt.rs index 07eb9882e..ade3e820e 100644 --- a/crates/argmin/src/solver/brent/brentopt.rs +++ b/crates/argmin/src/solver/brent/brentopt.rs @@ -102,7 +102,9 @@ where O: CostFunction, F: ArgminFloat, { - const NAME: &'static str = "BrentOpt"; + fn name(&self) -> &str { + "BrentOpt" + } fn init( &mut self, diff --git a/crates/argmin/src/solver/brent/brentroot.rs b/crates/argmin/src/solver/brent/brentroot.rs index 7a841ca94..108cad96f 100644 --- a/crates/argmin/src/solver/brent/brentroot.rs +++ b/crates/argmin/src/solver/brent/brentroot.rs @@ -80,7 +80,9 @@ where O: CostFunction, F: ArgminFloat, { - const NAME: &'static str = "BrentRoot"; + fn name(&self) -> &str { + "BrentRoot" + } fn init( &mut self, diff --git a/crates/argmin/src/solver/conjugategradient/cg.rs b/crates/argmin/src/solver/conjugategradient/cg.rs index 1a0284164..43fe0b13f 100644 --- a/crates/argmin/src/solver/conjugategradient/cg.rs +++ b/crates/argmin/src/solver/conjugategradient/cg.rs @@ -91,7 +91,9 @@ where R: ArgminMul + ArgminMul + ArgminConj + ArgminDot + ArgminScaledAdd, F: ArgminFloat + ArgminL2Norm, { - const NAME: &'static str = "Conjugate Gradient"; + fn name(&self) -> &str { + "Conjugate Gradient" + } fn init( &mut self, diff --git a/crates/argmin/src/solver/conjugategradient/nonlinear_cg.rs b/crates/argmin/src/solver/conjugategradient/nonlinear_cg.rs index 0d373af2a..74ecf7167 100644 --- a/crates/argmin/src/solver/conjugategradient/nonlinear_cg.rs +++ b/crates/argmin/src/solver/conjugategradient/nonlinear_cg.rs @@ -128,7 +128,9 @@ where B: NLCGBetaUpdate, F: ArgminFloat, { - const NAME: &'static str = "Nonlinear Conjugate Gradient"; + fn name(&self) -> &str { + "Nonlinear Conjugate Gradient" + } fn init( &mut self, diff --git a/crates/argmin/src/solver/gaussnewton/gaussnewton_linesearch.rs b/crates/argmin/src/solver/gaussnewton/gaussnewton_linesearch.rs index 400499483..1bd50cce9 100644 --- a/crates/argmin/src/solver/gaussnewton/gaussnewton_linesearch.rs +++ b/crates/argmin/src/solver/gaussnewton/gaussnewton_linesearch.rs @@ -96,7 +96,9 @@ where F: ArgminFloat, R: Clone, { - const NAME: &'static str = "Gauss-Newton method with line search"; + fn name(&self) -> &str { + "Gauss-Newton method with line search" + } fn next_iter( &mut self, diff --git a/crates/argmin/src/solver/gaussnewton/gaussnewton_method.rs b/crates/argmin/src/solver/gaussnewton/gaussnewton_method.rs index b7faf0195..4160b54a3 100644 --- a/crates/argmin/src/solver/gaussnewton/gaussnewton_method.rs +++ b/crates/argmin/src/solver/gaussnewton/gaussnewton_method.rs @@ -122,7 +122,9 @@ where + ArgminDot, F: ArgminFloat, { - const NAME: &'static str = "Gauss-Newton method"; + fn name(&self) -> &str { + "Gauss-Newton method" + } fn init( &mut self, diff --git a/crates/argmin/src/solver/goldensectionsearch/mod.rs b/crates/argmin/src/solver/goldensectionsearch/mod.rs index 67044ee7c..0fe6b934f 100644 --- a/crates/argmin/src/solver/goldensectionsearch/mod.rs +++ b/crates/argmin/src/solver/goldensectionsearch/mod.rs @@ -139,7 +139,9 @@ where O: CostFunction, F: ArgminFloat, { - const NAME: &'static str = "Golden-section search"; + fn name(&self) -> &str { + "Golden-section search" + } fn init( &mut self, diff --git a/crates/argmin/src/solver/gradientdescent/steepestdescent.rs b/crates/argmin/src/solver/gradientdescent/steepestdescent.rs index 63fe32f4b..215a75481 100644 --- a/crates/argmin/src/solver/gradientdescent/steepestdescent.rs +++ b/crates/argmin/src/solver/gradientdescent/steepestdescent.rs @@ -58,7 +58,9 @@ where L: Clone + LineSearch + Solver>, F: ArgminFloat, { - const NAME: &'static str = "Steepest Descent"; + fn name(&self) -> &str { + "Steepest Descent" + } fn next_iter( &mut self, diff --git a/crates/argmin/src/solver/landweber/mod.rs b/crates/argmin/src/solver/landweber/mod.rs index 3b168ba10..a261a6719 100644 --- a/crates/argmin/src/solver/landweber/mod.rs +++ b/crates/argmin/src/solver/landweber/mod.rs @@ -69,7 +69,9 @@ where P: Clone + ArgminScaledSub, F: ArgminFloat, { - const NAME: &'static str = "Landweber"; + fn name(&self) -> &str { + "Landweber" + } fn next_iter( &mut self, diff --git a/crates/argmin/src/solver/linesearch/backtracking.rs b/crates/argmin/src/solver/linesearch/backtracking.rs index e0a6a346d..e5acbd92c 100644 --- a/crates/argmin/src/solver/linesearch/backtracking.rs +++ b/crates/argmin/src/solver/linesearch/backtracking.rs @@ -183,7 +183,9 @@ where L: LineSearchCondition, F: ArgminFloat, { - const NAME: &'static str = "Backtracking line search"; + fn name(&self) -> &str { + "Backtracking line search" + } fn init( &mut self, diff --git a/crates/argmin/src/solver/linesearch/hagerzhang.rs b/crates/argmin/src/solver/linesearch/hagerzhang.rs index cb345c61d..4a7d7e4c1 100644 --- a/crates/argmin/src/solver/linesearch/hagerzhang.rs +++ b/crates/argmin/src/solver/linesearch/hagerzhang.rs @@ -502,7 +502,9 @@ where G: Clone + ArgminDot, F: ArgminFloat, { - const NAME: &'static str = "Hager-Zhang line search"; + fn name(&self) -> &str { + "Hager-Zhang line search" + } fn init( &mut self, diff --git a/crates/argmin/src/solver/linesearch/morethuente.rs b/crates/argmin/src/solver/linesearch/morethuente.rs index b1040979c..b52f193b7 100644 --- a/crates/argmin/src/solver/linesearch/morethuente.rs +++ b/crates/argmin/src/solver/linesearch/morethuente.rs @@ -302,7 +302,9 @@ where G: Clone + ArgminDot, F: ArgminFloat, { - const NAME: &'static str = "More-Thuente Line search"; + fn name(&self) -> &str { + "More-Thuente Line search" + } fn init( &mut self, diff --git a/crates/argmin/src/solver/neldermead/mod.rs b/crates/argmin/src/solver/neldermead/mod.rs index 1ac5e40e3..3a1d04971 100644 --- a/crates/argmin/src/solver/neldermead/mod.rs +++ b/crates/argmin/src/solver/neldermead/mod.rs @@ -322,7 +322,9 @@ where P: Clone + ArgminSub + ArgminAdd + ArgminMul, F: ArgminFloat + std::iter::Sum, { - const NAME: &'static str = "Nelder-Mead method"; + fn name(&self) -> &str { + "Nelder-Mead method" + } fn init( &mut self, diff --git a/crates/argmin/src/solver/newton/newton_cg.rs b/crates/argmin/src/solver/newton/newton_cg.rs index d9d9b9d57..0cd75e988 100644 --- a/crates/argmin/src/solver/newton/newton_cg.rs +++ b/crates/argmin/src/solver/newton/newton_cg.rs @@ -120,7 +120,9 @@ where L: Clone + LineSearch + Solver>, F: ArgminFloat + ArgminL2Norm, { - const NAME: &'static str = "Newton-CG"; + fn name(&self) -> &str { + "Newton-CG" + } fn next_iter( &mut self, diff --git a/crates/argmin/src/solver/newton/newton_method.rs b/crates/argmin/src/solver/newton/newton_method.rs index 792d3c9b8..44a7f3a8b 100644 --- a/crates/argmin/src/solver/newton/newton_method.rs +++ b/crates/argmin/src/solver/newton/newton_method.rs @@ -91,7 +91,9 @@ where H: ArgminInv + ArgminDot, F: ArgminFloat, { - const NAME: &'static str = "Newton method"; + fn name(&self) -> &str { + "Newton method" + } fn next_iter( &mut self, diff --git a/crates/argmin/src/solver/particleswarm/mod.rs b/crates/argmin/src/solver/particleswarm/mod.rs index dabfcf333..57623a8cc 100644 --- a/crates/argmin/src/solver/particleswarm/mod.rs +++ b/crates/argmin/src/solver/particleswarm/mod.rs @@ -289,7 +289,9 @@ where F: ArgminFloat, R: Rng, { - const NAME: &'static str = "Particle Swarm Optimization"; + fn name(&self) -> &str { + "Particle Swarm Optimization" + } fn init( &mut self, diff --git a/crates/argmin/src/solver/quasinewton/bfgs.rs b/crates/argmin/src/solver/quasinewton/bfgs.rs index cfb5eb280..d7f967560 100644 --- a/crates/argmin/src/solver/quasinewton/bfgs.rs +++ b/crates/argmin/src/solver/quasinewton/bfgs.rs @@ -145,7 +145,9 @@ where L: Clone + LineSearch + Solver>, F: ArgminFloat, { - const NAME: &'static str = "BFGS"; + fn name(&self) -> &str { + "BFGS" + } fn init( &mut self, diff --git a/crates/argmin/src/solver/quasinewton/dfp.rs b/crates/argmin/src/solver/quasinewton/dfp.rs index 08ff7803b..26858c657 100644 --- a/crates/argmin/src/solver/quasinewton/dfp.rs +++ b/crates/argmin/src/solver/quasinewton/dfp.rs @@ -104,7 +104,9 @@ where L: Clone + LineSearch + Solver>, F: ArgminFloat, { - const NAME: &'static str = "DFP"; + fn name(&self) -> &str { + "DFP" + } fn init( &mut self, diff --git a/crates/argmin/src/solver/quasinewton/lbfgs.rs b/crates/argmin/src/solver/quasinewton/lbfgs.rs index 03c49f6f9..409eb51eb 100644 --- a/crates/argmin/src/solver/quasinewton/lbfgs.rs +++ b/crates/argmin/src/solver/quasinewton/lbfgs.rs @@ -333,7 +333,9 @@ where + Solver, IterState>, F: ArgminFloat, { - const NAME: &'static str = "L-BFGS"; + fn name(&self) -> &str { + "L-BFGS" + } fn init( &mut self, diff --git a/crates/argmin/src/solver/quasinewton/sr1.rs b/crates/argmin/src/solver/quasinewton/sr1.rs index a7f4a0956..dc14aae87 100644 --- a/crates/argmin/src/solver/quasinewton/sr1.rs +++ b/crates/argmin/src/solver/quasinewton/sr1.rs @@ -159,7 +159,9 @@ where L: Clone + LineSearch + Solver>, F: ArgminFloat, { - const NAME: &'static str = "SR1"; + fn name(&self) -> &str { + "SR1" + } fn init( &mut self, diff --git a/crates/argmin/src/solver/quasinewton/sr1_trustregion.rs b/crates/argmin/src/solver/quasinewton/sr1_trustregion.rs index e1ee83f1b..a7d5435dd 100644 --- a/crates/argmin/src/solver/quasinewton/sr1_trustregion.rs +++ b/crates/argmin/src/solver/quasinewton/sr1_trustregion.rs @@ -196,7 +196,9 @@ where R: Clone + TrustRegionRadius + Solver>, F: ArgminFloat + ArgminL2Norm, { - const NAME: &'static str = "SR1 trust region"; + fn name(&self) -> &str { + "SR1 trust region" + } fn init( &mut self, diff --git a/crates/argmin/src/solver/simulatedannealing/mod.rs b/crates/argmin/src/solver/simulatedannealing/mod.rs index c1ae80678..c22277a1d 100644 --- a/crates/argmin/src/solver/simulatedannealing/mod.rs +++ b/crates/argmin/src/solver/simulatedannealing/mod.rs @@ -442,7 +442,9 @@ where F: ArgminFloat, R: Rng, { - const NAME: &'static str = "Simulated Annealing"; + fn name(&self) -> &str { + "Simulated Annealing" + } fn init( &mut self, problem: &mut Problem, diff --git a/crates/argmin/src/solver/trustregion/cauchypoint.rs b/crates/argmin/src/solver/trustregion/cauchypoint.rs index 56149d954..4b6a96097 100644 --- a/crates/argmin/src/solver/trustregion/cauchypoint.rs +++ b/crates/argmin/src/solver/trustregion/cauchypoint.rs @@ -58,7 +58,9 @@ where G: ArgminMul + ArgminWeightedDot + ArgminL2Norm, F: ArgminFloat, { - const NAME: &'static str = "Cauchy Point"; + fn name(&self) -> &str { + "Cauchy Point" + } fn next_iter( &mut self, diff --git a/crates/argmin/src/solver/trustregion/dogleg.rs b/crates/argmin/src/solver/trustregion/dogleg.rs index 97b4f70d9..16e75e00b 100644 --- a/crates/argmin/src/solver/trustregion/dogleg.rs +++ b/crates/argmin/src/solver/trustregion/dogleg.rs @@ -65,7 +65,9 @@ where H: ArgminInv + ArgminDot, F: ArgminFloat, { - const NAME: &'static str = "Dogleg"; + fn name(&self) -> &str { + "Dogleg" + } fn next_iter( &mut self, diff --git a/crates/argmin/src/solver/trustregion/steihaug.rs b/crates/argmin/src/solver/trustregion/steihaug.rs index 17892eea0..2f69846bd 100644 --- a/crates/argmin/src/solver/trustregion/steihaug.rs +++ b/crates/argmin/src/solver/trustregion/steihaug.rs @@ -189,7 +189,9 @@ where H: ArgminDot, F: ArgminFloat, { - const NAME: &'static str = "Steihaug"; + fn name(&self) -> &str { + "Steihaug" + } fn init( &mut self, diff --git a/crates/argmin/src/solver/trustregion/trustregion_method.rs b/crates/argmin/src/solver/trustregion/trustregion_method.rs index 8996cb68f..b9c0aaf57 100644 --- a/crates/argmin/src/solver/trustregion/trustregion_method.rs +++ b/crates/argmin/src/solver/trustregion/trustregion_method.rs @@ -167,7 +167,9 @@ where R: Clone + TrustRegionRadius + Solver>, F: ArgminFloat, { - const NAME: &'static str = "Trust region"; + fn name(&self) -> &str { + "Trust region" + } fn init( &mut self, diff --git a/media/book/src/implementing_solver.md b/media/book/src/implementing_solver.md index 8255c48b0..05fec0c94 100644 --- a/media/book/src/implementing_solver.md +++ b/media/book/src/implementing_solver.md @@ -98,7 +98,7 @@ where F: ArgminFloat, { // This gives the solver a name which will be used for logging - const NAME: &'static str = "Landweber"; + fn name(&self) -> &str { "Landweber" } // Defines the computations performed in a single iteration. fn next_iter(