pub enum ElementExpression {
    Constant(Element),
    Variable(usize),
    ResourceVariable(usize),
    BinaryOperation(BinaryOperator, Box<ElementExpression>, Box<ElementExpression>),
    Last(Box<VectorExpression>),
    At(Box<VectorExpression>, Box<ElementExpression>),
    Table(Box<TableExpression<Element>>),
    If(Box<Condition>, Box<ElementExpression>, Box<ElementExpression>),
}
Expand description

Element expression .

Variants§

§

Constant(Element)

Constant.

§

Variable(usize)

Variable index.

§

ResourceVariable(usize)

Resource variable index.

§

BinaryOperation(BinaryOperator, Box<ElementExpression>, Box<ElementExpression>)

Binary arithmetic operation.

§

Last(Box<VectorExpression>)

The last value of a vector expression.

§

At(Box<VectorExpression>, Box<ElementExpression>)

An item in a vector expression.

§

Table(Box<TableExpression<Element>>)

A constant in a element table.

§

If(Box<Condition>, Box<ElementExpression>, Box<ElementExpression>)

If-then-else expression, which returns the first one if the condition holds and the second one otherwise.

Implementations§

source§

impl ElementExpression

source

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

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 object_type = model.add_object_type("object_type", 2).unwrap();
let variable = model.add_element_variable("variable", object_type, 1).unwrap();
let state = model.target.clone();

let expression = ElementExpression::from(variable);
assert_eq!(expression.eval(&state, &model.table_registry), 1);
source

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

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 Add<ElementExpression> for ElementResourceVariable

source§

fn add(self, rhs: ElementExpression) -> ElementExpression

Returns an expression representing the addition.

§

type Output = ElementExpression

The resulting type after applying the + operator.
source§

impl Add<ElementExpression> for ElementVariable

source§

fn add(self, rhs: ElementExpression) -> ElementExpression

Returns an expression representing the addition.

§

type Output = ElementExpression

The resulting type after applying the + operator.
source§

impl Add<ElementExpression> for Element

source§

fn add(self, rhs: ElementExpression) -> ElementExpression

Returns an expression representing the addition.

§

type Output = ElementExpression

The resulting type after applying the + operator.
source§

impl Add<ElementResourceVariable> for ElementExpression

source§

fn add(self, rhs: ElementResourceVariable) -> ElementExpression

Returns an expression representing the addition.

§

type Output = ElementExpression

The resulting type after applying the + operator.
source§

impl Add<ElementVariable> for ElementExpression

source§

fn add(self, rhs: ElementVariable) -> ElementExpression

Returns an expression representing the addition.

§

type Output = ElementExpression

The resulting type after applying the + operator.
source§

impl Add<usize> for ElementExpression

source§

fn add(self, rhs: Element) -> ElementExpression

Returns an expression representing the addition.

§

type Output = ElementExpression

The resulting type after applying the + operator.
source§

impl Add for ElementExpression

source§

fn add(self, rhs: Self) -> Self::Output

Returns an expression representing the addition.

§Examples
use dypdl::prelude::*;

let model = Model::default();
let state = model.target.clone();
let a = ElementExpression::from(2);
let b = ElementExpression::from(3);
let expression = a + b;

assert_eq!(expression.eval(&state, &model.table_registry), 5);
§

type Output = ElementExpression

The resulting type after applying the + operator.
source§

impl AddEffect<ElementResourceVariable, ElementExpression> for Transition

source§

fn add_effect<V>( &mut self, v: ElementResourceVariable, expression: V ) -> Result<(), ModelErr>

Adds an effect. Read more
source§

impl AddEffect<ElementVariable, ElementExpression> for Transition

source§

fn add_effect<V>( &mut self, v: ElementVariable, expression: V ) -> Result<(), ModelErr>

Adds an effect. Read more
source§

impl CheckExpression<ElementExpression> for Model

source§

fn check_expression( &self, expression: &ElementExpression, allow_cost: bool ) -> Result<(), ModelErr>

Checks if an expression is valid. Read more
source§

impl Clone for ElementExpression

source§

fn clone(&self) -> ElementExpression

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 ElementExpression

source§

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

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

impl Default for ElementExpression

