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

Cartesian product of constraints

Cartesian product of constraints, $C_0, C_1, \ldots, C_{n-1}$, which is defined as a set

$$ C = C_0 \times C_1 \times \ldots \times C_{n-1}, $$

for some integer $n>1$. Sets $C_i$ are structures which implement the trait Constraint.

In an $n$-dimensional space, a vector $x$ is split in parts

$$x = (x_0, x_1, …, x_{n-1}),$$

where $x_i$ has dimension $n_i$.

The constraint $x \in C$ is interpreted as $x_i \in C_i$ for all $i=0,\ldots, n-1$.

Implementations§

source§

impl<'a> CartesianProduct<'a>

source

pub fn new() -> Self

Construct new instance of Cartesian product of constraints

§Note

The use of new_with_capacity should be preferred over this method, when possible (provided you have an estimate of the number of sets your Cartesian product will consist of).

source

pub fn new_with_capacity(num_sets: usize) -> Self

Constructs a new instance of Cartesian product with a given capacity

§Arguments
  • num_sets: number of sets; this is used to allocate initial memory (via Vec::with_capacity).
§Returns

New instance of CartesianProduct

source

pub fn dimension(&self) -> usize

Dimension of the current constraints

source

pub fn add_constraint(self, ni: usize, constraint: impl Constraint + 'a) -> Self

Add constraint x(i) in C(i)

Vector x is segmented into subvectors x = (x(0), x(1), ..., x(n-1), where x(0) has length n0.

§Arguments
  • ni: total length of vector (x(0), ..., x(i)) (see example below)
  • constraint: constraint to be added implementation of trait Constraint
§Returns

Returns the current mutable and updated instance of the provided object

§Example
use optimization_engine::constraints::*;

/*
 * Cartesian product of two balls of dimensions 3 and 2,
 * that is, x = (x0, x1), with x0 being 3-dimensional and
 * x1 being 2-dimensional, that is, x0 = (x[0], x[1], x[2])
 * and x2 = (x[3], x[4]).
 */
let idx1 = 3;
let idx2 = 5;
let ball1 = Ball2::new(None, 1.0);
let ball2 = Ball2::new(None, 0.5);
let mut cart_prod = CartesianProduct::new()
    .add_constraint(idx1, ball1)
    .add_constraint(idx2, ball2);
§Panics

The method panics if ni is less than or equal to the previous dimension of the cartesian product. For example, the following code will fail:

let mut cart_prod = CartesianProduct::new()
    .add_constraint(7, &rectangle);     // OK, since 7  > 0
    .add_constraint(10, &ball1);        // OK, since 10 > 7
    .add_constraint(2, &ball3);         // 2 <= 10, so it will fail

The method will panic if any of the associated projections panics.

Trait Implementations§

source§

impl<'a> Constraint for CartesianProduct<'a>

source§

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

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())

source§

fn is_convex(&self) -> bool

Returns true if and only if the set is convex
source§

impl<'a> Default for CartesianProduct<'a>

source§

fn default() -> CartesianProduct<'a>

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for CartesianProduct<'a>

§

impl<'a> !RefUnwindSafe for CartesianProduct<'a>

§

impl<'a> !Send for CartesianProduct<'a>

§

impl<'a> !Sync for CartesianProduct<'a>

§

impl<'a> Unpin for CartesianProduct<'a>

§

impl<'a> !UnwindSafe for CartesianProduct<'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, 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