[][src]Trait optimization_engine::constraints::Constraint

pub trait Constraint {
    fn project(&self, x: &mut [f64]);
fn is_convex(&self) -> bool; }

A set which can be used as a constraint

This trait defines an abstract function that allows to compute projections on sets; this is implemented by a series of structures (see below for details)

Required methods

fn project(&self, x: &mut [f64])

Projection onto the set, that is,

$$ \Pi_C(v) = \mathrm{argmin}_{z\in C}\Vert{}z-v{}\Vert $$

Arguments

  • x: The given vector $x$ is updated with the projection on the set

fn is_convex(&self) -> bool

Returns true if and only if the set is convex

Loading content...

Implementors

impl Constraint for NoConstraints[src]

impl Constraint for SecondOrderCone[src]

fn project(&self, x: &mut [f64])[src]

Project on the second-order cone (updates the given vector/slice)

Arguments

  • x: (in) vector to be projected on the current instance of a second-order cone, (out) projection on the second-order cone

Panics

The methods panics is the length of x is less than 2.

impl Constraint for Zero[src]

fn project(&self, x: &mut [f64])[src]

Computes the projection on $\{0\}$, that is, $\Pi_{\{0\}}(x) = 0$ for all $x$

impl<'a> Constraint for Ball2<'a>[src]

impl<'a> Constraint for BallInf<'a>[src]

fn project(&self, x: &mut [f64])[src]

Computes the projection of a given vector x on the current infinity ball.

The projection of a $v\in\mathbb{R}^{n}$ on $B_\infty^r$ is given by $\Pi_{B_\infty^r}(v) = z$ with

$$ z_i = \begin{cases}v_i,&\text{ if } |z_i| \leq r\\\mathrm{sng}(v_i)r,&\text{ otherwise}\end{cases} $$

for all $i=1,\ldots, n$, where sgn is the sign function.

The projection of $v\in\mathbb{R}^{n}$ on $B_\infty^{x_c,r}$ is given by $\Pi_{B_\infty^r}(v) = z$ with

$$ z_i = \begin{cases}v_i,&\text{ if } |z_i-x_{c, i}| \leq r\\x_{c,i} + \mathrm{sng}(v_i)r,&\text{ otherwise}\end{cases} $$

for all $i=1,\ldots, n$.

impl<'a> Constraint for CartesianProduct<'a>[src]

fn project(&self, x: &mut [f64])[src]

Project onto Cartesian product of constraints

The given vector x is updated with the projection on the set

Panics

The method will panic if the dimension of x is not equal to the dimension of the Cartesian product (see dimension())

impl<'a> Constraint for FiniteSet<'a>[src]

fn project(&self, x: &mut [f64])[src]

Projection on the current finite set

Traverses the elements of the vector, computes norm-2 distances to each element, and updates the given vector x with the closest element from the finite set.

Parameters

  • x: (input) given vector, (output) projection on finite set

Example

use optimization_engine::constraints::*;

let data: &[&[f64]] = &[
   &[0.0, 0.0],
   &[1.0, 1.0],
];
let finite_set = FiniteSet::new(data);
let mut x = [0.7, 0.6];
finite_set.project(&mut x); // compute projection

Panics

Does not panic

impl<'a> Constraint for Rectangle<'a>[src]

Loading content...