Skip to main content

Quadratic

Struct Quadratic 

Source
#[non_exhaustive]
pub struct Quadratic { pub rows: Vec<u64>, pub columns: Vec<u64>, pub values: Vec<f64>, pub linear: Option<Linear>, }
Expand description

Quadratic function as a COO-style sparse matrix and linear sparse vector.

COOrdinate format, also known as triplet format, is a way to represent sparse matrices as a list of non-zero elements. It consists of three lists: the row indices, the column indices, and the values of the non-zero elements with following constraints:

  • Entries and coordinates sorted by row, then column.
  • There are no duplicate entries (i.e. duplicate (i,j) locations)
  • Data arrays MAY have explicit zeros.

Note that this matrix is not assured to be symmetric nor upper triangular. For example, a quadratic function x1^2 + x2^2 + 2x1*x2 can be represented as:

  • { rows: \[0, 0, 1\], columns: \[0, 1, 1\], values: \[1, 2, 1\] }, i.e. an upper triangular matrix \[[1, 2\], \[0, 1\]
  • { rows: \[0, 0, 1, 1\], columns: \[0, 1, 0, 1\], values: \[1, 1, 1, 1\] }, i.e. a symmetric matrix \[[1, 1\], \[1, 1]\]

or even a non-symmetric, non-trianglar matrix as x1^2 + 3x1*x2 - x2*x1 + x2^2:

  • { rows: \[0, 0, 1, 1\], columns: \[0, 1, 0, 1\], values: \[1, 3, -1, 1\] }, i.e. a non-symmetric matrix \[[1, 3\], \[-1, 1]\]

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§rows: Vec<u64>§columns: Vec<u64>§values: Vec<f64>§linear: Option<Linear>

Implementations§

Source§

impl Quadratic

Source

pub fn quad_iter(&self) -> impl Iterator<Item = ((u64, u64), f64)> + '_

Source

pub fn as_linear(self) -> Option<Linear>

Downcast to a linear function if the quadratic function is linear.

Source

pub fn as_constant(self) -> Option<f64>

Downcast to a constant if the quadratic function is constant.

Source

pub fn degree(&self) -> u32

Source

pub fn get_constant(&self) -> f64

Trait Implementations§

Source§

impl AbsDiffEq for Quadratic

Compare coefficients in sup-norm.

Source§

type Epsilon = ATol

Used for specifying relative comparisons.
Source§

fn default_epsilon() -> Self::Epsilon

The default tolerance to use when testing values that are close together. Read more
Source§

fn abs_diff_eq(&self, other: &Self, epsilon: Self::Epsilon) -> bool

A test for equality that uses the absolute difference to compute the approximate equality of two numbers.
Source§

fn abs_diff_ne(&self, other: &Rhs, epsilon: Self::Epsilon) -> bool

The inverse of AbsDiffEq::abs_diff_eq.
Source§

impl Add<&DecisionVariable> for Quadratic

Source§

type Output = <Linear as Add<Quadratic>>::Output

The resulting type after applying the + operator.
Source§

fn add(self, rhs: &DecisionVariable) -> Self::Output

Performs the + operation. Read more
Source§

impl Add<&Parameter> for Quadratic

Source§

type Output = <Linear as Add<Quadratic>>::Output

The resulting type after applying the + operator.
Source§

fn add(self, rhs: &Parameter) -> Self::Output

Performs the + operation. Read more
Source§

impl Add<Function> for Quadratic

Source§

type Output = <Function as Add<Quadratic>>::Output

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Function) -> Self::Output

Performs the + operation. Read more
Source§

impl Add<Linear> for Quadratic

Source§

type Output = Quadratic

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Linear) -> Self

Performs the + operation. Read more
Source§

impl Add<Polynomial> for Quadratic

Source§

type Output = <Polynomial as Add<Quadratic>>::Output

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Polynomial) -> Self::Output

Performs the + operation. Read more
Source§

impl Add<Quadratic> for &DecisionVariable

Source§

type Output = <Linear as Add<Quadratic>>::Output

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Quadratic) -> Self::Output

Performs the + operation. Read more
Source§

impl Add<Quadratic> for &Parameter

Source§

type Output = <Linear as Add<Quadratic>>::Output

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Quadratic) -> Self::Output

Performs the + operation. Read more
Source§

impl Add<Quadratic> for Function

Source§

type Output = Function

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Quadratic) -> Self::Output

Performs the + operation. Read more
Source§

impl Add<Quadratic> for Linear

Source§

type Output = <Quadratic as Add<Linear>>::Output

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Quadratic) -> Self::Output

Performs the + operation. Read more
Source§

impl Add<Quadratic> for Polynomial

Source§

type Output = Polynomial

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Quadratic) -> Self::Output

