Struct dypdl::StateMetadata

source ·
pub struct StateMetadata {
Show 26 fields pub object_type_names: Vec<String>, pub name_to_object_type: FxHashMap<String, usize>, pub object_numbers: Vec<usize>, pub set_variable_names: Vec<String>, pub name_to_set_variable: FxHashMap<String, usize>, pub set_variable_to_object: Vec<usize>, pub vector_variable_names: Vec<String>, pub name_to_vector_variable: FxHashMap<String, usize>, pub vector_variable_to_object: Vec<usize>, pub element_variable_names: Vec<String>, pub name_to_element_variable: FxHashMap<String, usize>, pub element_variable_to_object: Vec<usize>, pub integer_variable_names: Vec<String>, pub name_to_integer_variable: FxHashMap<String, usize>, pub continuous_variable_names: Vec<String>, pub name_to_continuous_variable: FxHashMap<String, usize>, pub element_resource_variable_names: Vec<String>, pub name_to_element_resource_variable: FxHashMap<String, usize>, pub element_resource_variable_to_object: Vec<usize>, pub element_less_is_better: Vec<bool>, pub integer_resource_variable_names: Vec<String>, pub name_to_integer_resource_variable: FxHashMap<String, usize>, pub integer_less_is_better: Vec<bool>, pub continuous_resource_variable_names: Vec<String>, pub name_to_continuous_resource_variable: FxHashMap<String, usize>, pub continuous_less_is_better: Vec<bool>,
}
Expand description

Information about state variables.

Fields§

§object_type_names: Vec<String>

Map from an object type id to the name.

§name_to_object_type: FxHashMap<String, usize>

Map from a name to its object type id.

§object_numbers: Vec<usize>

Map from an object type id to the number of objects.

§set_variable_names: Vec<String>

Map from a set variable id to the name.

§name_to_set_variable: FxHashMap<String, usize>

Map from a name to the set variable id.

§set_variable_to_object: Vec<usize>

Map from a set variable id to its object type id.

§vector_variable_names: Vec<String>

Map from a vector variable id to the name.

§name_to_vector_variable: FxHashMap<String, usize>

Map from a name to a set variable id.

§vector_variable_to_object: Vec<usize>

Map from a vector variable id to its object type id.

§element_variable_names: Vec<String>

Map from an element variable id to the name.

§name_to_element_variable: FxHashMap<String, usize>

Map from a name to an element variable id.

§element_variable_to_object: Vec<usize>

Map from an element variable id to its object type id.

§integer_variable_names: Vec<String>

Map from an integer variable id to the name.

§name_to_integer_variable: FxHashMap<String, usize>

Map from a name to an integer variable id.

§continuous_variable_names: Vec<String>

Map from a continuous variable id to the name.

§name_to_continuous_variable: FxHashMap<String, usize>

Map from a name to a continuous variable id.

§element_resource_variable_names: Vec<String>

Map from an element resource variable id to the name.

§name_to_element_resource_variable: FxHashMap<String, usize>

Map from a name to an element resource variable id.

§element_resource_variable_to_object: Vec<usize>

Map from an element resource variable id to its object type id.

§element_less_is_better: Vec<bool>

Map from an element resource variable id to its preference.

§integer_resource_variable_names: Vec<String>

Map from an integer resource variable id to the name.

§name_to_integer_resource_variable: FxHashMap<String, usize>

Map from a name to an integer resource variable id.

§integer_less_is_better: Vec<bool>

Map from an integer resource variable id to its preference.

§continuous_resource_variable_names: Vec<String>

Map from a continuous resource variable id to the name.

§name_to_continuous_resource_variable: FxHashMap<String, usize>

Map from a name to a continuous resource variable id.

§continuous_less_is_better: Vec<bool>

Map from a continuous resource variable id to its preference.

Implementations§

source§

impl StateMetadata

source

pub fn number_of_object_types(&self) -> usize

Returns the number of object types.

§Examples
use dypdl::prelude::*;

let mut model = Model::default();
model.add_object_type("object", 4).unwrap();

assert_eq!(model.state_metadata.number_of_object_types(), 1);
source

pub fn number_of_set_variables(&self) -> usize

Returns the number of set variables.

§Examples
use dypdl::prelude::*;