source§

fn default() -> Self

Returns an expression representing a constant zero.

source§

impl Div<ElementExpression> for ElementResourceVariable

source§

fn div(self, rhs: ElementExpression) -> ElementExpression

Returns an expression representing the division.

§

type Output = ElementExpression

The resulting type after applying the / operator.
source§

impl Div<ElementExpression> for ElementVariable

source§

fn div(self, rhs: ElementExpression) -> ElementExpression

Returns an expression representing the division.

§

type Output = ElementExpression

The resulting type after applying the / operator.
source§

impl Div<ElementExpression> for Element

source§

fn div(self, rhs: ElementExpression) -> ElementExpression

Returns an expression representing the division.

§

type Output = ElementExpression

The resulting type after applying the / operator.
source§

impl Div<ElementResourceVariable> for ElementExpression

source§

fn div(self, rhs: ElementResourceVariable) -> ElementExpression

Returns an expression representing the division.

§

type Output = ElementExpression

The resulting type after applying the / operator.
source§

impl Div<ElementVariable> for ElementExpression

source§

fn div(self, rhs: ElementVariable) -> ElementExpression

Returns an expression representing the division.

§

type Output = ElementExpression

The resulting type after applying the / operator.
source§

impl Div<usize> for ElementExpression

source§

fn div(self, rhs: Element) -> ElementExpression

Returns an expression representing the division.

§

type Output = ElementExpression

The resulting type after applying the / operator.
source§

impl Div for ElementExpression

source§

fn div(self, rhs: Self) -> Self::Output

Returns an expression representing the division.

§Examples
use dypdl::prelude::*;

let model = Model::default();
let state = model.target.clone();
let a = ElementExpression::from(2);
let b = ElementExpression::from(3);
let expression = a / b;

assert_eq!(expression.eval(&state, &model.table_registry), 0);
§

type Output = ElementExpression

The resulting type after applying the / operator.
source§

impl From<ElementExpression> for ArgumentExpression

source§

fn from(v: ElementExpression) -> ArgumentExpression

Converts to this type from the input type.
source§

impl From<ElementResourceVariable> for ElementExpression

source§

fn from(v: ElementResourceVariable) -> ElementExpression

Converts to this type from the input type.
source§

impl From<ElementVariable> for ElementExpression

source§

fn from(v: ElementVariable) -> ElementExpression

Converts to this type from the input type.
source§

impl From<usize> for ElementExpression

source§

fn from(e: Element) -> ElementExpression

Converts to this type from the input type.
source§

impl IfThenElse<ElementExpression> for Condition

source§

fn if_then_else<U, V>(self, lhs: U, rhs: V) -> ElementExpression
where ElementExpression: From<U> + From<V>,

Returns an if-then-else expression, which returns a if this condition holds and b otherwise.
source§

impl MaxMin<ElementExpression> for ElementResourceVariable

§

type Output = ElementExpression

source§

fn max(self, rhs: ElementExpression) -> ElementExpression

Returns an expression representing the maximum.
source§

fn min(self, rhs: ElementExpression) -> ElementExpression

Returns an expression representing the minimum.
source§

impl MaxMin<ElementExpression> for ElementVariable

§

type Output = ElementExpression

source§

fn max(self, rhs: ElementExpression) -> ElementExpression

Returns an expression representing the maximum.
source§

fn min(self, rhs: ElementExpression) -> ElementExpression

Returns an expression representing the minimum.
source§

impl MaxMin<ElementExpression> for Element

§

type Output = ElementExpression

source§

fn max(self, rhs: ElementExpression) -> ElementExpression

Returns an expression representing the maximum.
source§

fn min(self, rhs: ElementExpression) -> ElementExpression

Returns an expression representing the minimum.
source§

impl MaxMin<ElementResourceVariable> for ElementExpression

§

type Output = ElementExpression

source§

fn max(self, rhs: ElementResourceVariable) -> ElementExpression

Returns an expression representing the maximum.
source§

fn min(self, rhs: ElementResourceVariable) -> ElementExpression

Returns an expression representing the minimum.
source§

impl MaxMin<ElementVariable> for ElementExpression

§

type Output = ElementExpression

source§

