pub struct OptimProblem<S: Scalar> { /* private fields */ }Expand description
Declarative optimization problem.
Build a problem with the fluent API, then call .solve() to automatically
dispatch to the best solver, or .solve_with(choice) for explicit control.
Implementations§
Source§impl<S: Scalar> OptimProblem<S>
impl<S: Scalar> OptimProblem<S>
Sourcepub fn all_bounds(self, bounds: &[(S, S)]) -> Self
pub fn all_bounds(self, bounds: &[(S, S)]) -> Self
Set bounds for all variables at once.
Sourcepub fn integer_var(self, i: usize) -> Self
pub fn integer_var(self, i: usize) -> Self
Mark variable i as integer-valued.
Sourcepub fn binary_var(self, i: usize) -> Self
pub fn binary_var(self, i: usize) -> Self
Mark variable i as binary (0 or 1).
Sourcepub fn objective<F: Fn(&[S]) -> S + 'static>(self, f: F) -> Self
pub fn objective<F: Fn(&[S]) -> S + 'static>(self, f: F) -> Self
Set a scalar objective function to minimize.
Sourcepub fn gradient<G: Fn(&[S], &mut [S]) + 'static>(self, g: G) -> Self
pub fn gradient<G: Fn(&[S], &mut [S]) + 'static>(self, g: G) -> Self
Set the gradient for the scalar objective.
Sourcepub fn maximize<F: Fn(&[S]) -> S + 'static>(self, f: F) -> Self
pub fn maximize<F: Fn(&[S]) -> S + 'static>(self, f: F) -> Self
Set a scalar objective function to maximize.
Internally converts to minimization by negating the objective and gradient.
Sourcepub fn maximize_gradient<G: Fn(&[S], &mut [S]) + 'static>(self, g: G) -> Self
pub fn maximize_gradient<G: Fn(&[S], &mut [S]) + 'static>(self, g: G) -> Self
Set the gradient for a maximization objective.
Note: provide the gradient of the ORIGINAL function (not negated). The builder handles negation internally.
Sourcepub fn least_squares<R: Fn(&[S], &mut [S]) + 'static>(
self,
n_residuals: usize,
residual: R,
) -> Self
pub fn least_squares<R: Fn(&[S], &mut [S]) + 'static>( self, n_residuals: usize, residual: R, ) -> Self
Set a least-squares objective: minimize ||r(x)||^2.
Sourcepub fn jacobian<J: Fn(&[S], &mut [S]) + 'static>(self, j: J) -> Self
pub fn jacobian<J: Fn(&[S], &mut [S]) + 'static>(self, j: J) -> Self
Set the Jacobian for a least-squares objective.
Sourcepub fn linear_objective(self, c: &[S]) -> Self
pub fn linear_objective(self, c: &[S]) -> Self
Set a linear objective: minimize c^T x.
Sourcepub fn quadratic_objective_dense(self, h_row_major: &[S], c: &[S]) -> Self
pub fn quadratic_objective_dense(self, h_row_major: &[S], c: &[S]) -> Self
Set a quadratic objective: minimize 1/2 x^T H x + c^T x.
h_row_major is the n x n Hessian in row-major order.
Sourcepub fn linear_constraint_ineq(self, a: &[S], b: S) -> Self
pub fn linear_constraint_ineq(self, a: &[S], b: S) -> Self
Add a linear inequality constraint: a^T x <= b.
Sourcepub fn linear_constraint_eq(self, a: &[S], b: S) -> Self
pub fn linear_constraint_eq(self, a: &[S], b: S) -> Self
Add a linear equality constraint: a^T x = b.
Sourcepub fn constraint_ineq<F: Fn(&[S]) -> S + 'static>(self, f: F) -> Self
pub fn constraint_ineq<F: Fn(&[S]) -> S + 'static>(self, f: F) -> Self
Add an inequality constraint g(x) <= 0.
Sourcepub fn constraint_eq<F: Fn(&[S]) -> S + 'static>(self, f: F) -> Self
pub fn constraint_eq<F: Fn(&[S]) -> S + 'static>(self, f: F) -> Self
Add an equality constraint h(x) = 0.
Sourcepub fn constraint_ineq_with_grad<F, G>(self, f: F, g: G) -> Self
pub fn constraint_ineq_with_grad<F, G>(self, f: F, g: G) -> Self
Add an inequality constraint with gradient.
Sourcepub fn constraint_eq_with_grad<F, G>(self, f: F, g: G) -> Self
pub fn constraint_eq_with_grad<F, G>(self, f: F, g: G) -> Self
Add an equality constraint with gradient.
Sourcepub fn options(self, opts: OptimOptions<S>) -> Self
pub fn options(self, opts: OptimOptions<S>) -> Self
Override all options.
Sourcepub fn aug_lag_options(self, opts: AugLagOptions<S>) -> Self
pub fn aug_lag_options(self, opts: AugLagOptions<S>) -> Self
Set augmented Lagrangian options for constrained problems.
Sourcepub fn global(self, enabled: bool) -> Self
pub fn global(self, enabled: bool) -> Self
Enable global optimization (Differential Evolution).
Sourcepub fn de_options(self, opts: DEOptions<S>) -> Self
pub fn de_options(self, opts: DEOptions<S>) -> Self
Set Differential Evolution options.
Sourcepub fn multi_objective(self, funcs: Vec<ScalarFn<S>>) -> Self
pub fn multi_objective(self, funcs: Vec<ScalarFn<S>>) -> Self
Set multiple objectives for multi-objective optimization (all minimized).
Sourcepub fn hint(self, hint: ProblemHint) -> Self
pub fn hint(self, hint: ProblemHint) -> Self
Provide a structural hint about the closure-based objective.
This informs auto solver selection when the objective is a closure that implements a linear or quadratic function but cannot be decomposed into coefficient vectors.
Sourcepub fn has_bounds(&self) -> bool
pub fn has_bounds(&self) -> bool
Returns true if any variable has bounds.
Sourcepub fn has_constraints(&self) -> bool
pub fn has_constraints(&self) -> bool
Returns true if constraints have been added.
Sourcepub fn is_least_squares(&self) -> bool
pub fn is_least_squares(&self) -> bool
Returns true if the objective is a least-squares residual.
Sourcepub fn is_linear(&self) -> bool
pub fn is_linear(&self) -> bool
Returns true if the objective is structurally linear (coefficient vector).
Sourcepub fn is_quadratic(&self) -> bool
pub fn is_quadratic(&self) -> bool
Returns true if the objective is structurally quadratic (Hessian + linear).
Sourcepub fn is_hint_linear(&self) -> bool
pub fn is_hint_linear(&self) -> bool
Returns true if a linear hint is set (closure known to be linear).
Sourcepub fn is_hint_quadratic(&self) -> bool
pub fn is_hint_quadratic(&self) -> bool
Returns true if a quadratic hint is set (closure known to be quadratic).
Sourcepub fn is_multi_objective(&self) -> bool
pub fn is_multi_objective(&self) -> bool
Returns true if the objective is multi-objective.
Sourcepub fn has_linear_constraints(&self) -> bool
pub fn has_linear_constraints(&self) -> bool
Returns true if linear constraints have been added.
Sourcepub fn has_integer_vars(&self) -> bool
pub fn has_integer_vars(&self) -> bool
Returns true if any variable is integer or binary.
Sourcepub fn n_eq_constraints(&self) -> usize
pub fn n_eq_constraints(&self) -> usize
Number of equality constraints.
Sourcepub fn n_ineq_constraints(&self) -> usize
pub fn n_ineq_constraints(&self) -> usize
Number of inequality constraints.
Source§impl<S: Scalar + SimpleEntity + Conjugate<Canonical = S> + ComplexField> OptimProblem<S>
impl<S: Scalar + SimpleEntity + Conjugate<Canonical = S> + ComplexField> OptimProblem<S>
Sourcepub fn solve(self) -> Result<OptimResult<S>, OptimError>
pub fn solve(self) -> Result<OptimResult<S>, OptimError>
Solve using automatic solver selection.
Sourcepub fn solve_with(
self,
choice: SolverChoice,
) -> Result<OptimResult<S>, OptimError>
pub fn solve_with( self, choice: SolverChoice, ) -> Result<OptimResult<S>, OptimError>
Solve using an explicitly chosen solver.
Auto Trait Implementations§
impl<S> Freeze for OptimProblem<S>where
S: Freeze,
impl<S> !RefUnwindSafe for OptimProblem<S>
impl<S> !Send for OptimProblem<S>
impl<S> !Sync for OptimProblem<S>
impl<S> Unpin for OptimProblem<S>where
S: Unpin,
impl<S> UnsafeUnpin for OptimProblem<S>where
S: UnsafeUnpin,
impl<S> !UnwindSafe for OptimProblem<S>
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> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more