Struct good_lp::Expression[][src]

pub struct Expression { /* fields omitted */ }

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]

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]

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]

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

A HashMap is a valid Solution

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.

impl<RHS: IntoAffineExpression> AddAssign<RHS> for Expression[src]

impl Clone for Expression[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.

impl FormatWithVars for Expression[src]

impl From<Variable> for Expression[src]

impl From<f64> for Expression[src]

impl From<i32> for Expression[src]

impl IntoAffineExpression for Expression[src]

type Iter = <LinearExpression as IntoAffineExpression>::Iter

The iterator returned by linear_coefficients.

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.

impl<N: Into<f64>> Mul<N> for Expression[src]

type Output = Expression

The resulting type after applying the * operator.

impl<N: Into<f64>> MulAssign<N> for Expression[src]

impl Neg for Expression[src]

type Output = Self

The resulting type after applying the - operator.

impl PartialEq<Expression> for Expression[src]

impl<RHS> Shl<RHS> for Expression where
    Self: Sub<RHS, Output = Expression>, 
[src]

type Output = Constraint

The resulting type after applying the << operator.

impl<RHS: Sub<Self, Output = Expression>> Shr<RHS> for Expression[src]

type Output = Constraint

The resulting type after applying the >> operator.

impl<RHS: IntoAffineExpression> Sub<RHS> for Expression[src]

type Output = Expression

The resulting type after applying the - operator.

impl<RHS: IntoAffineExpression> SubAssign<RHS> for Expression[src]

impl<E: IntoAffineExpression> Sum<E> for Expression[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.