Skip to main content

OptimProblem

Struct OptimProblem 

Source
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>

Source

pub fn new(n: usize) -> Self

Create a new problem with n decision variables.

Source

pub fn x0(self, x0: &[S]) -> Self

Set the initial point.

Source

pub fn bounds(self, i: usize, lo_hi: (S, S)) -> Self

Set bounds for variable i.

Source

pub fn all_bounds(self, bounds: &[(S, S)]) -> Self

Set bounds for all variables at once.

Source

pub fn integer_var(self, i: usize) -> Self

Mark variable i as integer-valued.

Source

pub fn binary_var(self, i: usize) -> Self

Mark variable i as binary (0 or 1).

Source

pub fn objective<F: Fn(&[S]) -> S + 'static>(self, f: F) -> Self

Set a scalar objective function to minimize.

Source

pub fn gradient<G: Fn(&[S], &mut [S]) + 'static>(self, g: G) -> Self

Set the gradient for the scalar objective.

Source

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.

Source

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.

Source

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.

Source

pub fn jacobian<J: Fn(&[S], &mut [S]) + 'static>(self, j: J) -> Self

Set the Jacobian for a least-squares objective.

Source

pub fn linear_objective(self, c: &[S]) -> Self

Set a linear objective: minimize c^T x.

Source

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.

Source

pub fn linear_constraint_ineq(self, a: &[S], b: S) -> Self

Add a linear inequality constraint: a^T x <= b.

Source

pub fn linear_constraint_eq(self, a: &[S], b: S) -> Self

Add a linear equality constraint: a^T x = b.

Source

pub fn constraint_ineq<F: Fn(&[S]) -> S + 'static>(self, f: F) -> Self

Add an inequality constraint g(x) <= 0.

Source

pub fn constraint_eq<F: Fn(&[S]) -> S + 'static>(self, f: F) -> Self

Add an equality constraint h(x) = 0.

Source

pub fn constraint_ineq_with_grad<F, G>(self, f: F, g: G) -> Self
where F: Fn(&[S]) -> S + 'static, G: Fn(&[S], &mut [S]) + 'static,

Add an inequality constraint with gradient.

Source

pub fn constraint_eq_with_grad<F, G>(self, f: F, g: G) -> Self
where F: Fn(&[S]) -> S + 'static, G: Fn(&[S], &mut [S]) + 'static,

Add an equality constraint with gradient.

Source

pub fn max_iter(self, n: usize) -> Self

Set maximum iterations.

Source

pub fn gtol(self, tol: S) -> Self

Set gradient tolerance.

Source

pub fn options(self, opts: OptimOptions<S>) -> Self

Override all options.

Source

pub fn aug_lag_options(self, opts: AugLagOptions<S>) -> Self

Set augmented Lagrangian options for constrained problems.

Source

pub fn ctol(self, tol: S) -> Self

Set the constraint tolerance for constrained problems.

Source

pub fn global(self, enabled: bool) -> Self

Enable global optimization (Differential Evolution).

Source

pub fn de_options(self, opts: DEOptions<S>) -> Self

Set Differential Evolution options.

Source

pub fn multi_objective(self, funcs: Vec<ScalarFn<S>>) -> Self

Set multiple objectives for multi-objective optimization (all minimized).

Source

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.

Source

pub fn has_bounds(&self) -> bool

Returns true if any variable has bounds.

Source

pub fn has_constraints(&self) -> bool

Returns true if constraints have been added.

Source

pub fn is_least_squares(&self) -> bool

Returns true if the objective is a least-squares residual.

Source

pub fn is_linear(&self) -> bool

Returns true if the objective is structurally linear (coefficient vector).

Source

pub fn is_quadratic(&self) -> bool

Returns true if the objective is structurally quadratic (Hessian + linear).

Source

pub fn is_hint_linear(&self) -> bool

Returns true if a linear hint is set (closure known to be linear).

Source

pub fn is_hint_quadratic(&self) -> bool

Returns true if a quadratic hint is set (closure known to be quadratic).

Source

pub fn is_multi_objective(&self) -> bool

Returns true if the objective is multi-objective.

Source

pub fn has_linear_constraints(&self) -> bool

Returns true if linear constraints have been added.

Source

pub fn has_integer_vars(&self) -> bool

Returns true if any variable is integer or binary.

Source

pub fn n_eq_constraints(&self) -> usize

Number of equality constraints.

Source

pub fn n_ineq_constraints(&self) -> usize

Number of inequality constraints.

Source§

impl<S: Scalar + SimpleEntity + Conjugate<Canonical = S> + ComplexField> OptimProblem<S>

Source

pub fn solve(self) -> Result<OptimResult<S>, OptimError>

Solve using automatic solver selection.

Source

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V