Skip to main content

SharedOperatorTerminal

Struct SharedOperatorTerminal 

Source
pub struct SharedOperatorTerminal<S, O, A, Scorers, Sc> { /* private fields */ }
Expand description

Scoring terminal that owns one operator tree and scores it for several named constraints.

#[solverforge_constraints] appends terminals to one grouped node through penalize/reward and SharedOperatorBuilder::named. Every entity notification advances the operator once, then each scorer in Scorers re-scores the changed rows, so terminals share accumulator state but keep their own identity, weight and weight slot. A adapts each terminal’s weight to the operator’s rows.

Implementations§

Source§

impl<S, O, A, Scorers, Sc> SharedOperatorTerminal<S, O, A, Scorers, Sc>
where S: Send + Sync + 'static, O: GroupedOperator<S> + Send + Sync, Sc: Score,

Source

pub fn penalize<W>( self, weight: W, ) -> SharedOperatorBuilder<S, O, A, Scorers, W, Sc>

Starts another penalizing terminal over the same operator.

Source

pub fn reward<W>( self, weight: W, ) -> SharedOperatorBuilder<S, O, A, Scorers, W, Sc>

Starts another rewarding terminal over the same operator.

Source

pub fn evaluate(&self, solution: &S) -> Sc
where Scorers: OperatorScorerSet<S, O, Sc>,

Sums every scorer over the operator’s current rows, without retained state.

Source

pub fn initialize(&mut self, solution: &S) -> Sc
where Scorers: OperatorScorerSet<S, O, Sc>,

Initializes the operator from solution and returns the summed score of every scorer.

Source

pub fn on_retract( &mut self, solution: &S, index: usize, descriptor: usize, ) -> Sc
where Scorers: OperatorScorerSet<S, O, Sc>,

Retracts an entity from the operator and returns the summed score delta.

§Panics

Panics if the delta overflows.

Source

pub fn on_insert(&mut self, solution: &S, index: usize, descriptor: usize) -> Sc
where Scorers: OperatorScorerSet<S, O, Sc>,

Inserts an entity into the operator and returns the summed score delta.

§Panics

Panics if the delta overflows.

Source

pub fn update_count(&self) -> usize

Number of notifications that changed at least one operator row.

Source

pub fn changed_key_count(&self) -> usize

Number of group keys whose collector result a notification changed, summed over notifications.

Trait Implementations§

Source§

impl<S, O, A, Left, Right, Sc> ConstraintSet<S, Sc> for SharedOperatorTerminal<S, O, A, ScorerChain<(Left, Right)>, Sc>
where S: Send + Sync + 'static, O: GroupedOperator<S> + Send + Sync, A: Send + Sync, Left: OperatorScorerSet<S, O, Sc>, Right: OperatorScorerSet<S, O, Sc>, Sc: Score,

Source§

fn evaluate_all(&self, solution: &S) -> Sc

Evaluates all constraints and returns the total score.
Source§

fn constraint_count(&self) -> usize

Returns the number of constraints in this set.
Source§

fn constraint_metadata_entries(&self) -> Vec<ConstraintMetadata<'_>>

Returns one metadata entry per constraint in authored order, keeping duplicates. Read more
Source§

fn evaluate_each<'a>(&'a self, solution: &S) -> Vec<ConstraintResult<'a, Sc>>

Evaluates each constraint individually and returns per-constraint results. Read more
Source§

fn evaluate_detailed<'a>( &'a self, solution: &S, ) -> Vec<ConstraintAnalysis<'a, Sc>>

Evaluates each constraint with detailed match information. Read more
Source§

fn initialize_all(&mut self, solution: &S) -> Sc

Initializes all constraints by inserting all entities. Read more
Source§

fn on_insert_all(&mut self, solution: &S, index: usize, descriptor: usize) -> Sc

Called when an entity is inserted. Read more
Source§

fn on_retract_all( &mut self, solution: &S, index: usize, descriptor: usize, ) -> Sc

Called when an entity is retracted. Read more
Source§

fn reset_all(&mut self)

Resets all constraints for a new solving session.
Source§

fn constraint_weight_refs<'a>(&'a self, refs: &mut Vec<&'a ConstraintRef>)

Runtime constraint weights. Read more
Source§

fn evaluate_all_weighted(&self, solution: &S, multipliers: &[u32]) -> Sc

Weighted evaluate_all: multipliers holds one multiplier per weight slot.
Source§

fn evaluate_each_weighted<'a>( &'a self, solution: &S, multipliers: &[u32], ) -> Vec<ConstraintResult<'a, Sc>>

Weighted evaluate_each: weighted scores, with each result’s weight_multiplier set from its slot.
Source§

fn evaluate_detailed_weighted<'a>( &'a self, solution: &S, multipliers: &[u32], ) -> Vec<ConstraintAnalysis<'a, Sc>>

Weighted evaluate_detailed: weighted totals and match scores, with each analysis’s weight_multiplier set from its slot.
Source§

