pub fn minimize_constrained<F, S>(
func: F,
x0: &ArrayBase<S, Ix1>,
constraints: &[Constraint<ConstraintFn>],
method: Method,
options: Option<Options>,
) -> OptimizeResult<OptimizeResults<f64>>
Expand description
Minimizes a scalar function of one or more variables with constraints.
§Arguments
func
- A function that takes a slice of values and returns a scalarx0
- The initial guessconstraints
- Vector of constraintsmethod
- The optimization method to useoptions
- Options for the optimizer
§Returns
OptimizeResults
containing the optimization results
§Example
use ndarray::array;
use scirs2_optimize::constrained::{minimize_constrained, Method, Constraint};
// Function to minimize
fn objective(x: &[f64]) -> f64 {
(x[0] - 1.0).powi(2) + (x[1] - 2.5).powi(2)
}
// Constraint: x[0] + x[1] <= 3
fn constraint(x: &[f64]) -> f64 {
3.0 - x[0] - x[1] // Should be >= 0
}
let initial_point = array![0.0, 0.0];
let constraints = vec![Constraint::new(constraint, Constraint::INEQUALITY)];
let result = minimize_constrained(
objective,
&initial_point,
&constraints,
Method::SLSQP,
None
)?;