fn max(self, rhs: ElementVariable) -> ElementExpression

Returns an expression representing the maximum.
source§

fn min(self, rhs: ElementVariable) -> ElementExpression

Returns an expression representing the minimum.
source§

impl MaxMin<usize> for ElementExpression

§

type Output = ElementExpression

source§

fn max(self, rhs: Element) -> ElementExpression

Returns an expression representing the maximum.
source§

fn min(self, rhs: Element) -> ElementExpression

Returns an expression representing the minimum.
source§

impl MaxMin for ElementExpression

source§

fn max(self, rhs: Self) -> Self::Output

Returns an expression representing the maximum.

§Examples
use dypdl::prelude::*;

let model = Model::default();
let state = model.target.clone();
let a = ElementExpression::from(2);
let b = ElementExpression::from(3);
let expression = a.max(b);

assert_eq!(expression.eval(&state, &model.table_registry), 3);
source§

fn min(self, rhs: Self) -> Self::Output

Returns an expression representing the minimum.

§Examples
use dypdl::prelude::*;

let model = Model::default();
let state = model.target.clone();
let a = ElementExpression::from(2);
let b = ElementExpression::from(3);
let expression = a.min(b);

assert_eq!(expression.eval(&state, &model.table_registry), 2);
§

type Output = ElementExpression

source§

impl Mul<ElementExpression> for ElementResourceVariable

source§

fn mul(self, rhs: ElementExpression) -> ElementExpression

Returns an expression representing the multiplication.

§

type Output = ElementExpression

The resulting type after applying the * operator.
source§

impl Mul<ElementExpression> for ElementVariable

source§

fn mul(self, rhs: ElementExpression) -> ElementExpression

Returns an expression representing the multiplication.

§

type Output = ElementExpression

The resulting type after applying the * operator.
source§

impl Mul<ElementExpression> for Element

source§

fn mul(self, rhs: ElementExpression) -> ElementExpression

Returns an expression representing the multiplication.

§

type Output = ElementExpression

The resulting type after applying the * operator.
source§

impl Mul<ElementResourceVariable> for ElementExpression

source§

fn mul(self, rhs: ElementResourceVariable) -> ElementExpression

Returns an expression representing the multiplication.

§

type Output = ElementExpression

The resulting type after applying the * operator.
source§

impl Mul<ElementVariable> for ElementExpression

source§

fn mul(self, rhs: ElementVariable) -> ElementExpression

Returns an expression representing the multiplication.

§

type Output = ElementExpression

The resulting type after applying the * operator.
source§

impl Mul<usize> for ElementExpression

source§

fn mul(self, rhs: Element) -> ElementExpression

Returns an expression representing the multiplication.

§

type Output = ElementExpression

The resulting type after applying the * operator.
source§

impl Mul for ElementExpression

source§

fn mul(self, rhs: Self) -> Self::Output

Returns an expression representing the multiplication.

§Examples
use dypdl::prelude::*;

let model = Model::default();
let state = model.target.clone();
let a = ElementExpression::from(2);
let b = ElementExpression::from(3);
let expression = a * b;

assert_eq!(expression.eval(&state, &model.table_registry), 6);
§

type Output = ElementExpression

The resulting type after applying the * operator.
source§

impl PartialEq for ElementExpression

source§

fn eq(&self, other: &ElementExpression) -> 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 Rem<ElementExpression> for ElementResourceVariable

source§

fn rem(self, rhs: ElementExpression) -> ElementExpression

Returns an expression representing the remainder.

§

type Output = ElementExpression

The resulting type after applying the % operator.
source§

impl Rem<ElementExpression> for ElementVariable

source§

fn rem(self, rhs: ElementExpression) -> ElementExpression

Returns an expression representing the remainder.

§

type Output = ElementExpression

The resulting type after applying the % operator.
source§

impl Rem<ElementExpression> for Element

source§

fn rem(self, rhs: ElementExpression) -> ElementExpression

Returns an expression representing the remainder.

§

type Output = ElementExpression

The resulting type after applying the % operator.
source§

impl Rem<ElementResourceVariable> for ElementExpression

source§

fn rem(self, rhs: ElementResourceVariable) -> ElementExpression

