Enum dypdl::CostExpression

source ·
pub enum CostExpression {
    Integer(IntegerExpression),
    Continuous(ContinuousExpression),
}
Expand description

Wrapper for an integer expression or a continuous expression.

Variants§

§

Integer(IntegerExpression)

Integer numeric expression.

§

Continuous(ContinuousExpression)

Continuous numeric expression.

Implementations§

source§

impl CostExpression

source

pub fn eval<T: Numeric, U: StateInterface>( &self, state: &U, registry: &TableRegistry, ) -> T

Returns the evaluation result.

§Panics

Panics if the cost of the transition state is used or a min/max reduce operation is performed on an empty set or vector.

§Examples
use dypdl::prelude::*;

let mut model = Model::default();
let variable = model.add_integer_variable("x", 2).unwrap();
let state = model.target.clone();

let expression = CostExpression::from(IntegerExpression::from(variable));
assert_eq!(expression.eval::<Integer, _>(&state, &model.table_registry), 2);
source

pub fn eval_cost<T: Numeric, U: StateInterface>( &self, cost: T, state: &U, registry: &TableRegistry, ) -> T

Returns the evaluation result.

§Panics

Panics if a min/max reduce operation is performed on an empty set or vector.

§Examples
use dypdl::prelude::*;

let mut model = Model::default();
let variable = model.add_integer_variable("x", 2).unwrap();
let state = model.target.clone();

let expression = CostExpression::from(variable + IntegerExpression::Cost);
assert_eq!(expression.eval_cost(1, &state, &model.table_registry), 3);
source

pub fn simplify(&self, registry: &TableRegistry) -> CostExpression

Returns a simplified version by precomputation.

§Panics

Panics if a min/max reduce operation is performed on an empty set or vector.

Trait Implementations§

source§

impl Clone for CostExpression

source§

fn clone(&self) -> CostExpression

Returns a copy 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 CostExpression

source§

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

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

impl Default for CostExpression

source§

fn default() -> Self

Returns CostExpression::Integer(IntegerExpression::Cost).

source§

impl From<ContinuousExpression> for CostExpression

source§

fn from(cost: ContinuousExpression) -> Self

Converts to this type from the input type.
source§

impl From<ContinuousResourceVariable> for CostExpression

source§

fn from(cost: ContinuousResourceVariable) -> Self

Converts to this type from the input type.
source§

impl From<ContinuousVariable> for CostExpression

source§

fn from(cost: ContinuousVariable) -> Self

Converts to this type from the input type.
source§

impl<T> From<T> for CostExpression

source§

fn from(cost: T) -> Self

Converts to this type from the input type.
source§

impl From<f64> for CostExpression

source§

fn from(cost: Continuous) -> Self

Converts to this type from the input type.
source§

impl PartialEq for CostExpression

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl StructuralPartialEq for CostExpression

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

§

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, U> TryFrom<U> for T
where U: Into<T>,

§

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

§

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.