Struct good_lp::Expression [−][src]
Represents an affine expression, such as 2x + 3
or x + y + z
Implementations
impl Expression
[src]
pub fn with_capacity(capacity: usize) -> Self
[src]
Create an expression that has the value 0, but has memory allocated
for capacity
coefficients.
pub fn from_other_affine<E: IntoAffineExpression>(source: E) -> Self
[src]
Create a concrete expression struct from anything that has linear coefficients and a constant
Expression::from_other_affine(0.); // A constant expression
pub fn leq<RHS>(self, rhs: RHS) -> Constraint where
Expression: Sub<RHS, Output = Expression>,
[src]
Expression: Sub<RHS, Output = Expression>,
Creates a constraint indicating that this expression is lesser than or equal to the right hand side
pub fn geq<RHS: Sub<Expression, Output = Expression>>(
self,
rhs: RHS
) -> Constraint
[src]
self,
rhs: RHS
) -> Constraint
Creates a constraint indicating that this expression is greater than or equal to the right hand side
pub fn eq<RHS>(self, rhs: RHS) -> Constraint where
Expression: Sub<RHS, Output = Expression>,
[src]
Expression: Sub<RHS, Output = Expression>,
Creates a constraint indicating that this expression is equal to the right hand side
pub fn add_mul<N: Into<f64>, E: IntoAffineExpression>(&mut self, a: N, b: E)
[src]
Performs self = self + (a * b)
pub fn eval_with<S: Solution>(&self, values: &S) -> f64
[src]
Evaluate the concrete value of the expression, given the values of the variables
Examples
Evaluate an expression using a solution
use good_lp::{variables, variable, coin_cbc, SolverModel, Solution}; let mut vars = variables!(); let a = vars.add(variable().max(1)); let b = vars.add(variable().max(4)); let objective = a + b; let solution = vars.maximise(objective.clone()).using(coin_cbc).solve()?; assert_eq!(objective.eval_with(&solution), 5.);
Evaluate an expression with a HashMap
use std::collections::HashMap; use good_lp::{variables, Variable}; let mut vars = variables!(); let a = vars.add_variable(); let b = vars.add_variable(); let expr = a + b / 2; let var_mapping: HashMap<_, _> = vec![(a, 3), (b, 10)].into_iter().collect(); let value = expr.eval_with(&var_mapping); assert_eq!(value, 8.);
Trait Implementations
impl<RHS: IntoAffineExpression> Add<RHS> for Expression
[src]
type Output = Expression
The resulting type after applying the +
operator.
fn add(self, rhs: RHS) -> Self::Output
[src]
impl<RHS: IntoAffineExpression> AddAssign<RHS> for Expression
[src]
fn add_assign(&mut self, rhs: RHS)
[src]
impl Clone for Expression
[src]
fn clone(&self) -> Self
[src]
pub fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl Debug for Expression
[src]
impl Default for Expression
[src]
impl<N: Into<f64>> Div<N> for Expression
[src]
type Output = Expression
The resulting type after applying the /
operator.
fn div(self, rhs: N) -> Self::Output
[src]
impl FormatWithVars for Expression
[src]
fn format_with<FUN>(
&self,
f: &mut Formatter<'_>,
variable_format: FUN
) -> Result where
FUN: Fn(&mut Formatter<'_>, Variable) -> Result,
[src]
&self,
f: &mut Formatter<'_>,
variable_format: FUN
) -> Result where
FUN: Fn(&mut Formatter<'_>, Variable) -> Result,
fn format_debug(&self, f: &mut Formatter<'_>) -> Result
[src]
impl From<Variable> for Expression
[src]
fn from(x: Variable) -> Expression
[src]
impl From<f64> for Expression
[src]
fn from(x: f64) -> Expression
[src]
impl From<i32> for Expression
[src]
fn from(x: i32) -> Expression
[src]
impl IntoAffineExpression for Expression
[src]
type Iter = <LinearExpression as IntoAffineExpression>::Iter
The iterator returned by linear_coefficients
.
fn linear_coefficients(self) -> Self::Iter
[src]
fn constant(&self) -> f64
[src]
impl<'a> IntoAffineExpression for &'a Expression
[src]
This implementation copies all the variables and coefficients from the referenced Expression into the created iterator
type Iter = <&'a LinearExpression as IntoAffineExpression>::Iter
The iterator returned by linear_coefficients
.
fn linear_coefficients(self) -> Self::Iter
[src]
fn constant(&self) -> f64
[src]
impl<N: Into<f64>> Mul<N> for Expression
[src]
type Output = Expression
The resulting type after applying the *
operator.
fn mul(self, rhs: N) -> Self::Output
[src]
impl<N: Into<f64>> MulAssign<N> for Expression
[src]
fn mul_assign(&mut self, rhs: N)
[src]
impl Neg for Expression
[src]
type Output = Self
The resulting type after applying the -
operator.
fn neg(self) -> Self::Output
[src]
impl PartialEq<Expression> for Expression
[src]
impl<RHS> Shl<RHS> for Expression where
Self: Sub<RHS, Output = Expression>,
[src]
Self: Sub<RHS, Output = Expression>,
type Output = Constraint
The resulting type after applying the <<
operator.
fn shl(self, rhs: RHS) -> Self::Output
[src]
impl<RHS: Sub<Self, Output = Expression>> Shr<RHS> for Expression
[src]
type Output = Constraint
The resulting type after applying the >>
operator.
fn shr(self, rhs: RHS) -> Self::Output
[src]
impl<RHS: IntoAffineExpression> Sub<RHS> for Expression
[src]
type Output = Expression
The resulting type after applying the -
operator.
fn sub(self, rhs: RHS) -> Self::Output
[src]
impl<RHS: IntoAffineExpression> SubAssign<RHS> for Expression
[src]
fn sub_assign(&mut self, rhs: RHS)
[src]
impl<E: IntoAffineExpression> Sum<E> for Expression
[src]
Auto Trait Implementations
impl RefUnwindSafe for Expression
impl Send for Expression
impl Sync for Expression
impl Unpin for Expression
impl UnwindSafe for Expression
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,