#[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
impl Quadratic
pub fn quad_iter(&self) -> impl Iterator<Item = ((u64, u64), f64)> + '_
Sourcepub fn as_linear(self) -> Option<Linear>
pub fn as_linear(self) -> Option<Linear>
Downcast to a linear function if the quadratic function is linear.
Sourcepub fn as_constant(self) -> Option<f64>
pub fn as_constant(self) -> Option<f64>
Downcast to a constant if the quadratic function is constant.
pub fn degree(&self) -> u32
pub fn get_constant(&self) -> f64
Trait Implementations§
Source§impl AbsDiffEq for Quadratic
Compare coefficients in sup-norm.
impl AbsDiffEq for Quadratic
Compare coefficients in sup-norm.
Source§fn default_epsilon() -> Self::Epsilon
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
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
fn abs_diff_ne(&self, other: &Rhs, epsilon: Self::Epsilon) -> bool
The inverse of
AbsDiffEq::abs_diff_eq.Source§impl Add<&DecisionVariable> for Quadratic
impl Add<&DecisionVariable> for Quadratic
Source§impl Add<Polynomial> for Quadratic
impl Add<Polynomial> for Quadratic
Source§impl Add<Quadratic> for &DecisionVariable
impl Add<Quadratic> for &DecisionVariable
Source§impl Add<Quadratic> for Polynomial
impl Add<Quadratic> for Polynomial
Source§impl Arbitrary for Quadratic
impl Arbitrary for Quadratic
Source§type Parameters = FunctionParameters
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>
type Strategy = BoxedStrategy<Quadratic>
The type of
Strategy used to generate values of type Self.Source§fn arbitrary_with(p: Self::Parameters) -> Self::Strategy
fn arbitrary_with(p: Self::Parameters) -> Self::Strategy
Source§impl Evaluate for Quadratic
impl Evaluate for Quadratic
type Output = f64
type SampledOutput = SampledValues
Source§fn evaluate(&self, solution: &State, atol: ATol) -> Result<f64>
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<()>
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>
fn evaluate_samples( &self, samples: &Samples, atol: ATol, ) -> Result<Self::SampledOutput>
Evaluate for each sample
Source§fn required_ids(&self) -> VariableIDSet
fn required_ids(&self) -> VariableIDSet
Decision variable IDs required for evaluation
Source§impl From<&DecisionVariable> for Quadratic
impl From<&DecisionVariable> for Quadratic
Source§fn from(dv: &DecisionVariable) -> Self
fn from(dv: &DecisionVariable) -> Self
Converts to this type from the input type.
Source§impl From<PolynomialBase<QuadraticMonomial>> for Quadratic
impl From<PolynomialBase<QuadraticMonomial>> for Quadratic
Source§impl From<Quadratic> for Polynomial
impl From<Quadratic> for Polynomial
Source§impl<'a> IntoIterator for &'a Quadratic
impl<'a> IntoIterator for &'a Quadratic
Source§impl Message for Quadratic
impl Message for Quadratic
Source§fn encoded_len(&self) -> usize
fn encoded_len(&self) -> usize
Returns the encoded length of the message without a length delimiter.
Source§fn encode<B>(&self, buf: &mut B) -> Result<(), EncodeError>
fn encode<B>(&self, buf: &mut B) -> Result<(), EncodeError>
Encodes the message to a buffer. Read more
Source§fn encode_to_vec(&self) -> Vec<u8> ⓘwhere
Self: Sized,
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>
fn encode_length_delimited<B>(&self, buf: &mut B) -> Result<(), EncodeError>
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,
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>
fn decode<B>(buf: B) -> Result<Self, DecodeError>
Decodes an instance of the message from a buffer. Read more
Source§fn decode_length_delimited<B>(buf: B) -> Result<Self, DecodeError>
fn decode_length_delimited<B>(buf: B) -> Result<Self, DecodeError>
Decodes a length-delimited instance of the message from the buffer.
Source§fn merge<B>(&mut self, buf: B) -> Result<(), DecodeError>
fn merge<B>(&mut self, buf: B) -> Result<(), DecodeError>
Decodes an instance of the message from a buffer, and merges it into
self. Read moreSource§fn merge_length_delimited<B>(&mut self, buf: B) -> Result<(), DecodeError>
fn merge_length_delimited<B>(&mut self, buf: B) -> Result<(), DecodeError>
Decodes a length-delimited instance of the message from buffer, and
merges it into
self.Source§impl Mul<&DecisionVariable> for Quadratic
impl Mul<&DecisionVariable> for Quadratic
Source§impl Mul<Polynomial> for Quadratic
impl Mul<Polynomial> for Quadratic
Source§impl Mul<Quadratic> for &DecisionVariable
impl Mul<Quadratic> for &DecisionVariable
Source§impl Mul<Quadratic> for Polynomial
impl Mul<Quadratic> for Polynomial
impl StructuralPartialEq for Quadratic
Auto Trait Implementations§
impl Freeze for Quadratic
impl RefUnwindSafe for Quadratic
impl Send for Quadratic
impl Sync for Quadratic
impl Unpin for Quadratic
impl UnsafeUnpin for Quadratic
impl UnwindSafe for Quadratic
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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