fn initialize_all_weighted(&mut self, solution: &S, multipliers: &[u32]) -> Sc

Weighted initialize_all.
Source§

fn on_insert_all_weighted( &mut self, solution: &S, index: usize, descriptor: usize, multipliers: &[u32], ) -> Sc

Weighted on_insert_all.
Source§

fn on_retract_all_weighted( &mut self, solution: &S, index: usize, descriptor: usize, multipliers: &[u32], ) -> Sc

Weighted on_retract_all.
Source§

fn constraint_metadata(&self) -> Vec<ConstraintMetadata<'_>>

Returns deduplicated immutable metadata for constraints in this set.
Source§

impl<S, O, A, W, Sc> IncrementalConstraint<S, Sc> for SharedOperatorTerminal<S, O, A, OperatorScorer<W, Sc>, Sc>
where S: Send + Sync + 'static, O: GroupedOperator<S> + Send + Sync, A: Send + Sync, W: RowWeight<S, O, Sc>, Sc: Score,

Source§

fn evaluate(&self, solution: &S) -> Sc

Computes this constraint’s whole score from scratch, without reading or changing retained state.
Source§

fn match_count(&self, solution: &S) -> usize

Returns the number of matches for this constraint in solution.
Source§

fn initialize(&mut self, solution: &S) -> Sc

Builds retained state from solution and returns the constraint’s whole score, equal to evaluate.
Source§

fn on_insert(&mut self, solution: &S, index: usize, descriptor: usize) -> Sc

Called after entity entity_index of entity class descriptor_index changed; returns the score its matches now add.
Source§

fn on_retract(&mut self, solution: &S, index: usize, descriptor: usize) -> Sc

Called before entity entity_index of entity class descriptor_index changes; returns the negation of the score its matches currently contribute.
Source§

fn reset(&mut self)

Drops all retained state. initialize runs again before the next notification.
Source§

fn constraint_ref(&self) -> &ConstraintRef

Returns the constraint’s reference (package and name), the same for its whole life.
Source§

fn is_hard(&self) -> bool

Returns whether this is a hard constraint. Every constraint sharing this constraint’s full reference must agree.
Source§

fn get_matches<'a>( &'a self, solution: &S, ) -> Vec<DetailedConstraintMatch<'a, Sc>>

Returns each match with the entities that justify it, for score explanation. The default returns no matches.
Source§

fn name(&self) -> &str

Returns the constraint’s name.
Source§

fn evaluate_weighted(&self, solution: &S, multiplier: u32) -> Sc

Weighted counterparts of the scoring methods. Read more
Source§

fn initialize_weighted(&mut self, solution: &S, multiplier: u32) -> Sc

Weighted initialize: the initial score scaled by multiplier.
Source§

fn on_insert_weighted( &mut self, solution: &S, entity_index: usize, descriptor_index: usize, multiplier: u32, ) -> Sc

Weighted on_insert: the insert delta scaled by multiplier.
Source§

fn on_retract_weighted( &mut self, solution: &S, entity_index: usize, descriptor_index: usize, multiplier: u32, ) -> Sc

Weighted on_retract: the retract delta scaled by multiplier.
Source§

fn get_matches_weighted<'a>( &'a self, solution: &S, multiplier: u32, ) -> Vec<DetailedConstraintMatch<'a, Sc>>

Weighted get_matches: every match score scaled by multiplier.
Source§

impl<S, O, A, W, Sc> SingleConstraint for SharedOperatorTerminal<S, O, A, OperatorScorer<W, Sc>, Sc>

Auto Trait Implementations§

§

impl<S, O, A, Scorers, Sc> Forget for SharedOperatorTerminal<S, O, A, Scorers, Sc>

§

impl<S, O, A, Scorers, Sc> Freeze for SharedOperatorTerminal<S, O, A, Scorers, Sc>
where O: Freeze, A: Freeze, Scorers: Freeze, Option<fn(&O, &S, RowHandle, &mut Vec<EntityRef>)>: Freeze, PhantomData<fn() -> (S, Sc)>: Freeze,

§

impl<S, O, A, Scorers, Sc> Move for SharedOperatorTerminal<S, O, A, Scorers, Sc>

§

impl<S, O, A, Scorers, Sc> RefUnwindSafe for SharedOperatorTerminal<S, O, A, Scorers, Sc>

§

impl<S, O, A, Scorers, Sc> Send for SharedOperatorTerminal<S, O, A, Scorers, Sc>
where O: Send, A: Send, Scorers: Send, Option<fn(&O, &S, RowHandle, &mut Vec<EntityRef>)>: Send, PhantomData<fn() -> (S, Sc)>: Send,

§

impl<S, O, A, Scorers, Sc> Sync for SharedOperatorTerminal<S, O, A, Scorers, Sc>
where O: Sync, A: Sync, Scorers: Sync, Option<fn(&O, &S, RowHandle, &mut Vec<EntityRef>)>: Sync, PhantomData<fn() -> (S, Sc)>: Sync,