Performs the + operation. Read more
Source§

impl Add<Quadratic> for f64

Source§

type Output = <Quadratic as Add<f64>>::Output

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Quadratic) -> Self::Output

Performs the + operation. Read more
Source§

impl Add<f64> for Quadratic

Source§

type Output = Quadratic

The resulting type after applying the + operator.
Source§

fn add(self, rhs: f64) -> Self

Performs the + operation. Read more
Source§

impl Add for Quadratic

Source§

type Output = Quadratic

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Self) -> Self

Performs the + operation. Read more
Source§

impl Arbitrary for Quadratic

Source§

type Parameters = FunctionParameters

The type of parameters that arbitrary_with accepts for configuration of the generated Strategy. Parameters must implement Default.
Source§

type Strategy = BoxedStrategy<Quadratic>

The type of Strategy used to generate values of type Self.
Source§

fn arbitrary_with(p: Self::Parameters) -> Self::Strategy

Generates a Strategy for producing arbitrary values of type the implementing type (Self). The strategy is passed the arguments given in args. Read more
Source§

fn arbitrary() -> Self::Strategy

Generates a Strategy for producing arbitrary values of type the implementing type (Self). Read more
Source§

impl Clone for Quadratic

Source§

fn clone(&self) -> Quadratic

Returns a duplicate 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 Debug for Quadratic

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Quadratic

Source§

fn default() -> Self

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

impl Display for Quadratic

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Evaluate for Quadratic

Source§

type Output = f64

Source§

type SampledOutput = SampledValues

Source§

fn evaluate(&self, solution: &State, atol: ATol) -> Result<f64>

Evaluate to return the output with used variable ids
Source§

fn partial_evaluate(&mut self, state: &State, _atol: ATol) -> Result<()>

Partially evaluate the function to return the used variable ids
Source§

fn evaluate_samples( &self, samples: &Samples, atol: ATol, ) -> Result<Self::SampledOutput>

Evaluate for each sample
Source§

fn required_ids(&self) -> VariableIDSet

Decision variable IDs required for evaluation
Source§

impl From<&DecisionVariable> for Quadratic

Source§

fn from(dv: &DecisionVariable) -> Self

Converts to this type from the input type.
Source§

impl From<&Parameter> for Quadratic

Source§

fn from(dv: &Parameter) -> Self

Converts to this type from the input type.
Source§

impl From<Linear> for Quadratic

Source§

fn from(l: Linear) -> Self

Converts to this type from the input type.
Source§

impl From<PolynomialBase<QuadraticMonomial>> for Quadratic

Source§

fn from(value: Quadratic) -> Self

Converts to this type from the input type.
Source§

impl From<Quadratic> for Function

Source§

fn from(q: Quadratic) -> Self

Converts to this type from the input type.
Source§

impl From<Quadratic> for Polynomial

Source§

fn from(q: Quadratic) -> Self

Converts to this type from the input type.
Source§

impl From<f64> for Quadratic

Source§

fn from(c: f64) -> Self

Converts to this type from the input type.
Source§

impl FromIterator<((u64, u64), f64)> for Quadratic

Source§

fn from_iter<I: IntoIterator<Item = ((u64, u64), f64)>>(iter: I) -> Self

Creates a value from an iterator. Read more
Source§

impl<'a> IntoIterator for &'a Quadratic

Source§

type Item = (MonomialDyn, f64)

The type of the elements being iterated over.
Source§

type IntoIter = Box<dyn Iterator<Item = <&'a Quadratic as IntoIterator>::Item> + 'a>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl Message for Quadratic

Source§

fn encoded_len(&self) -> usize

Returns the encoded length of the message without a length delimiter.
Source§

fn clear(&mut self)

Clears the message, resetting all fields to their default.
Source§

fn encode<B>(&self, buf: &mut B) -> Result<(), EncodeError>
where B: BufMut, Self: Sized,

Encodes the message to a buffer. Read more
Source§

fn encode_to_vec(&self) -> Vec<u8>
where Self: Sized,

Encodes the message to a newly allocated buffer.
Source§

fn encode_length_delimited<B>(&self, buf: &mut B) -> Result<(), EncodeError>
where B: BufMut, Self: Sized,

Encodes the message with a length-delimiter to a buffer. Read more
Source§

fn encode_length_delimited_to_vec(&self) -> Vec<u8>
where Self: Sized,

Encodes the message with a length-delimiter to a newly allocated buffer.
Source§

fn decode<B>(buf: B) -> Result<Self, DecodeError>
where B: Buf, Self: Default,

Decodes an instance of the message from a buffer. Read more
Source§

fn decode_length_delimited<B>(buf: B) -> Result<Self, DecodeError>
where B: Buf, Self: Default,

Decodes a length-delimited instance of the message from the buffer.
Source§