let mut model = Model::default();
let object_type = model.add_object_type("object", 4).unwrap();
let set = model.create_set(object_type, &[0, 1, 2, 3]).unwrap();
model.add_set_variable("variable", object_type, set).unwrap();

assert_eq!(model.state_metadata.number_of_set_variables(), 1);
source

pub fn number_of_vector_variables(&self) -> usize

Returns the number of vector variables.

§Examples
use dypdl::prelude::*;

let mut model = Model::default();
let object_type = model.add_object_type("object", 4).unwrap();
model.add_vector_variable("variable", object_type, vec![0, 1, 2, 3]).unwrap();

assert_eq!(model.state_metadata.number_of_vector_variables(), 1);
source

pub fn number_of_element_variables(&self) -> usize

Returns the number of element variables.

§Examples
use dypdl::prelude::*;

let mut model = Model::default();
let object_type = model.add_object_type("object", 4).unwrap();
model.add_element_variable("variable", object_type, 0).unwrap();

assert_eq!(model.state_metadata.number_of_element_variables(), 1);
source

pub fn number_of_integer_variables(&self) -> usize

Returns the number of integer variables.

§Examples
use dypdl::prelude::*;

let mut model = Model::default();
model.add_integer_variable("variable", 0).unwrap();

assert_eq!(model.state_metadata.number_of_integer_variables(), 1);
source

pub fn number_of_continuous_variables(&self) -> usize

Returns the number of continuous variables.

§Examples
use dypdl::prelude::*;

let mut model = Model::default();
model.add_continuous_variable("variable", 0.5).unwrap();

assert_eq!(model.state_metadata.number_of_continuous_variables(), 1);
source

pub fn number_of_element_resource_variables(&self) -> usize

Returns the number of element resource variables.

§Examples
use dypdl::prelude::*;

let mut model = Model::default();
let object_type = model.add_object_type("object", 4).unwrap();
model.add_element_resource_variable("variable", object_type, false, 0).unwrap();

assert_eq!(model.state_metadata.number_of_element_resource_variables(), 1);
source

pub fn number_of_integer_resource_variables(&self) -> usize

Returns the number of integer resource variables.

§Examples
use dypdl::prelude::*;

let mut model = Model::default();
model.add_integer_resource_variable("variable", false, 0).unwrap();

assert_eq!(model.state_metadata.number_of_integer_resource_variables(), 1);
source

pub fn number_of_continuous_resource_variables(&self) -> usize

Returns the number of continuous resource variables.

use dypdl::prelude::*;

let mut model = Model::default();
model.add_continuous_resource_variable("variable", false, 0.5).unwrap();

assert_eq!(model.state_metadata.number_of_continuous_resource_variables(), 1);
source

pub fn has_resource_variables(&self) -> bool

Returns true if there is a resource variable and false otherwise.

source

pub fn get_name_set(&self) -> FxHashSet<String>

Returns the set of names used by object types and variables.

source

pub fn dominance<U: StateInterface, V: StateInterface>( &self, a: &U, b: &V ) -> Option<Ordering>

Returns the dominance relation between two states.

§Panics

Panics the metadata is wrong.

§Examples
use dypdl::prelude::*;
use std::cmp::Ordering;

let mut model = Model::default();
let v1 = model.add_integer_resource_variable("v1", false, 1).unwrap();
let v2 = model.add_continuous_resource_variable("v2", true, 1.5).unwrap();
let a = model.target.clone();

model.set_target(v1, 0).unwrap();
model.set_target(v2, 2.5).unwrap();
let b = model.target.clone();
assert_eq!(model.state_metadata.dominance(&a, &b), Some(Ordering::Greater));

model.set_target(v1, 1).unwrap();
model.set_target(v2, 0.5).unwrap();
let b = model.target.clone();
assert_eq!(model.state_metadata.dominance(&a, &b), Some(Ordering::Less));

model.set_target(v1, 0).unwrap();
model.set_target(v2, 0.5).unwrap();
let b = model.target.clone();
assert_eq!(model.state_metadata.dominance(&a, &b), None);
source

pub fn check_state<'a, T: StateInterface>( &self, state: &'a T ) -> Result<(), ModelErr>

Check if a state is valid.

§Errors

If a state is invalid, e.g., it contains variables not existing in this model.

