Struct optimization_engine::alm::AlmFactory
source · 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
andMappingF2
: 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
andJacobianMappingF2Trans
: 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,
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,
sourcepub 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
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 functionmapping_f1
(optional) mapping $F_1$ orNO_MAPPING
jacobian_mapping_f1_trans
(optional) $JF_1(u)^\intercal d$ orNO_JACOBIAN_MAPPING
mapping_f2
(optional) mapping $F_2$ orNO_MAPPING
jacobian_mapping_f2_trans
$JF_2(u)^\intercal d$ orNO_JACOBIAN_MAPPING
set_c
(optional) set $C$ orNO_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,
);
sourcepub fn psi(&self, u: &[f64], xi: &[f64], cost: &mut f64) -> FunctionCallResult
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.
sourcepub fn d_psi(
&self,
u: &[f64],
xi: &[f64],
grad: &mut [f64]
) -> FunctionCallResult
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.