§

impl<S, O, A, Scorers, Sc> Unpin for SharedOperatorTerminal<S, O, A, Scorers, Sc>
where O: Unpin, A: Unpin, Scorers: Unpin, Option<fn(&O, &S, RowHandle, &mut Vec<EntityRef>)>: Unpin, PhantomData<fn() -> (S, Sc)>: Unpin,

§

impl<S, O, A, Scorers, Sc> UnsafeUnpin for SharedOperatorTerminal<S, O, A, Scorers, Sc>
where O: UnsafeUnpin, A: UnsafeUnpin, Scorers: UnsafeUnpin, Option<fn(&O, &S, RowHandle, &mut Vec<EntityRef>)>: UnsafeUnpin, PhantomData<fn() -> (S, Sc)>: UnsafeUnpin,

§

impl<S, O, A, Scorers, Sc> UnwindSafe for SharedOperatorTerminal<S, O, A, Scorers, Sc>
where O: UnwindSafe, A: UnwindSafe, Scorers: UnwindSafe, Option<fn(&O, &S, RowHandle, &mut Vec<EntityRef>)>: UnwindSafe, PhantomData<fn() -> (S, Sc)>: UnwindSafe,

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<S, Sc, C> ConstraintSet<S, Sc> for C
where S: Send + Sync, Sc: Score, C: IncrementalConstraint<S, Sc>,

Source§

fn evaluate_all(&self, solution: &S) -> Sc

Evaluates all constraints and returns the total score.
Source§

fn constraint_count(&self) -> usize

Returns the number of constraints in this set.
Source§

fn constraint_metadata_entries(&self) -> Vec<ConstraintMetadata<'_>>

Returns one metadata entry per constraint in authored order, keeping duplicates. Read more
Source§

fn evaluate_each<'a>(&'a self, solution: &S) -> Vec<ConstraintResult<'a, Sc>>

Evaluates each constraint individually and returns per-constraint results. Read more
Source§

fn evaluate_detailed<'a>( &'a self, solution: &S, ) -> Vec<ConstraintAnalysis<'a, Sc>>

Evaluates each constraint with detailed match information. Read more
Source§

fn initialize_all(&mut self, solution: &S) -> Sc

Initializes all constraints by inserting all entities. Read more
Source§

fn on_insert_all( &mut self, solution: &S, entity_index: usize, descriptor_index: usize, ) -> Sc

Called when an entity is inserted. Read more
Source§

fn on_retract_all( &mut self, solution: &S, entity_index: usize, descriptor_index: usize, ) -> Sc

Called when an entity is retracted. Read more
Source§

fn on_insert_all_overflowing( &mut self, solution: &S, entity_index: usize, descriptor_index: usize, ) -> (Sc, bool)

Source§

fn on_retract_all_overflowing( &mut self, solution: &S, entity_index: usize, descriptor_index: usize, ) -> (Sc, bool)

Source§

fn reset_all(&mut self)

Resets all constraints for a new solving session.
Source§

fn constraint_weight_refs<'a>(&'a self, refs: &mut Vec<&'a ConstraintRef>)

Runtime constraint weights. Read more
Source§

fn evaluate_all_weighted(&self, solution: &S, multipliers: &[u32]) -> Sc

Weighted evaluate_all: multipliers holds one multiplier per weight slot.
Source§

fn evaluate_each_weighted<'a>( &'a self, solution: &S, multipliers: &[u32], ) -> Vec<ConstraintResult<'a, Sc>>

Weighted evaluate_each: weighted scores, with each result’s weight_multiplier set from its slot.
Source§

fn evaluate_detailed_weighted<'a>( &'a self, solution: &S, multipliers: &[u32], ) -> Vec<ConstraintAnalysis<'a, Sc>>

Weighted evaluate_detailed: weighted totals and match scores, with each analysis’s weight_multiplier set from its slot.
Source§

fn initialize_all_weighted(&mut self, solution: &S, multipliers: &[u32]) -> Sc

Weighted initialize_all.
Source§

fn on_insert_all_weighted( &mut self, solution: &S, entity_index: usize, descriptor_index: usize, multipliers: &[u32], ) -> Sc

Weighted on_insert_all.
Source§

fn on_retract_all_weighted( &mut self, solution: &S, entity_index: usize, descriptor_index: usize, multipliers: &[u32], ) -> Sc

Weighted on_retract_all.
Source§

fn on_insert_all_weighted_overflowing( &mut self, solution: &S, entity_index: usize, descriptor_index: usize, multipliers: &[u32], ) -> (Sc, bool)

Source§

fn on_retract_all_weighted_overflowing( &mut self, solution: &S, entity_index: usize, descriptor_index: usize, multipliers: &[u32], ) -> (Sc, bool)

Source§

fn constraint_metadata(&self) -> Vec<ConstraintMetadata<'_>>

Returns deduplicated immutable metadata for constraints in this set.
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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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.