Configure solver stopping criteria
mainSolvers accept a Progress state at construction to determine when Minimize should return. You can use built-in presets or customize them.
1. Default Stopping: DefaultStoppingSolverProgress
Best for well-conditioned problems. It terminates when:
- Gradient norm: $|g|\infty < 1e-5 \times \max(1, |x|\infty)$
- Plateau: The objective moves by less than $1e-6$ (relative to $\max(1, |f|)$) over the last 3 iterations.
auto stop = cppoptlib::solver::DefaultStoppingSolverProgress<Fn, State>();
cppoptlib::solver::Lbfgs<Fn> solver(stop);2. Conservative Stopping: ConservativeStoppingSolverProgress
Use this when the objective has flat regions (e.g., degenerate saddles or valleys) where the default might mistake a plateau for a minimum. It uses much tighter tolerances:
- Gradient norm:
5e-6 - Plateau window:
5iterations - Plateau delta:
1e-10
auto stop = cppoptlib::solver::ConservativeStoppingSolverProgress<Fn, State>();
cppoptlib::solver::Lbfgs<Fn> solver(stop);3. Customizing via Per-field Overrides
Both presets return a plain struct. You can modify individual fields to create a custom stopping condition without copying the whole preset.
auto stop = cppoptlib::solver::DefaultStoppingSolverProgress<Fn, State>();
stop.num_iterations = 500;
stop.gradient_norm = 1e-7;
cppoptlib::solver::Lbfgs<Fn> solver(stop);