Struct dypdl::Transition

source ·
pub struct Transition {
    pub name: String,
    pub parameter_names: Vec<String>,
    pub parameter_values: Vec<Element>,
    pub elements_in_set_variable: Vec<(usize, Element)>,
    pub elements_in_vector_variable: Vec<(usize, Element, usize)>,
    pub preconditions: Vec<GroundedCondition>,
    pub effect: Effect,
    pub cost: CostExpression,
}
Expand description

Transition.

Fields§

§name: String

Name of the transition.

§parameter_names: Vec<String>§parameter_values: Vec<Element>

The values of parameters.

§elements_in_set_variable: Vec<(usize, Element)>

Pairs of an index of a set variable and a parameter. A parameter must be included in the corresponding variable to be applicable.

§elements_in_vector_variable: Vec<(usize, Element, usize)>

Triplets of an index of a vector variable, a parameter, and the capacity. A parameter must be included in the corresponding variable to be applicable.

§preconditions: Vec<GroundedCondition>

Preconditions.

§effect: Effect

Effect.

§cost: CostExpression

Cost expression.

Implementations§

source§

impl Transition

source

pub fn get_full_name(&self) -> String

Returns the name of transition considering parameters.

§Examples
use dypdl::prelude::*;

let transition = Transition::new("transition");
assert_eq!(transition.get_full_name(), String::from("transition"));
source

pub fn new<T>(name: T) -> Transition
where String: From<T>,

Returns a new transition with the name.

source

pub fn set_cost<T>(&mut self, cost: T)
where CostExpression: From<T>,

Sets the cost expression;

§Examples
use dypdl::prelude::*;

let mut transition = Transition::new("transition");
transition.set_cost(IntegerExpression::Cost + 1);
source

pub fn get_preconditions(&self) -> Vec<Condition>

Gets preconditions.

Note that the preconditions and their order might be changed due to internal optimizations.

§Examples
use dypdl::prelude::*;

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

let mut transition = Transition::new("transition");
let condition = Condition::comparison_i(ComparisonOperator::Ge, variable, 0);;
transition.add_precondition(condition.clone());

let preconditions = transition.get_preconditions();
assert_eq!(preconditions.len(), 1);
assert!(preconditions[0].eval(&state, &model.table_registry));
source

pub fn add_precondition(&mut self, condition: Condition)

Adds a precondition;

§Examples
use dypdl::prelude::*;

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

let mut transition = Transition::new("transition");
let condition = Condition::comparison_i(ComparisonOperator::Ge, variable, 0);;
transition.add_precondition(condition);

Trait Implementations§

source§

impl AddEffect<ContinuousResourceVariable, ContinuousExpression> for Transition

source§

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

Adds an effect. Read more
source§

impl AddEffect<ContinuousVariable, ContinuousExpression> for Transition

source§

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

Adds an effect. Read more
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 AddEffect<IntegerResourceVariable, IntegerExpression> for Transition

source§

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

Adds an effect. Read more
source§

impl AddEffect<IntegerVariable, IntegerExpression> for Transition

source§

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

Adds an effect. Read more
source§

impl AddEffect<SetVariable, SetExpression> for Transition

source§

fn add_effect<V>( &mut self, v: SetVariable, expression: V ) -> Result<(), ModelErr>
where SetExpression: From<V>,

Adds an effect. Read more
source§

impl AddEffect<VectorVariable, VectorExpression> for Transition

source§

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

Adds an effect. Read more
source§

impl Clone for Transition

source§

fn clone(&self) -> Transition

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 Transition

source§

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

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

impl Default for Transition

source§

fn default() -> Transition

Returns the “default value” for a type. Read more
source§

impl PartialEq for Transition

source§

fn eq(&self, other: &Transition) -> 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 TransitionInterface for Transition

source§

fn is_applicable<S: StateInterface>( &self, state: &S, registry: &TableRegistry ) -> bool

Returns true if the transition is applicable and false otherwise.

§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 mut transition = Transition::new("transition");
assert!(transition.is_applicable(&state, &model.table_registry));

let condition = Condition::comparison_i(ComparisonOperator::Ge, variable, 0);;
transition.add_precondition(condition);
assert!(transition.is_applicable(&state, &model.table_registry));

let condition = Condition::comparison_i(ComparisonOperator::Le, variable, 1);;
transition.add_precondition(condition);
assert!(!transition.is_applicable(&state, &model.table_registry));
source§

fn apply<S: StateInterface, T: From<State>>( &self, state: &S, registry: &TableRegistry ) -> T

Returns the transitioned state.

§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 mut transition = Transition::new("transition");
transition.add_effect(variable, variable + 1);
let state: State = transition.apply(&state, &model.table_registry);
assert_eq!(state.get_integer_variable(variable.id()), 3);
source§

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

Returns the evaluation result of the cost expression.

§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 mut transition = Transition::new("transition");
transition.set_cost(IntegerExpression::Cost + variable);
assert_eq!(transition.eval_cost(1, &state, &model.table_registry), 3);
source§

impl StructuralPartialEq for Transition

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.