source

pub fn get_object_type(&self, name: &str) -> Result<ObjectType, ModelErr>

Returns object type given a name.

§Errors

If no object type with the name.

source

pub fn add_object_type<T>( &mut self, name: T, number: usize ) -> Result<ObjectType, ModelErr>
where String: From<T>,

Adds an object type and returns it.

§Errors

If the name is already used.

source

pub fn get_number_of_objects(&self, ob: ObjectType) -> Result<usize, ModelErr>

Returns the number of objects associated with the type.

§Errors

If the object type is not in the model.

source

pub fn create_set( &self, ob: ObjectType, array: &[Element] ) -> Result<Set, ModelErr>

Create a set of objects associated with the type.

§Errors

If the object type is not in the model or an input value is greater than or equal to the number of the objects.

source

pub fn get_element_variable( &self, name: &str ) -> Result<ElementVariable, ModelErr>

Returns an element variable given a name.

§Errors

If no such variable.

source

pub fn add_element_variable<T>( &mut self, name: T, ob: ObjectType ) -> Result<ElementVariable, ModelErr>
where String: From<T>,

Adds and returns an element variable.

The value in the target state must be specified.

§Errors

If the name is already used or the object type is not in the model.

source

pub fn get_element_resource_variable( &self, name: &str ) -> Result<ElementResourceVariable, ModelErr>

Returns an element resource variable given a name.

§Errors

If no such variable.

source

pub fn add_element_resource_variable<T>( &mut self, name: T, ob: ObjectType, less_is_better: bool ) -> Result<ElementResourceVariable, ModelErr>
where String: From<T>,

Adds and returns an element resource variable.

The value in the target state must be specified.

§Errors

If the name is already used or the object type is not in the model.

source

pub fn get_set_variable(&self, name: &str) -> Result<SetVariable, ModelErr>

Returns a set variable given a name.

§Errors

If no such variable.

source

pub fn add_set_variable<T>( &mut self, name: T, ob: ObjectType ) -> Result<SetVariable, ModelErr>
where String: From<T>,

Adds and returns a set variable.

The value in the target state must be specified.

§Errors

If the name is already used or the object type is not in the model.

source

pub fn get_vector_variable( &self, name: &str ) -> Result<VectorVariable, ModelErr>

Returns a vector variable given a name.

§Errors

If no such variable.

source

pub fn add_vector_variable<T>( &mut self, name: T, ob: ObjectType ) -> Result<VectorVariable, ModelErr>
where String: From<T>,

Adds and returns a vector variable.

The value in the target state must be specified.

§Errors

If the name is already used or the object type is not in the model.

source

pub fn get_integer_variable( &self, name: &str ) -> Result<IntegerVariable, ModelErr>

Returns an integer variable given a name.

§Errors

If no such variable.

source

pub fn add_integer_variable<T>( &mut self, name: T ) -> Result<IntegerVariable, ModelErr>
where String: From<T>,

Adds and returns an integer variable.

The value in the target state must be specified.

§Errors

If the name is already used.

source

pub fn get_integer_resource_variable( &self, name: &str ) -> Result<IntegerResourceVariable, ModelErr>

Returns an integer resource variable given a name.

§Errors

If no such variable.

source

pub fn add_integer_resource_variable<T>( &mut self, name: T, less_is_better: bool ) -> Result<IntegerResourceVariable, ModelErr>
where String: From<T>,

Adds and returns an integer resource variable.

The value in the target state must be specified.

§Errors

If the name is already used.

source

pub fn get_continuous_variable( &self, name: &str ) -> Result<ContinuousVariable, ModelErr>

Returns a continuous variable given a name.

§Errors

If no such variable.

source

pub fn add_continuous_variable<T>( &mut self, name: T ) -> Result<ContinuousVariable, ModelErr>
where String: From<T>,

Adds and returns a continuous variable.

The value in the target state must be specified.

§Errors

If the name is already used.

source

pub fn get_continuous_resource_variable( &self, name: &str ) -> Result<ContinuousResourceVariable, ModelErr>

Returns a continuous resource variable given a name.

§Errors

If no such variable.

source

pub fn add_continuous_resource_variable<T>( &mut self, name: T, less_is_better: bool ) -> Result<ContinuousResourceVariable, ModelErr>
where String: From<T>,

