Struct good_lp::Expression[][src]

pub struct Expression<F> { /* fields omitted */ }

Represents an affine expression, such as 2x + 3 or x + y + z

Implementations

impl<F> Expression<F>[src]

pub fn leq<RHS>(self, rhs: RHS) -> Constraint<F> where
    Expression<F>: Sub<RHS, Output = Expression<F>>, 
[src]

Creates a constraint indicating that this expression is lesser than or equal to the right hand side

pub fn geq<RHS: Sub<Expression<F>, Output = Expression<F>>>(
    self,
    rhs: RHS
) -> Constraint<F>
[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<F> where
    Expression<F>: Sub<RHS, Output = Expression<F>>, 
[src]

Creates a constraint indicating that this expression is greater than or equal to the right hand side

pub fn add_mul<N: Into<f64>>(&mut self, a: N, b: &Expression<F>)[src]

Performs self = self + (a * b)

pub fn eval_with<S: Solution<F>>(&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<'a, F> Add<&'a Expression<F>> for Expression<F>[src]

type Output = Expression<F>

The resulting type after applying the + operator.

impl<F, RHS: Into<Expression<F>>> Add<RHS> for Expression<F>[src]

type Output = Expression<F>

The resulting type after applying the + operator.

impl<'a, F> AddAssign<&'a Expression<F>> for Expression<F>[src]

impl<F, RHS: Into<Expression<F>>> AddAssign<RHS> for Expression<F>[src]

impl<F> Clone for Expression<F>[src]

impl<T> Debug for Expression<T>[src]

impl<F> Default for Expression<F>[src]

impl<F, N: Into<f64>> Div<N> for Expression<F>[src]

type Output = Expression<F>

The resulting type after applying the / operator.

impl<F> FormatWithVars<F> for Expression<F>[src]

impl<'a, F> From<&'a Variable<F>> for Expression<F>[src]

impl<F, N: Into<f64>> From<N> for Expression<F>[src]

impl<F> From<Variable<F>> for Expression<F>[src]

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

type Output = Expression<F>

The resulting type after applying the * operator.

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

impl<T> Neg for Expression<T>[src]

type Output = Self

The resulting type after applying the - operator.

impl<F> PartialEq<Expression<F>> for Expression<F>[src]

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

type Output = Constraint<F>

The resulting type after applying the << operator.

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

type Output = Constraint<F>

The resulting type after applying the >> operator.

impl<'a, F> Sub<&'a Expression<F>> for Expression<F>[src]

type Output = Expression<F>

The resulting type after applying the - operator.

impl<F, RHS: Into<Expression<F>>> Sub<RHS> for Expression<F>[src]

type Output = Expression<F>

The resulting type after applying the - operator.

impl<'a, F> SubAssign<&'a Expression<F>> for Expression<F>[src]

impl<F, RHS: Into<Expression<F>>> SubAssign<RHS> for Expression<F>[src]

impl<'a, F, A> Sum<A> for Expression<F> where
    Expression<F>: From<A>, 
[src]

Auto Trait Implementations

impl<F> RefUnwindSafe for Expression<F> where
    F: RefUnwindSafe
[src]

impl<F> Send for Expression<F> where
    F: Send
[src]

impl<F> Sync for Expression<F> where
    F: Sync
[src]

impl<F> Unpin for Expression<F> where
    F: Unpin
[src]

impl<F> UnwindSafe for Expression<F> where
    F: UnwindSafe
[src]

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.