fn merge<B>(&mut self, buf: B) -> Result<(), DecodeError>
where B: Buf, Self: Sized,

Decodes an instance of the message from a buffer, and merges it into self. Read more
Source§

fn merge_length_delimited<B>(&mut self, buf: B) -> Result<(), DecodeError>
where B: Buf, Self: Sized,

Decodes a length-delimited instance of the message from buffer, and merges it into self.
Source§

impl Mul<&DecisionVariable> for Quadratic

Source§

type Output = <Linear as Mul<Quadratic>>::Output

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: &DecisionVariable) -> Self::Output

Performs the * operation. Read more
Source§

impl Mul<&Parameter> for Quadratic

Source§

type Output = <Linear as Mul<Quadratic>>::Output

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: &Parameter) -> Self::Output

Performs the * operation. Read more
Source§

impl Mul<Function> for Quadratic

Source§

type Output = <Function as Mul<Quadratic>>::Output

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Function) -> Self::Output

Performs the * operation. Read more
Source§

impl Mul<Linear> for Quadratic

Source§

type Output = Polynomial

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Linear) -> Self::Output

Performs the * operation. Read more
Source§

impl Mul<Polynomial> for Quadratic

Source§

type Output = <Polynomial as Mul<Quadratic>>::Output

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Polynomial) -> Self::Output

Performs the * operation. Read more
Source§

impl Mul<Quadratic> for &DecisionVariable

Source§

type Output = <Linear as Mul<Quadratic>>::Output

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Quadratic) -> Self::Output

Performs the * operation. Read more
Source§

impl Mul<Quadratic> for &Parameter

Source§

type Output = <Linear as Mul<Quadratic>>::Output

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Quadratic) -> Self::Output

Performs the * operation. Read more
Source§

impl Mul<Quadratic> for Function

Source§

type Output = Function

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Quadratic) -> Self::Output

Performs the * operation. Read more
Source§

impl Mul<Quadratic> for Linear

Source§

type Output = <Quadratic as Mul<Linear>>::Output

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Quadratic) -> Self::Output

Performs the * operation. Read more
Source§

impl Mul<Quadratic> for Polynomial

Source§

type Output = Polynomial

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Quadratic) -> Self::Output

Performs the * operation. Read more
Source§

impl Mul<Quadratic> for f64

Source§

type Output = <Quadratic as Mul<f64>>::Output

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Quadratic) -> Self::Output

Performs the * operation. Read more
Source§

impl Mul<f64> for Quadratic

Source§

type Output = Quadratic

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: f64) -> Self

Performs the * operation. Read more
Source§

impl Mul for Quadratic

Source§

type Output = Polynomial

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: Self) -> Self::Output

Performs the * operation. Read more
Source§

impl Neg for &Quadratic

Source§

type Output = Quadratic

The resulting type after applying the - operator.
Source§

fn neg(self) -> Self::Output

Performs the unary - operation. Read more
Source§

impl Neg for Quadratic

Source§

type Output = Quadratic

The resulting type after applying the - operator.
Source§

fn neg(self) -> Self::Output

Performs the unary - operation. Read more
Source§

impl Parse for Quadratic

Source§

type Output = PolynomialBase<QuadraticMonomial>

Source§

type Context = ()

Source§

fn parse(self, _: &Self::Context) -> Result<Self::Output, ParseError>

Source§

fn parse_as( self, context: &Self::Context, message: &'static str, field: &'static str, ) -> Result<Self::Output, ParseError>

Source§

impl PartialEq for Quadratic

Source§

fn eq(&self, other: &Quadratic) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Sub<Linear> for Quadratic

Source§

type Output = Quadratic

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Linear) -> Self::Output

Performs the - operation. Read more
Source§

impl Sub<Quadratic> for Function

Source§

type Output = Function

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Quadratic) -> Self::Output

Performs the - operation. Read more
Source§

impl Sub<f64> for Quadratic

Source§

type Output = Quadratic

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: f64) -> Self::Output

Performs the - operation. Read more
Source§

impl Sub for Quadratic

Source§

type Output = Quadratic

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Quadratic) -> Self::Output

Performs the - operation. Read more
Source§

impl TryFrom<Quadratic> for Quadratic

Source§

type Error = ParseError

The type returned in the event of a conversion error.
Source§

fn try_from(value: Quadratic) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl Zero for Quadratic

Source§

fn zero() -> Self

Returns the additive identity element of Self, 0. Read more
Source§

fn is_zero(&self) -> bool

Returns true if self is equal to the additive identity.
Source§

fn set_zero(&mut self)

Sets self to the additive identity element of Self, 0.
Source§

impl StructuralPartialEq for Quadratic

Auto Trait Implementations§

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

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

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

Source§

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