Returns an expression representing the remainder.

§

type Output = ElementExpression

The resulting type after applying the % operator.
source§

impl Rem<ElementVariable> for ElementExpression

source§

fn rem(self, rhs: ElementVariable) -> ElementExpression

Returns an expression representing the remainder.

§

type Output = ElementExpression

The resulting type after applying the % operator.
source§

impl Rem<usize> for ElementExpression

source§

fn rem(self, rhs: Element) -> ElementExpression

Returns an expression representing the remainder.

§

type Output = ElementExpression

The resulting type after applying the % operator.
source§

impl Rem for ElementExpression

source§

fn rem(self, rhs: Self) -> Self::Output

Returns an expression representing the remainder.

§Examples
use dypdl::prelude::*;

let model = Model::default();
let state = model.target.clone();
let a = ElementExpression::from(2);
let b = ElementExpression::from(3);
let expression = a % b;

assert_eq!(expression.eval(&state, &model.table_registry), 2);
§

type Output = ElementExpression

The resulting type after applying the % operator.
source§

impl SetElementOperation<ElementExpression> for Set

source§

fn add(self, rhs: ElementExpression) -> SetExpression

Returns a set expression, where an element is added.
source§

fn remove(self, rhs: ElementExpression) -> SetExpression

Returns a set expression, where an element is removed.
source§

impl SetElementOperation<ElementExpression> for SetExpression

source§

fn add(self, rhs: ElementExpression) -> SetExpression

Returns a set expression, where an element is added.
source§

fn remove(self, rhs: ElementExpression) -> SetExpression

Returns a set expression, where an element is removed.
source§

impl SetElementOperation<ElementExpression> for SetVariable

source§

fn add(self, rhs: ElementExpression) -> SetExpression

Returns a set expression, where an element is added.
source§

fn remove(self, rhs: ElementExpression) -> SetExpression

Returns a set expression, where an element is removed.
source§

impl Sub<ElementExpression> for ElementResourceVariable

source§

fn sub(self, rhs: ElementExpression) -> ElementExpression

Returns an expression representing the subtraction.

§

type Output = ElementExpression

The resulting type after applying the - operator.
source§

impl Sub<ElementExpression> for ElementVariable

source§

fn sub(self, rhs: ElementExpression) -> ElementExpression

Returns an expression representing the subtraction.

§

type Output = ElementExpression

The resulting type after applying the - operator.
source§

impl Sub<ElementExpression> for Element

source§

fn sub(self, rhs: ElementExpression) -> ElementExpression

Returns an expression representing the subtraction.

§

type Output = ElementExpression

The resulting type after applying the - operator.
source§

impl Sub<ElementResourceVariable> for ElementExpression

source§

fn sub(self, rhs: ElementResourceVariable) -> ElementExpression

Returns an expression representing the subtraction.

§

type Output = ElementExpression

The resulting type after applying the - operator.
source§

impl Sub<ElementVariable> for ElementExpression

source§

fn sub(self, rhs: ElementVariable) -> ElementExpression

Returns an expression representing the subtraction.

§

type Output = ElementExpression

The resulting type after applying the - operator.
source§

impl Sub<usize> for ElementExpression

source§

fn sub(self, rhs: Element) -> ElementExpression

Returns an expression representing the subtraction.

§

type Output = ElementExpression

The resulting type after applying the - operator.
source§

impl Sub for ElementExpression

source§

fn sub(self, rhs: Self) -> Self::Output

Returns an expression representing the subtraction.

§Examples
use dypdl::prelude::*;

let model = Model::default();
let state = model.target.clone();
let a = ElementExpression::from(3);
let b = ElementExpression::from(2);
let expression = a - b;

assert_eq!(expression.eval(&state, &model.table_registry), 1);
§

type Output = ElementExpression

The resulting type after applying the - operator.
source§

impl StructuralPartialEq for ElementExpression

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.
source§

impl<T, Rhs, Output> NumOps<Rhs, Output> for T
where T: Sub<Rhs, Output = Output> + Mul<Rhs, Output = Output> + Div<Rhs, Output = Output> + Add<Rhs, Output = Output> + Rem<Rhs, Output = Output>,