Struct dypdl::Table1DHandle

source ·
pub struct Table1DHandle<T>(/* private fields */);
Expand description

A struct wrapping the id of a table.

Implementations§

source§

impl Table1DHandle<bool>

source

pub fn element<T>(&self, x: T) -> Condition

Returns a condition referring to a value in a 1D boolean table.

§Examples
use dypdl::prelude::*;

let mut model = Model::default();
let table = model.add_table_1d("table", vec![true, false]).unwrap();
let object_type = model.add_object_type("object", 2).unwrap();
let variable = model.add_element_variable("variable", object_type, 0).unwrap();
let state = model.target.clone();

let expression = table.element(variable);
assert!(expression.eval(&state, &model.table_registry));
source§

impl Table1DHandle<Continuous>

source

pub fn element<T>(&self, x: T) -> ContinuousExpression

Returns a constant in a 1D continuous table.

§Examples
use dypdl::prelude::*;
use approx::assert_relative_eq;

let mut model = Model::default();
let table = model.add_table_1d("table", vec![0.2, 0.3]).unwrap();
let object_type = model.add_object_type("object", 2).unwrap();
let variable = model.add_element_variable("variable", object_type, 0).unwrap();
let state = model.target.clone();

let expression = table.element(variable);
assert_relative_eq!(expression.eval(&state, &model.table_registry), 0.2);
source

pub fn sum<T>(&self, x: T) -> ContinuousExpression
where SetExpression: From<T>,

Returns the sum of constants over a set expression in a 1D continuous table.

use dypdl::prelude::*;
use approx::assert_relative_eq;

let mut model = Model::default();
let table = model.add_table_1d("table", vec![0.2, 0.3]).unwrap();
let object_type = model.add_object_type("object", 2).unwrap();
let set = model.create_set(object_type, &[0, 1]).unwrap();
let variable = model.add_set_variable("variable", object_type, set).unwrap();
let state = model.target.clone();

let expression = table.sum(variable);
assert_relative_eq!(expression.eval(&state, &model.table_registry), 0.5);
source

pub fn product<T>(&self, x: T) -> ContinuousExpression
where SetExpression: From<T>,

Returns the product of constants over a set expression in a 1D continuous table.

§Examples
use dypdl::prelude::*;
use approx::assert_relative_eq;

let mut model = Model::default();
let table = model.add_table_1d("table", vec![0.2, 0.3]).unwrap();
let object_type = model.add_object_type("object", 2).unwrap();
let set = model.create_set(object_type, &[0, 1]).unwrap();
let variable = model.add_set_variable("variable", object_type, set).unwrap();
let state = model.target.clone();

let expression = table.product(variable);
assert_relative_eq!(expression.eval(&state, &model.table_registry), 0.06);
source

pub fn max<T>(&self, x: T) -> ContinuousExpression
where SetExpression: From<T>,

Returns the maximum of constants over a set expression in a 1D continuous table.

§Examples
use dypdl::prelude::*;
use approx::assert_relative_eq;

let mut model = Model::default();
let table = model.add_table_1d("table", vec![0.2, 0.3]).unwrap();
let object_type = model.add_object_type("object", 2).unwrap();
let set = model.create_set(object_type, &[0, 1]).unwrap();
let variable = model.add_set_variable("variable", object_type, set).unwrap();
let state = model.target.clone();

let expression = table.max(variable);
assert_relative_eq!(expression.eval(&state, &model.table_registry), 0.3);
source

pub fn min<T>(&self, x: T) -> ContinuousExpression
where SetExpression: From<T>,

Returns the minimum of constants over a set expression in a 1D continuous table.

§Examples
use dypdl::prelude::*;
use approx::assert_relative_eq;

let mut model = Model::default();
let table = model.add_table_1d("table", vec![0.2, 0.3]).unwrap();
let object_type = model.add_object_type("object", 2).unwrap();
let set = model.create_set(object_type, &[0, 1]).unwrap();
let variable = model.add_set_variable("variable", object_type, set).unwrap();
let state = model.target.clone();

let expression = table.min(variable);
assert_relative_eq!(expression.eval(&state, &model.table_registry), 0.2);
source§

