pub struct Constraint {
pub fun: Box<dyn Fn(&[f64]) -> f64 + Send + Sync>,
pub jac: Option<Box<dyn Fn(&[f64]) -> Array1<f64> + Send + Sync>>,
pub kind: ConstraintKind,
pub lb: Option<f64>,
pub ub: Option<f64>,
}Expand description
Constraint type for constrained optimization.
The constraint callable is stored as a boxed trait object so that a
Vec<Constraint> can hold heterogeneous closures (issue #126). Closures
that capture outer variables (for example a threshold) are accepted via
Constraint::new. An optional analytical Jacobian (gradient of the
constraint with respect to each variable) can be attached via
Constraint::with_jacobian (issue #127); when present the solvers use it
instead of finite differences.
Fields§
§fun: Box<dyn Fn(&[f64]) -> f64 + Send + Sync>The constraint function
jac: Option<Box<dyn Fn(&[f64]) -> Array1<f64> + Send + Sync>>Optional analytical Jacobian (gradient) of the constraint, returning a
length-n vector of partial derivatives. None selects finite
differences.
kind: ConstraintKindThe type of constraint (equality or inequality)
lb: Option<f64>Lower bound for a box constraint
ub: Option<f64>Upper bound for a box constraint
Implementations§
Source§impl Constraint
impl Constraint
Sourcepub const EQUALITY: ConstraintKind = ConstraintKind::Equality
pub const EQUALITY: ConstraintKind = ConstraintKind::Equality
Constant for equality constraint
Sourcepub const INEQUALITY: ConstraintKind = ConstraintKind::Inequality
pub const INEQUALITY: ConstraintKind = ConstraintKind::Inequality
Constant for inequality constraint
Sourcepub fn new<F>(fun: F, kind: ConstraintKind) -> Self
pub fn new<F>(fun: F, kind: ConstraintKind) -> Self
Create a new constraint.
Accepts any callable implementing Fn(&[f64]) -> f64, including
closures that capture outer variables and plain fn pointers.
Sourcepub fn with_jacobian<J>(self, jac: J) -> Self
pub fn with_jacobian<J>(self, jac: J) -> Self
Attach an analytical Jacobian (gradient) for this constraint (issue #127).
The supplied callable returns the length-n gradient of the constraint
with respect to each variable, which fills one row of the constraint
Jacobian matrix. When present, the solvers use it instead of finite
differences.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for Constraint
impl !UnwindSafe for Constraint
impl Freeze for Constraint
impl Send for Constraint
impl Sync for Constraint
impl Unpin for Constraint
impl UnsafeUnpin for Constraint
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.