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
impl StateMetadata
sourcepub fn number_of_object_types(&self) -> usize
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);sourcepub fn number_of_set_variables(&self) -> usize
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);sourcepub fn number_of_vector_variables(&self) -> usize
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);sourcepub fn number_of_element_variables(&self) -> usize
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);sourcepub fn number_of_integer_variables(&self) -> usize
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);sourcepub fn number_of_continuous_variables(&self) -> usize
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);sourcepub fn number_of_element_resource_variables(&self) -> usize
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);sourcepub fn number_of_integer_resource_variables(&self) -> usize
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);sourcepub fn number_of_continuous_resource_variables(&self) -> usize
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);sourcepub fn has_resource_variables(&self) -> bool
pub fn has_resource_variables(&self) -> bool
Returns true if there is a resource variable and false otherwise.
sourcepub fn get_name_set(&self) -> FxHashSet<String>
pub fn get_name_set(&self) -> FxHashSet<String>
Returns the set of names used by object types and variables.
sourcepub fn dominance<U: StateInterface, V: StateInterface>(
&self,
a: &U,
b: &V
) -> Option<Ordering>
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);sourcepub fn check_state<'a, T: StateInterface>(
&self,
state: &'a T
) -> Result<(), ModelErr>where
&'a T: UnwindSafe,
pub fn check_state<'a, T: StateInterface>(
&self,
state: &'a T
) -> Result<(), ModelErr>where
&'a T: UnwindSafe,
Check if a state is valid.
§Errors
If a state is invalid, e.g., it contains variables not existing in this model.
sourcepub fn get_object_type(&self, name: &str) -> Result<ObjectType, ModelErr>
pub fn get_object_type(&self, name: &str) -> Result<ObjectType, ModelErr>
sourcepub fn add_object_type<T>(
&mut self,
name: T,
number: usize
) -> Result<ObjectType, ModelErr>
pub fn add_object_type<T>( &mut self, name: T, number: usize ) -> Result<ObjectType, ModelErr>
sourcepub fn get_number_of_objects(&self, ob: ObjectType) -> Result<usize, ModelErr>
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.
sourcepub fn create_set(
&self,
ob: ObjectType,
array: &[Element]
) -> Result<Set, ModelErr>
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.
sourcepub fn get_element_variable(
&self,
name: &str
) -> Result<ElementVariable, ModelErr>
pub fn get_element_variable( &self, name: &str ) -> Result<ElementVariable, ModelErr>
sourcepub fn add_element_variable<T>(
&mut self,
name: T,
ob: ObjectType
) -> Result<ElementVariable, ModelErr>
pub fn add_element_variable<T>( &mut self, name: T, ob: ObjectType ) -> Result<ElementVariable, ModelErr>
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.
sourcepub fn get_element_resource_variable(
&self,
name: &str
) -> Result<ElementResourceVariable, ModelErr>
pub fn get_element_resource_variable( &self, name: &str ) -> Result<ElementResourceVariable, ModelErr>
sourcepub fn add_element_resource_variable<T>(
&mut self,
name: T,
ob: ObjectType,
less_is_better: bool
) -> Result<ElementResourceVariable, ModelErr>
pub fn add_element_resource_variable<T>( &mut self, name: T, ob: ObjectType, less_is_better: bool ) -> Result<ElementResourceVariable, ModelErr>
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.
sourcepub fn get_set_variable(&self, name: &str) -> Result<SetVariable, ModelErr>
pub fn get_set_variable(&self, name: &str) -> Result<SetVariable, ModelErr>
sourcepub fn add_set_variable<T>(
&mut self,
name: T,
ob: ObjectType
) -> Result<SetVariable, ModelErr>
pub fn add_set_variable<T>( &mut self, name: T, ob: ObjectType ) -> Result<SetVariable, ModelErr>
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.
sourcepub fn get_vector_variable(
&self,
name: &str
) -> Result<VectorVariable, ModelErr>
pub fn get_vector_variable( &self, name: &str ) -> Result<VectorVariable, ModelErr>
sourcepub fn add_vector_variable<T>(
&mut self,
name: T,
ob: ObjectType
) -> Result<VectorVariable, ModelErr>
pub fn add_vector_variable<T>( &mut self, name: T, ob: ObjectType ) -> Result<VectorVariable, ModelErr>
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.
sourcepub fn get_integer_variable(
&self,
name: &str
) -> Result<IntegerVariable, ModelErr>
pub fn get_integer_variable( &self, name: &str ) -> Result<IntegerVariable, ModelErr>
sourcepub fn add_integer_variable<T>(
&mut self,
name: T
) -> Result<IntegerVariable, ModelErr>
pub fn add_integer_variable<T>( &mut self, name: T ) -> Result<IntegerVariable, ModelErr>
Adds and returns an integer variable.
The value in the target state must be specified.
§Errors
If the name is already used.
sourcepub fn get_integer_resource_variable(
&self,
name: &str
) -> Result<IntegerResourceVariable, ModelErr>
pub fn get_integer_resource_variable( &self, name: &str ) -> Result<IntegerResourceVariable, ModelErr>
sourcepub fn add_integer_resource_variable<T>(
&mut self,
name: T,
less_is_better: bool
) -> Result<IntegerResourceVariable, ModelErr>
pub fn add_integer_resource_variable<T>( &mut self, name: T, less_is_better: bool ) -> Result<IntegerResourceVariable, ModelErr>
Adds and returns an integer resource variable.
The value in the target state must be specified.
§Errors
If the name is already used.
sourcepub fn get_continuous_variable(
&self,
name: &str
) -> Result<ContinuousVariable, ModelErr>
pub fn get_continuous_variable( &self, name: &str ) -> Result<ContinuousVariable, ModelErr>
sourcepub fn add_continuous_variable<T>(
&mut self,
name: T
) -> Result<ContinuousVariable, ModelErr>
pub fn add_continuous_variable<T>( &mut self, name: T ) -> Result<ContinuousVariable, ModelErr>
Adds and returns a continuous variable.
The value in the target state must be specified.
§Errors
If the name is already used.
sourcepub fn get_continuous_resource_variable(
&self,
name: &str
) -> Result<ContinuousResourceVariable, ModelErr>
pub fn get_continuous_resource_variable( &self, name: &str ) -> Result<ContinuousResourceVariable, ModelErr>
sourcepub fn add_continuous_resource_variable<T>(
&mut self,
name: T,
less_is_better: bool
) -> Result<ContinuousResourceVariable, ModelErr>
pub fn add_continuous_resource_variable<T>( &mut self, name: T, less_is_better: bool ) -> Result<ContinuousResourceVariable, ModelErr>
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
impl AccessPreference<ContinuousResourceVariable> for StateMetadata
source§fn get_preference(
&self,
v: ContinuousResourceVariable
) -> Result<bool, ModelErr>
fn get_preference( &self, v: ContinuousResourceVariable ) -> Result<bool, ModelErr>
source§fn set_preference(
&mut self,
v: ContinuousResourceVariable,
less_is_better: bool
) -> Result<(), ModelErr>
fn set_preference( &mut self, v: ContinuousResourceVariable, less_is_better: bool ) -> Result<(), ModelErr>
source§impl AccessPreference<ElementResourceVariable> for StateMetadata
impl AccessPreference<ElementResourceVariable> for StateMetadata
source§fn get_preference(&self, v: ElementResourceVariable) -> Result<bool, ModelErr>
fn get_preference(&self, v: ElementResourceVariable) -> Result<bool, ModelErr>
source§fn set_preference(
&mut self,
v: ElementResourceVariable,
less_is_better: bool
) -> Result<(), ModelErr>
fn set_preference( &mut self, v: ElementResourceVariable, less_is_better: bool ) -> Result<(), ModelErr>
source§impl AccessPreference<IntegerResourceVariable> for StateMetadata
impl AccessPreference<IntegerResourceVariable> for StateMetadata
source§fn get_preference(&self, v: IntegerResourceVariable) -> Result<bool, ModelErr>
fn get_preference(&self, v: IntegerResourceVariable) -> Result<bool, ModelErr>
source§fn set_preference(
&mut self,
v: IntegerResourceVariable,
less_is_better: bool
) -> Result<(), ModelErr>
fn set_preference( &mut self, v: IntegerResourceVariable, less_is_better: bool ) -> Result<(), ModelErr>
source§impl CheckVariable<ContinuousResourceVariable> for StateMetadata
impl CheckVariable<ContinuousResourceVariable> for StateMetadata
source§fn check_variable(&self, v: ContinuousResourceVariable) -> Result<(), ModelErr>
fn check_variable(&self, v: ContinuousResourceVariable) -> Result<(), ModelErr>
source§impl CheckVariable<ContinuousVariable> for StateMetadata
impl CheckVariable<ContinuousVariable> for StateMetadata
source§fn check_variable(&self, v: ContinuousVariable) -> Result<(), ModelErr>
fn check_variable(&self, v: ContinuousVariable) -> Result<(), ModelErr>
source§impl CheckVariable<ElementResourceVariable> for StateMetadata
impl CheckVariable<ElementResourceVariable> for StateMetadata
source§fn check_variable(&self, v: ElementResourceVariable) -> Result<(), ModelErr>
fn check_variable(&self, v: ElementResourceVariable) -> Result<(), ModelErr>
source§impl CheckVariable<ElementVariable> for StateMetadata
impl CheckVariable<ElementVariable> for StateMetadata
source§fn check_variable(&self, v: ElementVariable) -> Result<(), ModelErr>
fn check_variable(&self, v: ElementVariable) -> Result<(), ModelErr>
source§impl CheckVariable<IntegerResourceVariable> for StateMetadata
impl CheckVariable<IntegerResourceVariable> for StateMetadata
source§fn check_variable(&self, v: IntegerResourceVariable) -> Result<(), ModelErr>
fn check_variable(&self, v: IntegerResourceVariable) -> Result<(), ModelErr>
source§impl CheckVariable<IntegerVariable> for StateMetadata
impl CheckVariable<IntegerVariable> for StateMetadata
source§fn check_variable(&self, v: IntegerVariable) -> Result<(), ModelErr>
fn check_variable(&self, v: IntegerVariable) -> Result<(), ModelErr>
source§impl CheckVariable<SetVariable> for StateMetadata
impl CheckVariable<SetVariable> for StateMetadata
source§fn check_variable(&self, v: SetVariable) -> Result<(), ModelErr>
fn check_variable(&self, v: SetVariable) -> Result<(), ModelErr>
source§impl CheckVariable<VectorVariable> for StateMetadata
impl CheckVariable<VectorVariable> for StateMetadata
source§fn check_variable(&self, v: VectorVariable) -> Result<(), ModelErr>
fn check_variable(&self, v: VectorVariable) -> Result<(), ModelErr>
source§impl Clone for StateMetadata
impl Clone for StateMetadata
source§fn clone(&self) -> StateMetadata
fn clone(&self) -> StateMetadata
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moresource§impl Debug for StateMetadata
impl Debug for StateMetadata
source§impl Default for StateMetadata
impl Default for StateMetadata
source§fn default() -> StateMetadata
fn default() -> StateMetadata
source§impl GetObjectTypeOf<ElementResourceVariable> for StateMetadata
impl GetObjectTypeOf<ElementResourceVariable> for StateMetadata
source§fn get_object_type_of(
&self,
v: ElementResourceVariable
) -> Result<ObjectType, ModelErr>
fn get_object_type_of( &self, v: ElementResourceVariable ) -> Result<ObjectType, ModelErr>
source§impl GetObjectTypeOf<ElementVariable> for StateMetadata
impl GetObjectTypeOf<ElementVariable> for StateMetadata
source§fn get_object_type_of(&self, v: ElementVariable) -> Result<ObjectType, ModelErr>
fn get_object_type_of(&self, v: ElementVariable) -> Result<ObjectType, ModelErr>
source§impl GetObjectTypeOf<SetVariable> for StateMetadata
impl GetObjectTypeOf<SetVariable> for StateMetadata
source§fn get_object_type_of(&self, v: SetVariable) -> Result<ObjectType, ModelErr>
fn get_object_type_of(&self, v: SetVariable) -> Result<ObjectType, ModelErr>
source§impl GetObjectTypeOf<VectorVariable> for StateMetadata
impl GetObjectTypeOf<VectorVariable> for StateMetadata
source§fn get_object_type_of(&self, v: VectorVariable) -> Result<ObjectType, ModelErr>
fn get_object_type_of(&self, v: VectorVariable) -> Result<ObjectType, ModelErr>
source§impl PartialEq for StateMetadata
impl PartialEq for StateMetadata
source§fn eq(&self, other: &StateMetadata) -> bool
fn eq(&self, other: &StateMetadata) -> bool
self and other values to be equal, and is used
by ==.