impl Table1DHandle<Element>

source

pub fn element<T>(&self, x: T) -> ElementExpression

Returns a constant in a 1D element table.

§Examples
use dypdl::prelude::*;

let mut model = Model::default();
let table = model.add_table_1d("table", vec![1, 0]).unwrap();
let object_type = model.add_object_type("object", 2).unwrap();
let variable = model.add_element_variable("variable", object_type, 0).unwrap();
let state = model.target.clone();

let expression = Table1DHandle::<Element>::element(&table, variable);
assert_eq!(expression.eval(&state, &model.table_registry), 1);
source§

impl Table1DHandle<Integer>

source

pub fn element<T>(&self, x: T) -> IntegerExpression

Returns a constant in a 1D integer table.

§Examples
use dypdl::prelude::*;

let mut model = Model::default();
let table = model.add_table_1d("table", vec![2, 3]).unwrap();
let object_type = model.add_object_type("object", 2).unwrap();
let variable = model.add_element_variable("variable", object_type, 0).unwrap();
let state = model.target.clone();

let expression = Table1DHandle::<Integer>::element(&table, variable);
assert_eq!(expression.eval(&state, &model.table_registry), 2);
source

pub fn sum<T>(&self, x: T) -> IntegerExpression
where SetExpression: From<T>,

Returns the sum of constants over a set expression in a 1D integer table.

§Examples
use dypdl::prelude::*;

let mut model = Model::default();
let table = model.add_table_1d("table", vec![2, 3]).unwrap();
let object_type = model.add_object_type("object", 2).unwrap();
let set = model.create_set(object_type, &[0, 1]).unwrap();
let variable = model.add_set_variable("variable", object_type, set).unwrap();
let state = model.target.clone();

let expression = table.sum(variable);
assert_eq!(expression.eval(&state, &model.table_registry), 5);
source

pub fn product<T>(&self, x: T) -> IntegerExpression
where SetExpression: From<T>,

Returns the product of constants over a set expression in a 1D integer table.

§Examples
use dypdl::prelude::*;

let mut model = Model::default();
let table = model.add_table_1d("table", vec![2, 3]).unwrap();
let object_type = model.add_object_type("object", 2).unwrap();
let set = model.create_set(object_type, &[0, 1]).unwrap();
let variable = model.add_set_variable("variable", object_type, set).unwrap();
let state = model.target.clone();

let expression = table.product(variable);
assert_eq!(expression.eval(&state, &model.table_registry), 6);
source

pub fn max<T>(&self, x: T) -> IntegerExpression
where SetExpression: From<T>,

Returns the maximum of constants over a set expression in a 1D integer table.

§Examples
use dypdl::prelude::*;

let mut model = Model::default();
let table = model.add_table_1d("table", vec![2, 3]).unwrap();
let object_type = model.add_object_type("object", 2).unwrap();
let set = model.create_set(object_type, &[0, 1]).unwrap();
let variable = model.add_set_variable("variable", object_type, set).unwrap();
let state = model.target.clone();

let expression = table.max(variable);
assert_eq!(expression.eval(&state, &model.table_registry), 3);
source

pub fn min<T>(&self, x: T) -> IntegerExpression
where SetExpression: From<T>,

Returns the minimum of constants over a set expression in a 1D integer table.

§Examples
use dypdl::prelude::*;

let mut model = Model::default();
let table = model.add_table_1d("table", vec![2, 3]).unwrap();
let object_type = model.add_object_type("object", 2).unwrap();
let set = model.create_set(object_type, &[0, 1]).unwrap();
let variable = model.add_set_variable("variable", object_type, set).unwrap();
let state = model.target.clone();

let expression = table.min(variable);
assert_eq!(expression.eval(&state, &model.table_registry), 2);
source§

impl Table1DHandle<Set>

source

pub fn element<T>(&self, x: T) -> SetExpression

Returns a constant in a 1D set table.

§Examples
use dypdl::prelude::*;

