pub struct Model {Show 13 fields
pub state_metadata: StateMetadata,
pub target: State,
pub table_registry: TableRegistry,
pub state_constraints: Vec<GroundedCondition>,
pub base_cases: Vec<BaseCase>,
pub base_states: Vec<(State, Option<CostExpression>)>,
pub reduce_function: ReduceFunction,
pub cost_type: CostType,
pub forward_transitions: Vec<Transition>,
pub forward_forced_transitions: Vec<Transition>,
pub backward_transitions: Vec<Transition>,
pub backward_forced_transitions: Vec<Transition>,
pub dual_bounds: Vec<CostExpression>,
}
Expand description
DyPDL model.
Fields§
§state_metadata: StateMetadata
Information about state variables.
target: State
Target state.
table_registry: TableRegistry
Tables of constants.
state_constraints: Vec<GroundedCondition>
State constraints.
base_cases: Vec<BaseCase>
Base cases.
base_states: Vec<(State, Option<CostExpression>)>
Explicit definitions of base states.
reduce_function: ReduceFunction
Specifying how to compute the value of a state from applicable transitions.
cost_type: CostType
Type of the cost.
forward_transitions: Vec<Transition>
Forward transitions.
forward_forced_transitions: Vec<Transition>
Forward forced transitions.
backward_transitions: Vec<Transition>
Backward transitions.
backward_forced_transitions: Vec<Transition>
Backward forced transitions.
dual_bounds: Vec<CostExpression>
Dual bounds.
Implementations§
source§impl Model
impl Model
sourcepub fn check_constraints<U: StateInterface>(&self, state: &U) -> bool
pub fn check_constraints<U: StateInterface>(&self, state: &U) -> bool
Returns true if a state satisfies all state constraints and false otherwise.
§Examples
use dypdl::prelude::*;
let mut model = Model::default();
let variable = model.add_integer_variable("variable", 2).unwrap();
let state = model.target.clone();
let condition = Condition::comparison_i(ComparisonOperator::Ge, variable, 0);
model.add_state_constraint(condition).unwrap();
assert!(model.check_constraints(&state));
let condition = Condition::comparison_i(ComparisonOperator::Ge, variable, 3);
model.add_state_constraint(condition).unwrap();
assert!(!model.check_constraints(&state));
sourcepub fn is_base<U: StateInterface>(&self, state: &U) -> bool
pub fn is_base<U: StateInterface>(&self, state: &U) -> bool
Returns true if a state satisfies any of base cases and false otherwise.
§Panics
Panics if the cost of the transitioned state is used or a min/max reduce operation is performed on an empty set or vector in a base case.
§Examples
use dypdl::prelude::*;
let mut model = Model::default();
let variable = model.add_integer_variable("variable", 2).unwrap();
let state = model.target.clone();
let a = Condition::comparison_i(ComparisonOperator::Ge, variable, 0);
let b = Condition::comparison_i(ComparisonOperator::Le, variable, 1);
model.add_base_case(vec![a, b]).unwrap();
assert!(!model.is_base(&state));
let a = Condition::comparison_i(ComparisonOperator::Ge, variable, 0);
let b = Condition::comparison_i(ComparisonOperator::Le, variable, 2);
model.add_base_case(vec![a, b]).unwrap();
assert!(model.is_base(&state));
sourcepub fn eval_base_cost<T: Numeric + Ord, U: StateInterface>(
&self,
state: &U,
) -> Option<T>
pub fn eval_base_cost<T: Numeric + Ord, U: StateInterface>( &self, state: &U, ) -> Option<T>
Evaluates the base cost given a state.
Returns None
if the state does not satisfy any base case.
§Examples
use dypdl::prelude::*;
let mut model = Model::default();
let variable = model.add_integer_variable("variable", 2).unwrap();
let state = model.target.clone();
let a = Condition::comparison_i(ComparisonOperator::Ge, variable, 0);
let b = Condition::comparison_i(ComparisonOperator::Le, variable, 1);
model.add_base_case(vec![a, b]).unwrap();
assert!(!model.is_base(&state));
let a = Condition::comparison_i(ComparisonOperator::Ge, variable, 0);
let b = Condition::comparison_i(ComparisonOperator::Le, variable, 2);
model.add_base_case(vec![a, b]).unwrap();
assert!(model.is_base(&state));
sourcepub fn eval_dual_bound<U: StateInterface, T: Numeric + Ord>(
&self,
state: &U,
) -> Option<T>
pub fn eval_dual_bound<U: StateInterface, T: Numeric + Ord>( &self, state: &U, ) -> Option<T>
Evaluates the dual bound given a state.
§Panics
Panics if the cost of the transitioned state is used or a min/max reduce operation is performed on an empty set or vector in a dual bound.
§Examples
use dypdl::prelude::*;
let mut model = Model::default();
model.set_minimize();
let variable = model.add_integer_variable("variable", 2).unwrap();
let state = model.target.clone();
assert_eq!(model.eval_dual_bound::<_, Integer>(&state), None);
model.add_dual_bound(IntegerExpression::from(0)).unwrap();
model.add_dual_bound(IntegerExpression::from(variable)).unwrap();
assert_eq!(model.eval_dual_bound::<_, Integer>(&state), Some(2));
sourcepub fn generate_successor_state<S: StateInterface, R: StateInterface + From<State>, T: TransitionInterface, U: Numeric>(
&self,
state: &S,
cost: U,
transition: &T,
cost_bound: Option<U>,
) -> Option<(R, U)>
pub fn generate_successor_state<S: StateInterface, R: StateInterface + From<State>, T: TransitionInterface, U: Numeric>( &self, state: &S, cost: U, transition: &T, cost_bound: Option<U>, ) -> Option<(R, U)>
Returns the successor state and the cost of a state, given a transition and the cost of the successor state.
Returns None
if the cost is greater than or equal to the bound.
§Panics
Panics if the cost of the transitioned state is used or a min/max reduce operation is performed on an empty set or vector in a precondition or an effect of the transition.
§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 transition = Transition::new("transition");
transition.add_effect(variable, variable + 1);
transition.set_cost(IntegerExpression::Cost + 1);
let (successor, cost): (State, _) = model.generate_successor_state(&state, 0, &transition, None).unwrap();
assert_eq!(successor.get_integer_variable(variable.id()), 3);
assert_eq!(cost, 1);
let result: Option<(State, _)> = model.generate_successor_state(&state, 0, &transition, Some(1));
assert_eq!(result, None);
sourcepub fn validate_forward<T: Numeric + Display + Ord>(
&self,
transitions: &[Transition],
cost: T,
show_message: bool,
) -> bool
pub fn validate_forward<T: Numeric + Display + Ord>( &self, transitions: &[Transition], cost: T, show_message: bool, ) -> bool
Validate a solution consists of forward transitions.
§Panics
Panics if the cost of the transitioned state is used or a min/max reduce operation is performed on an empty set or vector in a precondition or an effect of a transition.
§Examples
use dypdl::prelude::*;
let mut model = Model::default();
let variable = model.add_integer_variable("variable", 1).unwrap();
model.add_base_case(vec![Condition::comparison_i(ComparisonOperator::Eq, variable, 0)]).unwrap();
let mut transition = Transition::new("decrement");
transition.add_effect(variable, variable - 1).unwrap();
transition.set_cost(IntegerExpression::Cost + 1);
let transitions = [transition];
let cost = 1;
assert!(model.validate_forward(&transitions, cost, true));
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.
§Examples
use dypdl::prelude::*;
let mut model = Model::default();
let variable = model.add_integer_variable("variable", 2).unwrap();
assert!(!model.has_resource_variables());
let variable = model.add_integer_resource_variable("variable", true, 2).unwrap();
assert!(model.has_resource_variables());
sourcepub fn has_dual_bounds(&self) -> bool
pub fn has_dual_bounds(&self) -> bool
Returns true if a dual bound is defined and false otherwise.
§Examples
use dypdl::prelude::*;
let mut model = Model::default();
assert!(!model.has_dual_bounds());
model.add_dual_bound(IntegerExpression::from(0)).unwrap();
assert!(model.has_dual_bounds());
sourcepub fn integer_cost_model() -> Model
pub fn integer_cost_model() -> Model
Creates a model whose cost is integer.
sourcepub fn continuous_cost_model() -> Model
pub fn continuous_cost_model() -> Model
Creates a model whose cost is continuous.
sourcepub fn set_minimize(&mut self)
pub fn set_minimize(&mut self)
Set the objective to minimization.
sourcepub fn set_maximize(&mut self)
pub fn set_maximize(&mut self)
Set the objective to maximization.
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>
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.
§Examples
use dypdl::prelude::*;
let mut model = Model::default();
let object_type = model.add_object_type("object", 4).unwrap();
assert!(model.create_set(object_type, &[0, 1, 2, 3]).is_ok());
sourcepub fn get_element_variable(
&self,
name: &str,
) -> Result<ElementVariable, ModelErr>
pub fn get_element_variable( &self, name: &str, ) -> Result<ElementVariable, ModelErr>
Returns an element variable given a name.
§Errors
If no such variable.
§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!(model.get_element_variable("variable").is_ok());
sourcepub fn add_element_variable<T>(
&mut self,
name: T,
ob: ObjectType,
target: Element,
) -> Result<ElementVariable, ModelErr>
pub fn add_element_variable<T>( &mut self, name: T, ob: ObjectType, target: Element, ) -> 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.
§Examples
use dypdl::prelude::*;
let mut model = Model::default();
let object_type = model.add_object_type("object", 4).unwrap();
assert!(model.add_element_variable("variable", object_type, 0).is_ok());
sourcepub fn get_element_resource_variable(
&self,
name: &str,
) -> Result<ElementResourceVariable, ModelErr>
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.
§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!(model.get_element_resource_variable("variable").is_ok());
sourcepub fn add_element_resource_variable<T>(
&mut self,
name: T,
ob: ObjectType,
less_is_better: bool,
target: Element,
) -> Result<ElementResourceVariable, ModelErr>
pub fn add_element_resource_variable<T>( &mut self, name: T, ob: ObjectType, less_is_better: bool, target: Element, ) -> 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.
§Examples
use dypdl::prelude::*;
let mut model = Model::default();
let object_type = model.add_object_type("object", 4).unwrap();
assert!(model.add_element_resource_variable("variable", object_type, false, 0).is_ok());
sourcepub fn get_set_variable(&self, name: &str) -> Result<SetVariable, ModelErr>
pub fn get_set_variable(&self, name: &str) -> Result<SetVariable, ModelErr>
Returns a set variable given a name.
§Errors
If no such variable.
§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!(model.get_set_variable("variable").is_ok());
sourcepub fn add_set_variable<T>(
&mut self,
name: T,
ob: ObjectType,
target: Set,
) -> Result<SetVariable, ModelErr>
pub fn add_set_variable<T>( &mut self, name: T, ob: ObjectType, target: Set, ) -> 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, the object type is not in the model, or the target contains a value greater than or equal to the number of the objects.
§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();
assert!(model.add_set_variable("variable", object_type, set).is_ok());
sourcepub fn get_vector_variable(
&self,
name: &str,
) -> Result<VectorVariable, ModelErr>
pub fn get_vector_variable( &self, name: &str, ) -> Result<VectorVariable, ModelErr>
Returns a vector variable given a name.
§Errors
If no such variable.
§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!(model.get_vector_variable("variable").is_ok());
sourcepub fn add_vector_variable<T>(
&mut self,
name: T,
ob: ObjectType,
target: Vector,
) -> Result<VectorVariable, ModelErr>
pub fn add_vector_variable<T>( &mut self, name: T, ob: ObjectType, target: Vector, ) -> 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, the object type is not in the model, or the target contains a value greater than or equal to the number of the objects.
§Examples
use dypdl::prelude::*;
let mut model = Model::default();
let object_type = model.add_object_type("object", 4).unwrap();
assert!(model.add_vector_variable("variable", object_type, vec![0, 1, 2, 3]).is_ok());
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,
target: Integer,
) -> Result<IntegerVariable, ModelErr>
pub fn add_integer_variable<T>( &mut self, name: T, target: Integer, ) -> 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.
use dypdl::prelude::*;
let mut model = Model::default();
assert!(model.add_integer_variable("variable", 0).is_ok());
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,
target: Integer,
) -> Result<IntegerResourceVariable, ModelErr>
pub fn add_integer_resource_variable<T>( &mut self, name: T, less_is_better: bool, target: Integer, ) -> Result<IntegerResourceVariable, ModelErr>
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,
target: Continuous,
) -> Result<ContinuousVariable, ModelErr>
pub fn add_continuous_variable<T>( &mut self, name: T, target: Continuous, ) -> Result<ContinuousVariable, ModelErr>
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,
target: Continuous,
) -> Result<ContinuousResourceVariable, ModelErr>
pub fn add_continuous_resource_variable<T>( &mut self, name: T, less_is_better: bool, target: Continuous, ) -> Result<ContinuousResourceVariable, ModelErr>
sourcepub fn add_state_constraint(
&mut self,
condition: Condition,
) -> Result<(), ModelErr>
pub fn add_state_constraint( &mut self, condition: Condition, ) -> Result<(), ModelErr>
Adds a state constraint.
§Errors
If the condition is invalid, e.., it uses not existing variables or the state of the transitioned state.
§Examples
use dypdl::prelude::*;
let mut model = Model::default();
let variable = model.add_integer_variable("variable", 2).unwrap();
let constraint = Condition::comparison_i(ComparisonOperator::Ge, variable, 0);
assert!(model.add_state_constraint(constraint).is_ok());
sourcepub fn add_base_case(
&mut self,
conditions: Vec<Condition>,
) -> Result<(), ModelErr>
pub fn add_base_case( &mut self, conditions: Vec<Condition>, ) -> Result<(), ModelErr>
Adds a base case.
The cost of a base case is assumed to be zero.
§Errors
If a condition is invalid, e.g., it uses variables not existing in this model or the state of the transitioned state.
§Examples
use dypdl::prelude::*;
let mut model = Model::default();
let variable = model.add_integer_variable("variable", 2).unwrap();
let a = Condition::comparison_i(ComparisonOperator::Ge, variable, 0);
let b = Condition::comparison_i(ComparisonOperator::Le, variable, 1);
assert!(model.add_base_case(vec![a, b]).is_ok());
sourcepub fn add_base_case_with_cost<T>(
&mut self,
conditions: Vec<Condition>,
cost: T,
) -> Result<(), ModelErr>where
CostExpression: From<T>,
pub fn add_base_case_with_cost<T>(
&mut self,
conditions: Vec<Condition>,
cost: T,
) -> Result<(), ModelErr>where
CostExpression: From<T>,
Adds a base case with its cost.
§Errors
If a condition is invalid, e.g., it uses variables not existing in this model or the state of the transitioned state.
§Examples
use dypdl::prelude::*;
let mut model = Model::default();
let variable = model.add_integer_variable("variable", 2).unwrap();
let a = Condition::comparison_i(ComparisonOperator::Ge, variable, 0);
let b = Condition::comparison_i(ComparisonOperator::Le, variable, 1);
let cost = 1;
assert!(model.add_base_case_with_cost(vec![a, b], 1).is_ok());
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 add_base_state(&mut self, state: State) -> Result<(), ModelErr>
pub fn add_base_state(&mut self, state: State) -> Result<(), ModelErr>
Adds a base state.
The cost of the state is assumed to be zero.
§Errors
If a state is invalid, e.g., it contains variables not existing in this model.
sourcepub fn add_base_state_with_cost<T>(
&mut self,
state: State,
cost: T,
) -> Result<(), ModelErr>where
CostExpression: From<T>,
pub fn add_base_state_with_cost<T>(
&mut self,
state: State,
cost: T,
) -> Result<(), ModelErr>where
CostExpression: From<T>,
Adds a base state with its cost.
§Errors
If a state is invalid, e.g., it contains variables not existing in this model.
sourcepub fn get_reduce_function(&self) -> ReduceFunction
pub fn get_reduce_function(&self) -> ReduceFunction
Returns the reduce function.
sourcepub fn set_reduce_function(&mut self, reduce_function: ReduceFunction)
pub fn set_reduce_function(&mut self, reduce_function: ReduceFunction)
Changes the reduce function.
sourcepub fn add_forward_transition(
&mut self,
transition: Transition,
) -> Result<(), ModelErr>
pub fn add_forward_transition( &mut self, transition: Transition, ) -> Result<(), ModelErr>
Adds a forward transition.
§Errors
If it uses an invalid expression, e.g., it uses variables not existing in this model or the state of the transitioned state.
§Examples
use dypdl::prelude::*;
let mut model = Model::default();
let transition = Transition::new("transition");
assert!(model.add_forward_transition(transition).is_ok());
sourcepub fn add_forward_forced_transition(
&mut self,
transition: Transition,
) -> Result<(), ModelErr>
pub fn add_forward_forced_transition( &mut self, transition: Transition, ) -> Result<(), ModelErr>
Adds a forward forced transition.
§Errors
If it uses an invalid expression, e.g., it uses variables not existing in this model or the state of the transitioned state.
§Examples
use dypdl::prelude::*;
let mut model = Model::default();
let transition = Transition::new("transition");
assert!(model.add_forward_forced_transition(transition).is_ok());
sourcepub fn add_backward_transition(
&mut self,
transition: Transition,
) -> Result<(), ModelErr>
pub fn add_backward_transition( &mut self, transition: Transition, ) -> Result<(), ModelErr>
Adds a backward transition.
§Errors
If it uses an invalid expression, e.g., it uses variables not existing in this model or the state of the transitioned state.
§Examples
use dypdl::prelude::*;
let mut model = Model::default();
let transition = Transition::new("transition");
assert!(model.add_backward_transition(transition).is_ok());
sourcepub fn add_backward_forced_transition(
&mut self,
transition: Transition,
) -> Result<(), ModelErr>
pub fn add_backward_forced_transition( &mut self, transition: Transition, ) -> Result<(), ModelErr>
Adds a backward forced transition.
§Errors
If it uses an invalid expression, e.g., it uses variables not existing in this model or the state of the transitioned state.
§Examples
use dypdl::prelude::*;
let mut model = Model::default();
let transition = Transition::new("transition");
assert!(model.add_backward_forced_transition(transition).is_ok());
sourcepub fn get_capacity_of_set_in_1d_table(
&self,
table: Table1DHandle<Set>,
) -> Result<usize, ModelErr>
pub fn get_capacity_of_set_in_1d_table( &self, table: Table1DHandle<Set>, ) -> Result<usize, ModelErr>
Returns the capacity of a set constant in a 1D table.
§Errors
Errors if the table does not exist in the model.
§Panics
Panics if the table is empty.
§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();
let table = model.add_table_1d("table", vec![set]).unwrap();
assert_eq!(model.get_capacity_of_set_in_1d_table(table).unwrap(), 4);
sourcepub fn get_capacity_of_set_in_2d_table(
&self,
table: Table2DHandle<Set>,
) -> Result<usize, ModelErr>
pub fn get_capacity_of_set_in_2d_table( &self, table: Table2DHandle<Set>, ) -> Result<usize, ModelErr>
Returns the capacity of a set constant in a 2D table.
§Errors
Errors if the table does not exist in the model.
§Panics
Panics if the table is empty.
§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();
let table = model.add_table_2d("table", vec![vec![set]]).unwrap();
assert_eq!(model.get_capacity_of_set_in_2d_table(table).unwrap(), 4);
sourcepub fn get_capacity_of_set_in_3d_table(
&self,
table: Table3DHandle<Set>,
) -> Result<usize, ModelErr>
pub fn get_capacity_of_set_in_3d_table( &self, table: Table3DHandle<Set>, ) -> Result<usize, ModelErr>
Returns the capacity of a set constant in a 3D table.
§Errors
Errors if the table does not exist in the model.
§Panics
Panics if the table is empty.
§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();
let table = model.add_table_3d("table", vec![vec![vec![set]]]).unwrap();
assert_eq!(model.get_capacity_of_set_in_3d_table(table).unwrap(), 4);
sourcepub fn get_capacity_of_set_in_table(
&self,
table: TableHandle<Set>,
) -> Result<usize, ModelErr>
pub fn get_capacity_of_set_in_table( &self, table: TableHandle<Set>, ) -> Result<usize, ModelErr>
Returns the capacity of a set constant in a table.
§Errors
Errors if the table does not exist in the model.
§Panics
Panics if the table is empty.
§Examples
use dypdl::prelude::*;
use rustc_hash::FxHashMap;
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();
let map = FxHashMap::from_iter(vec![(vec![0, 0, 0, 0], set.clone())]);
let table = model.add_table("table", map, set.clone()).unwrap();
assert_eq!(model.get_capacity_of_set_in_table(table).unwrap(), 4);
Trait Implementations§
source§impl AccessPreference<ContinuousResourceVariable> for Model
impl AccessPreference<ContinuousResourceVariable> for Model
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 Model
impl AccessPreference<ElementResourceVariable> for Model
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 Model
impl AccessPreference<IntegerResourceVariable> for Model
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 AccessTarget<ContinuousResourceVariable, f64> for Model
impl AccessTarget<ContinuousResourceVariable, f64> for Model
source§fn get_target(
&self,
v: ContinuousResourceVariable,
) -> Result<Continuous, ModelErr>
fn get_target( &self, v: ContinuousResourceVariable, ) -> Result<Continuous, ModelErr>
source§fn set_target(
&mut self,
v: ContinuousResourceVariable,
target: Continuous,
) -> Result<(), ModelErr>
fn set_target( &mut self, v: ContinuousResourceVariable, target: Continuous, ) -> Result<(), ModelErr>
source§impl AccessTarget<ContinuousVariable, f64> for Model
impl AccessTarget<ContinuousVariable, f64> for Model
source§fn get_target(&self, v: ContinuousVariable) -> Result<Continuous, ModelErr>
fn get_target(&self, v: ContinuousVariable) -> Result<Continuous, ModelErr>
source§fn set_target(
&mut self,
v: ContinuousVariable,
target: Continuous,
) -> Result<(), ModelErr>
fn set_target( &mut self, v: ContinuousVariable, target: Continuous, ) -> Result<(), ModelErr>
source§impl AccessTarget<ElementResourceVariable, usize> for Model
impl AccessTarget<ElementResourceVariable, usize> for Model
source§fn get_target(
&self,
variable: ElementResourceVariable,
) -> Result<Element, ModelErr>
fn get_target( &self, variable: ElementResourceVariable, ) -> Result<Element, ModelErr>
source§fn set_target(
&mut self,
variable: ElementResourceVariable,
target: Element,
) -> Result<(), ModelErr>
fn set_target( &mut self, variable: ElementResourceVariable, target: Element, ) -> Result<(), ModelErr>
source§impl AccessTarget<ElementVariable, usize> for Model
impl AccessTarget<ElementVariable, usize> for Model
source§fn get_target(&self, variable: ElementVariable) -> Result<Element, ModelErr>
fn get_target(&self, variable: ElementVariable) -> Result<Element, ModelErr>
source§fn set_target(
&mut self,
variable: ElementVariable,
target: Element,
) -> Result<(), ModelErr>
fn set_target( &mut self, variable: ElementVariable, target: Element, ) -> Result<(), ModelErr>
source§impl AccessTarget<IntegerResourceVariable, i32> for Model
impl AccessTarget<IntegerResourceVariable, i32> for Model
source§fn get_target(&self, v: IntegerResourceVariable) -> Result<Integer, ModelErr>
fn get_target(&self, v: IntegerResourceVariable) -> Result<Integer, ModelErr>
source§fn set_target(
&mut self,
v: IntegerResourceVariable,
target: Integer,
) -> Result<(), ModelErr>
fn set_target( &mut self, v: IntegerResourceVariable, target: Integer, ) -> Result<(), ModelErr>
source§impl AccessTarget<IntegerVariable, i32> for Model
impl AccessTarget<IntegerVariable, i32> for Model
source§fn get_target(&self, v: IntegerVariable) -> Result<Integer, ModelErr>
fn get_target(&self, v: IntegerVariable) -> Result<Integer, ModelErr>
source§fn set_target(
&mut self,
v: IntegerVariable,
target: Integer,
) -> Result<(), ModelErr>
fn set_target( &mut self, v: IntegerVariable, target: Integer, ) -> Result<(), ModelErr>
source§impl AccessTarget<SetVariable, FixedBitSet> for Model
impl AccessTarget<SetVariable, FixedBitSet> for Model
source§fn get_target(&self, variable: SetVariable) -> Result<Set, ModelErr>
fn get_target(&self, variable: SetVariable) -> Result<Set, ModelErr>
source§fn set_target(
&mut self,
variable: SetVariable,
target: Set,
) -> Result<(), ModelErr>
fn set_target( &mut self, variable: SetVariable, target: Set, ) -> Result<(), ModelErr>
source§impl AccessTarget<VectorVariable, Vec<usize>> for Model
impl AccessTarget<VectorVariable, Vec<usize>> for Model
source§fn get_target(&self, variable: VectorVariable) -> Result<Vector, ModelErr>
fn get_target(&self, variable: VectorVariable) -> Result<Vector, ModelErr>
source§fn set_target(
&mut self,
variable: VectorVariable,
target: Vector,
) -> Result<(), ModelErr>
fn set_target( &mut self, variable: VectorVariable, target: Vector, ) -> Result<(), ModelErr>
source§impl AddDualBound<ContinuousExpression> for Model
impl AddDualBound<ContinuousExpression> for Model
source§fn add_dual_bound(
&mut self,
bound: ContinuousExpression,
) -> Result<(), ModelErr>
fn add_dual_bound( &mut self, bound: ContinuousExpression, ) -> Result<(), ModelErr>
Adds a dual bound.
§Errors
If the expression is invalid, e.g., it uses not existing variables or the state of the transitioned state. If the cost type is integer.
§Examples
use dypdl::prelude::*;
let mut model = Model::continuous_cost_model();
assert!(model.add_dual_bound(ContinuousExpression::from(0.0)).is_ok());