pub struct HardSoftScore { /* private fields */ }Expand description
A score with separate hard and soft constraint levels.
Hard constraints must be satisfied for a solution to be feasible. Soft constraints are optimization objectives.
When comparing scores:
- Hard scores are compared first
- Soft scores are only compared when hard scores are equal
§Examples
use solverforge_core::HardSoftScore;
let score1 = HardSoftScore::of(-1, -100); // 1 hard constraint broken
let score2 = HardSoftScore::of(0, -200); // Feasible but poor soft score
// Feasible solutions are always better than infeasible ones
assert!(score2 > score1);
let score3 = HardSoftScore::of(0, -50); // Better soft score
assert!(score3 > score2);Implementations§
Source§impl HardSoftScore
impl HardSoftScore
Sourcepub const ZERO: HardSoftScore
pub const ZERO: HardSoftScore
The zero score.
Sourcepub const ONE_HARD: HardSoftScore
pub const ONE_HARD: HardSoftScore
One hard constraint penalty.
Sourcepub const ONE_SOFT: HardSoftScore
pub const ONE_SOFT: HardSoftScore
One soft constraint penalty.
Sourcepub const fn hard_score(&self) -> HardSoftScore
pub const fn hard_score(&self) -> HardSoftScore
Returns this score with the soft level zeroed.
Sourcepub const fn soft_score(&self) -> HardSoftScore
pub const fn soft_score(&self) -> HardSoftScore
Returns this score with the hard level zeroed.
Trait Implementations§
Source§impl Add for HardSoftScore
impl Add for HardSoftScore
Source§impl Clone for HardSoftScore
impl Clone for HardSoftScore
impl Copy for HardSoftScore
Source§impl Debug for HardSoftScore
impl Debug for HardSoftScore
Source§impl Default for HardSoftScore
impl Default for HardSoftScore
Source§impl Display for HardSoftScore
impl Display for HardSoftScore
impl Eq for HardSoftScore
Source§impl Hash for HardSoftScore
impl Hash for HardSoftScore
Source§impl Neg for HardSoftScore
impl Neg for HardSoftScore
Source§impl Ord for HardSoftScore
impl Ord for HardSoftScore
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§fn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the minimum of two values. Read more
Source§impl ParseableScore for HardSoftScore
impl ParseableScore for HardSoftScore
Source§impl PartialEq for HardSoftScore
impl PartialEq for HardSoftScore
Source§impl PartialOrd for HardSoftScore
impl PartialOrd for HardSoftScore
Source§impl Score for HardSoftScore
impl Score for HardSoftScore
Source§fn is_feasible(&self) -> bool
fn is_feasible(&self) -> bool
Returns true if this score represents a feasible solution. Read more
Source§fn levels_count() -> usize
fn levels_count() -> usize
Returns the number of score levels. Read more
Source§fn level_number(&self, index: usize) -> i64
fn level_number(&self, index: usize) -> i64
Returns the score value at a priority level. Read more
Source§fn from_level_numbers(levels: &[i64]) -> Self
fn from_level_numbers(levels: &[i64]) -> Self
Creates a score from level numbers. Read more
Source§fn multiply(&self, multiplicand: f64) -> Self
fn multiply(&self, multiplicand: f64) -> Self
Multiplies every level by a scalar, rounding to the nearest integer. Read more
Source§fn overflowing_multiply(&self, multiplicand: f64) -> (Self, bool)
fn overflowing_multiply(&self, multiplicand: f64) -> (Self, bool)
multiply without panicking: the flag is set for a non-finite
multiplicand or a rounded level outside i64; see overflowing_add.Source§fn divide(&self, divisor: f64) -> Self
fn divide(&self, divisor: f64) -> Self
Divides every level by a scalar, rounding to the nearest integer. Read more
Source§fn scale(&self, factor: i64) -> Self
fn scale(&self, factor: i64) -> Self
Multiplies every level by an exact integer factor. Read more
Source§fn overflowing_scale(&self, factor: i64) -> (Self, bool)
fn overflowing_scale(&self, factor: i64) -> (Self, bool)
scale without panicking: the flag is set when a level overflowed;
see overflowing_add.Source§fn overflowing_add(self, other: Self) -> (Self, bool)
fn overflowing_add(self, other: Self) -> (Self, bool)
Adds
other without panicking, returning the sum and whether any level
overflowed i64 (the levels are then wrapped and meaningless). Read moreSource§fn overflowing_sub(self, other: Self) -> (Self, bool)
fn overflowing_sub(self, other: Self) -> (Self, bool)
Subtracts
other without panicking; see overflowing_add.Source§fn overflowing_neg(self) -> (Self, bool)
fn overflowing_neg(self) -> (Self, bool)
Negates without panicking; see
overflowing_add.Source§fn level_label(index: usize) -> ScoreLevel
fn level_label(index: usize) -> ScoreLevel
Returns the semantic label for the score level at the given index. Read more
Source§fn compare(&self, other: &Self) -> Ordering
fn compare(&self, other: &Self) -> Ordering
Compares two scores, returning the ordering. Read more
Source§fn 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. Read more
Source§fn 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.
Source§fn 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.
Source§fn one_medium() -> Self
fn one_medium() -> Self
Returns a score with 1 at the first Medium-labeled level and 0 elsewhere.
impl StructuralPartialEq for HardSoftScore
Auto Trait Implementations§
impl Forget for HardSoftScore
impl Freeze for HardSoftScore
impl Move for HardSoftScore
impl RefUnwindSafe for HardSoftScore
impl Send for HardSoftScore
impl Sync for HardSoftScore
impl Unpin for HardSoftScore
impl UnsafeUnpin for HardSoftScore
impl UnwindSafe for HardSoftScore
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more