pub struct ObjectiveRegistry<T: Send + Sync> { /* private fields */ }Expand description
Registry of named objectives.
Thread-safe: all operations are behind a single RwLock.
Implementations§
Source§impl<T: Send + Sync> ObjectiveRegistry<T>
impl<T: Send + Sync> ObjectiveRegistry<T>
Sourcepub fn register(
&self,
name: impl Into<String>,
objective: Box<dyn Objective<T>>,
) -> Option<Arc<RegisteredObjective<T>>>
pub fn register( &self, name: impl Into<String>, objective: Box<dyn Objective<T>>, ) -> Option<Arc<RegisteredObjective<T>>>
Register a named objective; returns the previous entry if the name was already taken.
Sourcepub fn register_with_desc(
&self,
name: impl Into<String>,
description: impl Into<String>,
objective: Box<dyn Objective<T>>,
) -> Option<Arc<RegisteredObjective<T>>>
pub fn register_with_desc( &self, name: impl Into<String>, description: impl Into<String>, objective: Box<dyn Objective<T>>, ) -> Option<Arc<RegisteredObjective<T>>>
Register a named objective with a human-readable description.
Sourcepub fn set_default(&self, name: impl Into<String>) -> ObjectiveResult<()>
pub fn set_default(&self, name: impl Into<String>) -> ObjectiveResult<()>
Set the named objective as the registry default.
Returns ObjectiveError::NotFound when no objective with that name is registered.
Sourcepub fn get(&self, name: &str) -> ObjectiveResult<Arc<RegisteredObjective<T>>>
pub fn get(&self, name: &str) -> ObjectiveResult<Arc<RegisteredObjective<T>>>
Retrieve a registered objective by name.
Returns ObjectiveError::NotFound when the name is not registered.
Sourcepub fn get_default(&self) -> ObjectiveResult<Arc<RegisteredObjective<T>>>
pub fn get_default(&self) -> ObjectiveResult<Arc<RegisteredObjective<T>>>
Retrieve the current default objective.
Returns ObjectiveError::NotFound when no default has been set.
Sourcepub fn contains(&self, name: &str) -> bool
pub fn contains(&self, name: &str) -> bool
Return true if an objective with the given name is registered.
Sourcepub fn score(
&self,
name: &str,
candidate: &T,
context: &ObjectiveContext,
) -> ObjectiveResult<f64>
pub fn score( &self, name: &str, candidate: &T, context: &ObjectiveContext, ) -> ObjectiveResult<f64>
Raw score via a named objective (no precision weighting).
Sourcepub fn select<'a>(
&self,
name: &str,
candidates: &'a [T],
context: &ObjectiveContext,
) -> ObjectiveResult<Selection<&'a T>>
pub fn select<'a>( &self, name: &str, candidates: &'a [T], context: &ObjectiveContext, ) -> ObjectiveResult<Selection<&'a T>>
Select the best candidate using the named objective.
Returns ObjectiveError::NoMatch when the candidate slice is empty.
Sourcepub fn select_default<'a>(
&self,
candidates: &'a [T],
context: &ObjectiveContext,
) -> ObjectiveResult<Selection<&'a T>>
pub fn select_default<'a>( &self, candidates: &'a [T], context: &ObjectiveContext, ) -> ObjectiveResult<Selection<&'a T>>
Select the best candidate using the current default objective.
Returns ObjectiveError::NotFound when no default is set.