pub struct Halfspace<'a> { /* private fields */ }
Expand description

A halfspace is a set given by $H = \{x \in \mathbb{R}^n {}:{} \langle c, x\rangle \leq b\}$.

Implementations§

source§

impl<'a> Halfspace<'a>

source

pub fn new(normal_vector: &'a [f64], offset: f64) -> Self

A halfspace is a set given by $H = \{x \in \mathbb{R}^n {}:{} \langle c, x\rangle \leq b\}$, where $c$ is the normal vector of the halfspace and $b$ is an offset.

This method constructs a new instance of Halfspace with a given normal vector and bias

§Arguments
  • normal_vector: the normal vector, $c$, as a slice
  • offset: the offset parameter, $b$
§Returns

New instance of Halfspace

§Panics

Does not panic. Note: it does not panic if you provide an empty slice as normal_vector, but you should avoid doing that.

§Example
use optimization_engine::constraints::{Constraint, Halfspace};

let normal_vector = [1., 2.];
let offset = 1.0;
let halfspace = Halfspace::new(&normal_vector, offset);
let mut x = [-1., 3.];
halfspace.project(&mut x);

Trait Implementations§

source§

impl<'a> Clone for Halfspace<'a>

source§

fn clone(&self) -> Halfspace<'a>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<'a> Constraint for Halfspace<'a>

source§

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

Projects on halfspace using the following formula:

$$\begin{aligned} \mathrm{proj}_{H}(x) = \begin{cases} x,& \text{ if } \langle c, x\rangle \leq b \\ x - \frac{\langle c, x\rangle - b} {\|c\|}c,& \text{else} \end{cases} \end{aligned}$$

where $H = \{x \in \mathbb{R}^n {}:{} \langle c, x\rangle \leq b\}$

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

This method panics if the length of x is not equal to the dimension of the halfspace.

source§

fn is_convex(&self) -> bool

Halfspaces are convex sets

§Returns

Returns true

Auto Trait Implementations§

§

impl<'a> Freeze for Halfspace<'a>

§

impl<'a> RefUnwindSafe for Halfspace<'a>

§

impl<'a> Send for Halfspace<'a>

§

impl<'a> Sync for Halfspace<'a>

§

impl<'a> Unpin for Halfspace<'a>

§

impl<'a> UnwindSafe for Halfspace<'a>

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> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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