Struct hotdrink_rs::model::Component [−][src]
pub struct Component<T> { /* fields omitted */ }
A collection of variables along with constraints that should be maintained between them. Variables can get new values, values can be retrieved from the component, and the constraints can be enforced. Subscribing to variables will send a notification when the new values are ready.
Implementations
impl<T> Component<T>
[src]
impl<T> Component<T>
[src]pub fn new_empty(name: String) -> Self
[src]
Constructs a new Constraint
with the specified name.
pub fn subscribe<'s>(
&mut self,
variable: &'s str,
callback: impl Fn(Event<'_, T, SolveError>) + Send + 'static
) -> Result<(), NoSuchVariable<'s>> where
T: 'static,
[src]
&mut self,
variable: &'s str,
callback: impl Fn(Event<'_, T, SolveError>) + Send + 'static
) -> Result<(), NoSuchVariable<'s>> where
T: 'static,
Add a callback to be called when a given variable is updated.
pub fn unsubscribe<'s>(
&mut self,
variable: &'s str
) -> Result<(), NoSuchVariable<'s>>
[src]
&mut self,
variable: &'s str
) -> Result<(), NoSuchVariable<'s>>
Unsubscribe from a variable to avoid receiving further events.
pub fn set_variable<'s>(
&mut self,
variable: &'s str,
value: impl Into<T>
) -> Result<(), NoSuchVariable<'s>>
[src]
&mut self,
variable: &'s str,
value: impl Into<T>
) -> Result<(), NoSuchVariable<'s>>
Give a variable a new value, and call its callback.
pub fn variable<'a>(
&self,
variable: &'a str
) -> Result<&Variable<Activation<T>>, NoSuchVariable<'a>>
[src]
&self,
variable: &'a str
) -> Result<&Variable<Activation<T>>, NoSuchVariable<'a>>
Returns the variable called variable
, if one exists.
pub fn value<'a>(
&self,
variable: &'a str
) -> Result<Activation<T>, NoSuchVariable<'a>>
[src]
&self,
variable: &'a str
) -> Result<Activation<T>, NoSuchVariable<'a>>
Returns the current activation of variable
, if one exists.
pub fn name(&self) -> &str
[src]
Returns a reference to the name of this component.
pub fn set_name<S: Into<String>>(&mut self, name: S)
[src]
Sets the name of the component.
pub fn variable_names(&self) -> Vec<&str>
[src]
Returns a Vec<&str>
of names of variables in this component.
pub fn variables(&self) -> &[Variable<Activation<T>>]
[src]
Returns the variables of the component.
pub fn values(&self) -> Vec<&Activation<T>>
[src]
Returns a Vec
of the current values.
pub fn constraint<'a>(
&self,
name: &'a str
) -> Result<&Constraint<T>, NoSuchConstraint<'a>>
[src]
&self,
name: &'a str
) -> Result<&Constraint<T>, NoSuchConstraint<'a>>
Returns a reference to the specified constraint.
pub fn constraint_mut<'a>(
&mut self,
name: &'a str
) -> Result<&mut Constraint<T>, NoSuchConstraint<'a>>
[src]
&mut self,
name: &'a str
) -> Result<&mut Constraint<T>, NoSuchConstraint<'a>>
Returns a mutable reference to the specified constraint.
pub fn new_with_map(
name: String,
name_to_idx: HashMap<String, usize>,
values: Vec<T>,
constraints: Vec<Constraint<T>>
) -> Self
[src]
name: String,
name_to_idx: HashMap<String, usize>,
values: Vec<T>,
constraints: Vec<Constraint<T>>
) -> Self
Constructs a new component from a precomputed map from variable names to indices.
pub fn update(&mut self) -> Result<(), PlanError> where
T: Send + Sync + 'static + Debug,
[src]
T: Send + Sync + 'static + Debug,
Enforces all constraints in the component.
Returns PlanError
if the system is overconstrained.
pub fn par_update(
&mut self,
pool: &mut impl ThreadPool
) -> Result<(), PlanError> where
T: Send + Sync + 'static + Debug,
[src]
&mut self,
pool: &mut impl ThreadPool
) -> Result<(), PlanError> where
T: Send + Sync + 'static + Debug,
Enforces all constraints in the component concurrently.
Returns PlanError
if the system is overconstrained.
pub fn pin<'s>(&mut self, variable: &'s str) -> Result<(), NoSuchVariable<'s>> where
T: 'static,
[src]
T: 'static,
Pins a variable.
This adds a stay constraint to the specified variable,
meaning that planning will attempt to avoid modifying it.
The stay constraint can be remove with Component::unpin
.
pub fn unpin<'s>(&mut self, variable: &'s str) -> Result<(), NoSuchVariable<'s>> where
T: 'static,
[src]
T: 'static,
Unpins a variable.
This removes the stay constraint added by Component::pin
.
pub fn is_modified(&self) -> bool
[src]
Returns true if any variables have been updated since the last solve, meaning that any constraints may be broken.
pub fn ranking(&self) -> Vec<usize>
[src]
Returns the current ranking of variables, based on when they were last updated.
pub fn to_dot_detailed(&self) -> Result<String, Error>
[src]
Constructs a string-representation of a graph formatted in the dot language. This can be used for visualization of the constraint graph that the component represents. This function includes every method in a constraint.
pub fn to_dot_simple(&self) -> Result<String, Error>
[src]
Constructs a string-representation of a graph formatted in the dot language. This can be used for visualization of the constraint graph that the component represents. This function only includes constraints, and not methods.
pub fn undo(&mut self) -> Result<(), NoMoreUndo>
[src]
Jumps back to the previous set/update call.
pub fn redo(&mut self) -> Result<(), NoMoreRedo>
[src]
Jumps forward to the next set/update call.
pub fn new_with_undo_limit(
name: String,
values: Vec<T>,
constraints: Vec<Constraint<T>>,
limit: usize
) -> Self
[src]
name: String,
values: Vec<T>,
constraints: Vec<Constraint<T>>,
limit: usize
) -> Self
Constructs a new Component
with the specified undo limit.
pub fn set_undo_limit(&mut self, limit: UndoLimit)
[src]
Sets the undo-limit on the values of the component.
pub fn enable_constraint<'a>(
&mut self,
name: &'a str
) -> Result<(), NoSuchConstraint<'a>>
[src]
&mut self,
name: &'a str
) -> Result<(), NoSuchConstraint<'a>>
Enables a specific constraint.
pub fn disable_constraint<'a>(
&mut self,
name: &'a str
) -> Result<(), NoSuchConstraint<'a>>
[src]
&mut self,
name: &'a str
) -> Result<(), NoSuchConstraint<'a>>
Disables a specific constraint.
Trait Implementations
impl<T> Clone for Component<T>
[src]
impl<T> Clone for Component<T>
[src]fn clone(&self) -> Self
[src]
pub fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl<T> ComponentSpec for Component<T>
[src]
impl<T> ComponentSpec for Component<T>
[src]type Value = Activation<T>
The variable type. It has more information than just the Value
.
type Constraint = Constraint<T>
The type of the constraints of the component.
fn new(
name: String,
values: Vec<impl Into<Self::Value>>,
constraints: Vec<Self::Constraint>
) -> Self
[src]
name: String,
values: Vec<impl Into<Self::Value>>,
constraints: Vec<Self::Constraint>
) -> Self
fn n_variables(&self) -> usize
[src]
fn constraints(&self) -> &[Self::Constraint]
[src]
fn constraints_mut(&mut self) -> &mut Vec<Self::Constraint>
[src]
fn add_constraint(&mut self, constraint: Self::Constraint)
[src]
fn pop_constraint(&mut self) -> Option<Self::Constraint>
[src]
fn remove_constraint(&mut self, idx: usize) -> Self::Constraint
[src]
fn ranking(&self) -> Vec<usize>
[src]
fn n_constraints(&self) -> usize
[src]
Auto Trait Implementations
impl<T> !RefUnwindSafe for Component<T>
impl<T> !RefUnwindSafe for Component<T>
impl<T> !UnwindSafe for Component<T>
impl<T> !UnwindSafe for Component<T>