pub trait Score:
Clone
+ Debug
+ Default
+ Send
+ Sync
+ PartialEq
+ Eq
+ PartialOrd
+ Ord
+ Add<Output = Self>
+ Sub<Output = Self>
+ Neg<Output = Self>
+ 'static {
// Required methods
fn is_feasible(&self) -> bool;
fn zero() -> Self;
fn levels_count() -> usize;
fn to_level_numbers(&self) -> Vec<i64>;
fn from_level_numbers(levels: &[i64]) -> Self;
fn multiply(&self, multiplicand: f64) -> Self;
fn divide(&self, divisor: f64) -> Self;
fn abs(&self) -> Self;
// Provided methods
fn compare(&self, other: &Self) -> Ordering { ... }
fn is_better_than(&self, other: &Self) -> bool { ... }
fn is_worse_than(&self, other: &Self) -> bool { ... }
fn is_equal_to(&self, other: &Self) -> bool { ... }
}Expand description
Core trait for all score types in SolverForge.
Scores represent the quality of a planning solution. They are used to:
- Compare solutions (better/worse/equal)
- Guide the optimization process
- Determine feasibility
All score implementations must be:
- Immutable (operations return new instances)
- Thread-safe (Send + Sync)
- Comparable (total ordering)
§Score Levels
Scores can have multiple levels (e.g., hard/soft constraints):
- Hard constraints: Must be satisfied for a solution to be feasible
- Soft constraints: Optimization objectives to maximize/minimize
When comparing scores, higher-priority levels are compared first.
Required Methods§
Sourcefn is_feasible(&self) -> bool
fn is_feasible(&self) -> bool
Returns true if this score represents a feasible solution.
A solution is feasible when all hard constraints are satisfied (i.e., the hard score is >= 0).
Sourcefn levels_count() -> usize
fn levels_count() -> usize
Returns the number of score levels.
For example:
- SimpleScore: 1 level
- HardSoftScore: 2 levels
- HardMediumSoftScore: 3 levels
Sourcefn to_level_numbers(&self) -> Vec<i64>
fn to_level_numbers(&self) -> Vec<i64>
Returns the score values as a vector of i64.
The order is from highest priority to lowest priority. For HardSoftScore: [hard, soft]
Sourcefn from_level_numbers(levels: &[i64]) -> Self
fn from_level_numbers(levels: &[i64]) -> Self
Creates a score from level numbers.
§Panics
Panics if the number of levels doesn’t match levels_count().
Provided Methods§
Sourcefn compare(&self, other: &Self) -> Ordering
fn compare(&self, other: &Self) -> Ordering
Compares two scores, returning the ordering.
Default implementation uses the Ord trait.
Sourcefn is_better_than(&self, other: &Self) -> bool
fn is_better_than(&self, other: &Self) -> bool
Returns true if this score is better than the other score.
In optimization, “better” typically means higher score.
Sourcefn is_worse_than(&self, other: &Self) -> bool
fn is_worse_than(&self, other: &Self) -> bool
Returns true if this score is worse than the other score.
Sourcefn is_equal_to(&self, other: &Self) -> bool
fn is_equal_to(&self, other: &Self) -> bool
Returns true if this score is equal to the other score.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.