Condition

Enum Condition 

Source
pub enum Condition {
    Constant(bool),
    StateFunction(usize),
    Not(Box<Condition>),
    And(Box<Condition>, Box<Condition>),
    Or(Box<Condition>, Box<Condition>),
    ComparisonE(ComparisonOperator, Box<ElementExpression>, Box<ElementExpression>),
    ComparisonI(ComparisonOperator, Box<IntegerExpression>, Box<IntegerExpression>),
    ComparisonC(ComparisonOperator, Box<ContinuousExpression>, Box<ContinuousExpression>),
    Set(Box<SetCondition>),
    Table(Box<TableExpression<bool>>),
}
Expand description

Condition.

Variants§

§

Constant(bool)

Constant.

§

StateFunction(usize)

State function index.

§

Not(Box<Condition>)

Not x.

§

And(Box<Condition>, Box<Condition>)

x and b.

§

Or(Box<Condition>, Box<Condition>)

x or b.

§

ComparisonE(ComparisonOperator, Box<ElementExpression>, Box<ElementExpression>)

Comparing two element expressions.

§

ComparisonI(ComparisonOperator, Box<IntegerExpression>, Box<IntegerExpression>)

Comparing two integer expressions.

§

ComparisonC(ComparisonOperator, Box<ContinuousExpression>, Box<ContinuousExpression>)

Comparing two continuous expressions.

§

Set(Box<SetCondition>)

Set condition.

§

Table(Box<TableExpression<bool>>)

A constant in a boolean table.

Implementations§

Source§

impl Condition

Source

pub fn comparison_e<T, U>(op: ComparisonOperator, lhs: T, rhs: U) -> Self
where ElementExpression: From<T> + From<U>,

Returns a condition comparing two element expressions.

§Examples
use dypdl::prelude::*;

let mut model = Model::default();
let object_type = model.add_object_type("object_type", 4).unwrap();
let variable = model.add_element_variable("variable", object_type, 2).unwrap();
let state = model.target.clone();
let mut function_cache = StateFunctionCache::new(&model.state_functions);

let condition = Condition::comparison_e(ComparisonOperator::Gt, variable, 0);
assert!(
    condition.eval(
        &state, &mut function_cache, &model.state_functions, &model.table_registry,
    )
);
Source

pub fn comparison_i<T, U>(op: ComparisonOperator, lhs: T, rhs: U) -> Self
where IntegerExpression: From<T> + From<U>,

Returns a condition comparing two integer expressions.

§Examples
use dypdl::prelude::*;

let mut model = Model::default();
let variable = model.add_integer_variable("variable", 2).unwrap();
let state = model.target.clone();
let mut function_cache = StateFunctionCache::new(&model.state_functions);

let condition = Condition::comparison_i(ComparisonOperator::Gt, variable, 0);
assert!(
    condition.eval(
        &state, &mut function_cache, &model.state_functions, &model.table_registry,
    )
);
Source

pub fn comparison_c<T, U>(op: ComparisonOperator, lhs: T, rhs: U) -> Self

Returns a condition comparing two continuous expressions.

§Examples
use dypdl::prelude::*;

let mut model = Model::default();
let variable = model.add_continuous_resource_variable("variable", true, 0.5).unwrap();
let state = model.target.clone();
let mut function_cache = StateFunctionCache::new(&model.state_functions);

let condition = Condition::comparison_c(ComparisonOperator::Gt, variable, 0);
assert!(
    condition.eval(
        &state, &mut function_cache, &model.state_functions, &model.table_registry,
    )
);
Source§

impl Condition

Source

pub fn eval<T: StateInterface>( &self, state: &T, function_cache: &mut StateFunctionCache, state_functions: &StateFunctions, registry: &TableRegistry, ) -> bool

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("variable", 1).unwrap();
let state = model.target.clone();
let mut function_cache = StateFunctionCache::new(&model.state_functions);

let condition = Condition::comparison_i(ComparisonOperator::Ge, variable, 0);
assert!(
    condition.eval(
        &state, &mut function_cache, &model.state_functions, &model.table_registry,
    ),
);
Source

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

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 BitAnd for Condition

Source§

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

Returns the conjunction of this condition and rhs.

§Examples
use dypdl::prelude::*;

let mut model = Model::default();
let variable = model.add_integer_variable("variable", 1).unwrap();
let state = model.target.clone();
let mut function_cache = StateFunctionCache::new(&model.state_functions);

let a = Condition::comparison_i(ComparisonOperator::Ge, variable, 0);
let b = Condition::comparison_i(ComparisonOperator::Le, variable, 2);
let condition = a & b;
assert!(
    condition.eval(
        &state, &mut function_cache, &model.state_functions, &model.table_registry,
    )
);
Source§

type Output = Condition

The resulting type after applying the & operator.
Source§

impl BitOr for Condition

Source§

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

Returns the disjunction of this condition and rhs.

§Examples
use dypdl::prelude::*;

let mut model = Model::default();
let variable = model.add_integer_variable("variable", 1).unwrap();
let state = model.target.clone();
let mut function_cache = StateFunctionCache::new(&model.state_functions);

let a = Condition::comparison_i(ComparisonOperator::Ge, variable, 0);
let b = Condition::comparison_i(ComparisonOperator::Lt, variable, 1);
let condition = a | b;
assert!(
    condition.eval(
        &state, &mut function_cache, &model.state_functions, &model.table_registry,
    )
);
Source§

type Output = Condition

The resulting type after applying the | operator.
Source§

impl CheckExpression<Condition> for Model

Source§

fn check_expression( &self, condition: &Condition, allow_cost: bool, ) -> Result<(), ModelErr>

Checks if an expression is valid. Read more
Source§

impl Clone for Condition

Source§

fn clone(&self) -> Condition

Returns a duplicate 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 Condition

Source§

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

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

impl Default for Condition

Source§

fn default() -> Condition

Returns Condition::Constant(false).

Source§

impl From<Condition> for GroundedCondition

Source§

fn from(condition: Condition) -> Self

Creates a grounded condition from a condition.

Source§

impl From<GroundedCondition> for Condition

Source§

fn from(grounded_condition: GroundedCondition) -> Self

Creates a condition from a grounded condition.

Source§

impl IfThenElse<ContinuousExpression> for Condition

Source§

fn if_then_else<U, V>(self, lhs: U, rhs: V) -> ContinuousExpression

Returns an if-then-else expression, which returns a if this condition holds and b otherwise.
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 IfThenElse<IntegerExpression> for Condition

Source§

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

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

impl IfThenElse<SetExpression> for Condition

Source§

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

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

impl Not for Condition

Source§

fn not(self) -> Self::Output

Returns the negation of this condition.

§Examples
use dypdl::prelude::*;

let mut model = Model::default();
let variable = model.add_integer_variable("variable", 1).unwrap();
let state = model.target.clone();
let mut function_cache = StateFunctionCache::new(&model.state_functions);

let condition = Condition::comparison_i(ComparisonOperator::Gt, variable, 1);
let condition = !condition;
assert!(
    condition.eval(
        &state, &mut function_cache, &model.state_functions, &model.table_registry,
    )
);
Source§

type Output = Condition

The resulting type after applying the ! operator.
Source§

impl PartialEq for Condition

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for Condition

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

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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,

Source§

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

Source§

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

Source§

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.