Adds and returns a continuous resource variable.

The value in the target state must be specified.

§Errors

If the name is already used.

Trait Implementations§

source§

impl AccessPreference<ContinuousResourceVariable> for StateMetadata

source§

fn get_preference( &self, v: ContinuousResourceVariable ) -> Result<bool, ModelErr>

Returns the preference of a resource variable. Read more
source§

fn set_preference( &mut self, v: ContinuousResourceVariable, less_is_better: bool ) -> Result<(), ModelErr>

Sets the preference of a resource variable. Read more
source§

impl AccessPreference<ElementResourceVariable> for StateMetadata

source§

fn get_preference(&self, v: ElementResourceVariable) -> Result<bool, ModelErr>

Returns the preference of a resource variable. Read more
source§

fn set_preference( &mut self, v: ElementResourceVariable, less_is_better: bool ) -> Result<(), ModelErr>

Sets the preference of a resource variable. Read more
source§

impl AccessPreference<IntegerResourceVariable> for StateMetadata

source§

fn get_preference(&self, v: IntegerResourceVariable) -> Result<bool, ModelErr>

Returns the preference of a resource variable. Read more
source§

fn set_preference( &mut self, v: IntegerResourceVariable, less_is_better: bool ) -> Result<(), ModelErr>

Sets the preference of a resource variable. Read more
source§

impl CheckVariable<ContinuousResourceVariable> for StateMetadata

source§

fn check_variable(&self, v: ContinuousResourceVariable) -> Result<(), ModelErr>

Check if the variable is defined. Read more
source§

impl CheckVariable<ContinuousVariable> for StateMetadata

source§

fn check_variable(&self, v: ContinuousVariable) -> Result<(), ModelErr>

Check if the variable is defined. Read more
source§

impl CheckVariable<ElementResourceVariable> for StateMetadata

source§

fn check_variable(&self, v: ElementResourceVariable) -> Result<(), ModelErr>

Check if the variable is defined. Read more
source§

impl CheckVariable<ElementVariable> for StateMetadata

source§

fn check_variable(&self, v: ElementVariable) -> Result<(), ModelErr>

Check if the variable is defined. Read more
source§

impl CheckVariable<IntegerResourceVariable> for StateMetadata

source§

fn check_variable(&self, v: IntegerResourceVariable) -> Result<(), ModelErr>

Check if the variable is defined. Read more
source§

impl CheckVariable<IntegerVariable> for StateMetadata

source§

fn check_variable(&self, v: IntegerVariable) -> Result<(), ModelErr>

Check if the variable is defined. Read more
source§

impl CheckVariable<SetVariable> for StateMetadata

source§

fn check_variable(&self, v: SetVariable) -> Result<(), ModelErr>

Check if the variable is defined. Read more
source§

impl CheckVariable<VectorVariable> for StateMetadata

source§

fn check_variable(&self, v: VectorVariable) -> Result<(), ModelErr>

Check if the variable is defined. Read more
source§

impl Clone for StateMetadata

source§

fn clone(&self) -> StateMetadata

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 StateMetadata

source§

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

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

impl Default for StateMetadata

source§

fn default() -> StateMetadata

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

impl GetObjectTypeOf<ElementResourceVariable> for StateMetadata

source§

fn get_object_type_of( &self, v: ElementResourceVariable ) -> Result<ObjectType, ModelErr>

Returns the object type of the variable. Read more
source§

impl GetObjectTypeOf<ElementVariable> for StateMetadata

source§

fn get_object_type_of(&self, v: ElementVariable) -> Result<ObjectType, ModelErr>

Returns the object type of the variable. Read more
source§

impl GetObjectTypeOf<SetVariable> for StateMetadata

source§

fn get_object_type_of(&self, v: SetVariable) -> Result<ObjectType, ModelErr>

Returns the object type of the variable. Read more
source§

impl GetObjectTypeOf<VectorVariable> for StateMetadata

source§

fn get_object_type_of(&self, v: VectorVariable) -> Result<ObjectType, ModelErr>

Returns the object type of the variable. Read more
source§

impl PartialEq for StateMetadata

source§

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

source§

impl StructuralEq for StateMetadata

source§

impl StructuralPartialEq for StateMetadata

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.