pub struct AlmFactory<MappingF1, JacobianMappingF1Trans, MappingF2, JacobianMappingF2Trans, Cost, CostGradient, SetC>
where Cost: Fn(&[f64], &mut f64) -> FunctionCallResult, CostGradient: Fn(&[f64], &mut [f64]) -> FunctionCallResult, MappingF1: Fn(&[f64], &mut [f64]) -> FunctionCallResult, JacobianMappingF1Trans: Fn(&[f64], &[f64], &mut [f64]) -> FunctionCallResult, MappingF2: Fn(&[f64], &mut [f64]) -> FunctionCallResult, JacobianMappingF2Trans: Fn(&[f64], &[f64], &mut [f64]) -> FunctionCallResult, SetC: Constraint,
{ /* private fields */ }
Expand description

Prepares function $\psi$ and its gradient given the problem data: $f$, $\nabla{}f$, and optionally $F_1$, $JF_1$, $C$ and $F_2$

§Types

  • Cost: cost function $f:\mathbb{R}^{n_u} \to \mathbb{R}$ which is computed by a function with signature:
fn f(u: &[f64], cost: &mut f64) -> FunctionCallResult

where cost is updated with the value $f(u)$,

  • CostGradient: gradient of the cost function, $\nabla f: \mathbb{R}^{n_u} \to \mathbb{R}^{n_u}$, which is computed by a function with signature
fn df(u: &[f64], grad: &mut [f64]) -> FunctionCallResult

where on exit grad stores the

  • MappingF1 and MappingF2: mappings $F_1:\mathbb{R}^n\to\mathbb{R}^{n_1}$ and $F_2:\mathbb{R}^n\to\mathbb{R}^{n_2}$ which are computed by functions with signature
fn mapping(u: &[f64], fu: &mut [f64]) -> FunctionCallResult
  • JacobianMappingF1Trans and JacobianMappingF2Trans: functions that compute product of the form $JF_i(u)^\top{}d$ for given $d\in\mathbb{R}^{n_i}$ and $u\in\mathbb{R}^{n_u}$

  • SetC: A set $C\subseteq \mathbb{R}^{n_1}$, which is used in the definition of the constraints $F_1(u) \in C$

The above are used to compute $\psi:\mathbb{R}^{n_u}\to\mathbb{R}$ for given $u\in\mathbb{R}^{n_u}$ and $\xi=(c, y)\in\mathbb{R}^{n_1+1}$, where $c\in\mathbb{R}$ and $y\in\mathbb{R}^{n_1}$ are the penalty parameter and vector of Lagrange multipliers respectively, according to

$$ \psi(u) = f(u) + \tfrac{c}{2}\left[\mathrm{dist}_C^2(F_1(u) + \bar{c}^{-1}y) + \Vert F_2(u) \Vert^2\right], $$

where $\bar{c} = \max\{1,c\}$ and

$$ \nabla \psi(u) = \nabla f(u) + c JF_1(u)^\top [t(u) - \Pi_C(t(u))] + c JF_2(u)^\top F_2(u). $$

where $t(u) = F_1(u) + \bar{c}^{-1}y$.

Implementations§

source§

impl<MappingF1, JacobianMappingF1Trans, MappingF2, JacobianMappingF2Trans, Cost, CostGradient, SetC> AlmFactory<MappingF1, JacobianMappingF1Trans, MappingF2, JacobianMappingF2Trans, Cost, CostGradient, SetC>
where Cost: Fn(&[f64], &mut f64) -> FunctionCallResult, CostGradient: Fn(&[f64], &mut [f64]) -> FunctionCallResult, MappingF1: Fn(&[f64], &mut [f64]) -> FunctionCallResult, JacobianMappingF1Trans: Fn(&[f64], &[f64], &mut [f64]) -> FunctionCallResult, MappingF2: Fn(&[f64], &mut [f64]) -> FunctionCallResult, JacobianMappingF2Trans: Fn(&[f64], &[f64], &mut [f64]) -> FunctionCallResult, SetC: Constraint,

source

pub fn new( f: Cost, df: CostGradient, mapping_f1: Option<MappingF1>, jacobian_mapping_f1_trans: Option<JacobianMappingF1Trans>, mapping_f2: Option<MappingF2>, jacobian_mapping_f2_trans: Option<JacobianMappingF2Trans>, set_c: Option<SetC>, n2: usize ) -> Self

Construct a new instance of MockFactory

§Arguments
  • f cost function $f$
  • df gradient of the cost function
  • mapping_f1 (optional) mapping $F_1$ or NO_MAPPING
  • jacobian_mapping_f1_trans (optional) $JF_1(u)^\intercal d$ or NO_JACOBIAN_MAPPING
  • mapping_f2 (optional) mapping $F_2$ or NO_MAPPING
  • jacobian_mapping_f2_trans $JF_2(u)^\intercal d$ or NO_JACOBIAN_MAPPING
  • set_c (optional) set $C$ or NO_SET
  • n2 image dimension of $F_2$ (can be 0)
§Example
use optimization_engine::{constraints::Ball2, alm::*, FunctionCallResult};

let set_c = Ball2::new(None, 1.0);
let n2 = 0;

let f = |u: &[f64], cost: &mut f64| -> FunctionCallResult { Ok(()) };
let df = |u: &[f64], grad: &mut [f64]| -> FunctionCallResult { Ok(()) };
let f1 = |u: &[f64], f1u: &mut [f64]| -> FunctionCallResult { Ok(()) };
let jf1_tr = |_u: &[f64], d: &[f64], res: &mut [f64]| -> FunctionCallResult { Ok(()) };