let mut model = Model::default();
let object_type = model.add_object_type("object", 2).unwrap();
let a = model.create_set(object_type, &[1]).unwrap();
let b = model.create_set(object_type, &[0]).unwrap();
let table = model.add_table_1d("table", vec![a.clone(), b]).unwrap();
let variable = model.add_element_variable("variable", object_type, 0).unwrap();
let state = model.target.clone();

let expression = table.element(variable);
assert_eq!(expression.eval(&state, &model.table_registry), a);
source

pub fn union<T>(&self, capacity: usize, x: T) -> SetExpression

Returns the union of sets in a 1D table.

§Examples
use dypdl::prelude::*;

let mut model = Model::default();
let capacity = 2;
let object_type = model.add_object_type("object", capacity).unwrap();
let a = model.create_set(object_type, &[0, 1]).unwrap();
let b = model.create_set(object_type, &[0]).unwrap();
let table = model.add_table_1d("table", vec![a, b]).unwrap();
let set = model.create_set(object_type, &[0, 1]).unwrap();
let variable = model.add_set_variable("variable", object_type, set).unwrap();
let state = model.target.clone();

let expression = table.union(capacity, variable);
let expected = model.create_set(object_type, &[0, 1]).unwrap();
assert_eq!(expression.eval(&state, &model.table_registry), expected);
source

pub fn intersection<T>(&self, capacity: usize, x: T) -> SetExpression

Returns the intersection of sets in a 1D table.

§Examples
use dypdl::prelude::*;

let mut model = Model::default();
let capacity = 2;
let object_type = model.add_object_type("object", capacity).unwrap();
let a = model.create_set(object_type, &[0, 1]).unwrap();
let b = model.create_set(object_type, &[0]).unwrap();
let table = model.add_table_1d("table", vec![a, b]).unwrap();
let set = model.create_set(object_type, &[0, 1]).unwrap();
let variable = model.add_set_variable("variable", object_type, set).unwrap();
let state = model.target.clone();

let expression = table.intersection(capacity, variable);
let expected = model.create_set(object_type, &[0]).unwrap();
assert_eq!(expression.eval(&state, &model.table_registry), expected);
source

pub fn symmetric_difference<T>(&self, capacity: usize, x: T) -> SetExpression

Returns the symmetric difference (disjunctive union) of sets in a 1D table.

§Examples
use dypdl::prelude::*;

let mut model = Model::default();
let capacity = 2;
let object_type = model.add_object_type("object", capacity).unwrap();
let a = model.create_set(object_type, &[1]).unwrap();
let b = model.create_set(object_type, &[0]).unwrap();
let table = model.add_table_1d("table", vec![a, b]).unwrap();
let set = model.create_set(object_type, &[0, 1]).unwrap();
let variable = model.add_set_variable("variable", object_type, set).unwrap();
let state = model.target.clone();

let expression = table.symmetric_difference(capacity, variable);
let expected = model.create_set(object_type, &[0, 1]).unwrap();
assert_eq!(expression.eval(&state, &model.table_registry), expected);
source§

impl<T> Table1DHandle<T>

source

pub fn id(&self) -> usize

Returns the id

Trait Implementations§

source§

impl<T: Clone> Clone for Table1DHandle<T>

source§

fn clone(&self) -> Table1DHandle<T>

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<T: Debug> Debug for Table1DHandle<T>

source§

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

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

impl<T: PartialEq> PartialEq for Table1DHandle<T>

source§

fn eq(&self, other: &Table1DHandle<T>) -> 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<T: Copy> Copy for Table1DHandle<T>

source§

impl<T: Eq> Eq for Table1DHandle<T>

source§

impl<T> StructuralPartialEq for Table1DHandle<T>

Auto Trait Implementations§

§

impl<T> Freeze for Table1DHandle<T>

§

impl<T> RefUnwindSafe for Table1DHandle<T>
where T: RefUnwindSafe,

§

impl<T> Send for Table1DHandle<T>
where T: Send,

§

impl<T> Sync for Table1DHandle<T>
where T: Sync,

§

impl<T> Unpin for Table1DHandle<T>
where T: Unpin,

§

impl<T> UnwindSafe for Table1DHandle<T>
where T: UnwindSafe,

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.