let factory = AlmFactory::new(
    f,
    df,
    Some(f1),
    Some(jf1_tr),
    NO_MAPPING,
    NO_JACOBIAN_MAPPING,
    Some(set_c),
    n2,
);
source

pub fn psi(&self, u: &[f64], xi: &[f64], cost: &mut f64) -> FunctionCallResult

Computes function $\psi$ given by

$$\psi(u) = f(u) + \tfrac{c}{2}\left[\mathrm{dist}_C^2\left(F_1(u) + \bar{c}^{-1}y\right) + \Vert F_2(u) \Vert^2\right],$$

where $\bar{c} = \max\{1,c\}$, $f:\mathbb{R}^{n_u}\to\mathbb{R}$ is a $C^{1,1}$ function, $F_1:\mathbb{R}^{n_u}\to\mathbb{R}^{n_1}$ and $F_2:\mathbb{R}^{n_u}\to\mathbb{R}^{n_2}$ are smooth mappings, $C\subseteq \mathbb{R}^{n_1}$ is a closed set on which we can compute projections and $c\in\mathbb{R}$ and $y\in\mathbb{R}^{n_1}$ are the penalty parameter and vector of Lagrange multipliers respectively.

§Arguments
  • u: vector $u$
  • xi is the vector $\xi = (c, y) \in \mathbb{R}^{n_1 + 1}$
  • cost: stores the value of $\psi(u; \xi)$ on exit
§Returns

This method returns Ok(()) if the computation is successful or an appropriate SolverError otherwise.

source

pub fn d_psi( &self, u: &[f64], xi: &[f64], grad: &mut [f64] ) -> FunctionCallResult

Computes the gradient of $\psi$

The gradient of psi is given by

$$\nabla \psi(u) = \nabla f(u) + c JF_1(u)^\top [t(u) - \Pi_C(t(u))] + c JF_2(u)^\top F_2(u),$$

where $t(u) = F_1(u) + \max\{1,c\}^{-1}y$.

§Arguments
  • u: vector $u$
  • xi is the vector $\xi = (c, y) \in \mathbb{R}^{n_1 + 1}$
  • grad: stores the value of $\nabla \psi(u; \xi)$ on exit
§Returns

This method returns Ok(()) if the computation is successful or an appropriate SolverError otherwise.

Auto Trait Implementations§

§

impl<MappingF1, JacobianMappingF1Trans, MappingF2, JacobianMappingF2Trans, Cost, CostGradient, SetC> Freeze for AlmFactory<MappingF1, JacobianMappingF1Trans, MappingF2, JacobianMappingF2Trans, Cost, CostGradient, SetC>
where Cost: Freeze, CostGradient: Freeze, JacobianMappingF1Trans: Freeze, JacobianMappingF2Trans: Freeze, MappingF1: Freeze, MappingF2: Freeze, SetC: Freeze,

§

impl<MappingF1, JacobianMappingF1Trans, MappingF2, JacobianMappingF2Trans, Cost, CostGradient, SetC> RefUnwindSafe for AlmFactory<MappingF1, JacobianMappingF1Trans, MappingF2, JacobianMappingF2Trans, Cost, CostGradient, SetC>
where Cost: RefUnwindSafe, CostGradient: RefUnwindSafe, JacobianMappingF1Trans: RefUnwindSafe, JacobianMappingF2Trans: RefUnwindSafe, MappingF1: RefUnwindSafe, MappingF2: RefUnwindSafe, SetC: RefUnwindSafe,

§

impl<MappingF1, JacobianMappingF1Trans, MappingF2, JacobianMappingF2Trans, Cost, CostGradient, SetC> Send for AlmFactory<MappingF1, JacobianMappingF1Trans, MappingF2, JacobianMappingF2Trans, Cost, CostGradient, SetC>
where Cost: Send, CostGradient: Send, JacobianMappingF1Trans: Send, JacobianMappingF2Trans: Send, MappingF1: Send, MappingF2: Send, SetC: Send,

§

impl<MappingF1, JacobianMappingF1Trans, MappingF2, JacobianMappingF2Trans, Cost, CostGradient, SetC> Sync for AlmFactory<MappingF1, JacobianMappingF1Trans, MappingF2, JacobianMappingF2Trans, Cost, CostGradient, SetC>
where Cost: Sync, CostGradient: Sync, JacobianMappingF1Trans: Sync, JacobianMappingF2Trans: Sync, MappingF1: Sync, MappingF2: Sync, SetC: Sync,

§

impl<MappingF1, JacobianMappingF1Trans, MappingF2, JacobianMappingF2Trans, Cost, CostGradient, SetC> Unpin for AlmFactory<MappingF1, JacobianMappingF1Trans, MappingF2, JacobianMappingF2Trans, Cost, CostGradient, SetC>
where Cost: Unpin, CostGradient: Unpin, JacobianMappingF1Trans: Unpin, JacobianMappingF2Trans: Unpin, MappingF1: Unpin, MappingF2: Unpin, SetC: Unpin,

§

impl<MappingF1, JacobianMappingF1Trans, MappingF2, JacobianMappingF2Trans, Cost, CostGradient, SetC> UnwindSafe for AlmFactory<MappingF1, JacobianMappingF1Trans, MappingF2, JacobianMappingF2Trans, Cost, CostGradient, SetC>
where Cost: UnwindSafe, CostGradient: UnwindSafe, JacobianMappingF1Trans: UnwindSafe, JacobianMappingF2Trans: UnwindSafe, MappingF1: UnwindSafe, MappingF2: UnwindSafe, SetC: UnwindSafe,

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, U> TryFrom<U> for T
where U: Into<T>,

§

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

§

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