pub struct HardSoftDecimalScore { /* private fields */ }Expand description
A score with separate hard and soft constraint levels, using i64 with x100000 scaling.
This provides 5 decimal places of precision while maintaining zero heap allocation and full type safety.
Internal values are stored pre-scaled. Use of for unscaled input
or of_scaled for pre-scaled values.
§Examples
use solverforge_core::{HardSoftDecimalScore, Score};
// Create from unscaled values (automatically multiplied by 100000)
let score1 = HardSoftDecimalScore::of(-1, -100);
assert_eq!(score1.hard_scaled(), -100000);
assert_eq!(score1.soft_scaled(), -10000000);
// Create from pre-scaled values (for minute-based penalties)
let score2 = HardSoftDecimalScore::of_scaled(-3050000, 0); // -30.5 hard
assert!(!score2.is_feasible());
// Display shows values (trailing zeros stripped)
let score3 = HardSoftDecimalScore::of_scaled(-150000, -250000);
assert_eq!(format!("{}", score3), "-1.5hard/-2.5soft");Implementations§
Source§impl HardSoftDecimalScore
impl HardSoftDecimalScore
Sourcepub const ZERO: HardSoftDecimalScore
pub const ZERO: HardSoftDecimalScore
The zero score.
Sourcepub const ONE_HARD: HardSoftDecimalScore
pub const ONE_HARD: HardSoftDecimalScore
One hard constraint penalty (scaled).
Sourcepub const ONE_SOFT: HardSoftDecimalScore
pub const ONE_SOFT: HardSoftDecimalScore
One soft constraint penalty (scaled).
Sourcepub const fn of(hard: i64, soft: i64) -> HardSoftDecimalScore
pub const fn of(hard: i64, soft: i64) -> HardSoftDecimalScore
Creates a new score from unscaled values.
The values are automatically multiplied by 100000.
§Examples
use solverforge_core::HardSoftDecimalScore;
let score = HardSoftDecimalScore::of(-2, -100);
assert_eq!(score.hard_scaled(), -200000);
assert_eq!(score.soft_scaled(), -10000000);Sourcepub const fn of_scaled(hard: i64, soft: i64) -> HardSoftDecimalScore
pub const fn of_scaled(hard: i64, soft: i64) -> HardSoftDecimalScore
Creates a new score from pre-scaled values.
Use this for minute-based penalties where precision matters.
§Examples
use solverforge_core::HardSoftDecimalScore;
// -30.5 hard constraint (overlap of 30.5 minutes)
let score = HardSoftDecimalScore::of_scaled(-3050000, 0);
assert_eq!(score.hard_scaled(), -3050000);Sourcepub const fn of_hard(hard: i64) -> HardSoftDecimalScore
pub const fn of_hard(hard: i64) -> HardSoftDecimalScore
Creates a score with only a hard component (unscaled input).
Sourcepub const fn of_soft(soft: i64) -> HardSoftDecimalScore
pub const fn of_soft(soft: i64) -> HardSoftDecimalScore
Creates a score with only a soft component (unscaled input).
Sourcepub const fn of_hard_scaled(hard: i64) -> HardSoftDecimalScore
pub const fn of_hard_scaled(hard: i64) -> HardSoftDecimalScore
Creates a score with only a hard component (pre-scaled input).
Sourcepub const fn of_soft_scaled(soft: i64) -> HardSoftDecimalScore
pub const fn of_soft_scaled(soft: i64) -> HardSoftDecimalScore
Creates a score with only a soft component (pre-scaled input).
Sourcepub const fn hard_scaled(&self) -> i64
pub const fn hard_scaled(&self) -> i64
Returns the scaled hard score component.
Sourcepub const fn soft_scaled(&self) -> i64
pub const fn soft_scaled(&self) -> i64
Returns the scaled soft score component.
Sourcepub const fn hard_score(&self) -> HardSoftDecimalScore
pub const fn hard_score(&self) -> HardSoftDecimalScore
Returns the hard score as a new HardSoftDecimalScore.
Sourcepub const fn soft_score(&self) -> HardSoftDecimalScore
pub const fn soft_score(&self) -> HardSoftDecimalScore
Returns the soft score as a new HardSoftDecimalScore.
Sourcepub const fn has_hard_component(&self) -> bool
pub const fn has_hard_component(&self) -> bool
Returns true if this score has a non-zero hard component.
Used by constraint streams to determine if a weight represents a hard or soft constraint.
Trait Implementations§
Source§impl Add for HardSoftDecimalScore
impl Add for HardSoftDecimalScore
Source§type Output = HardSoftDecimalScore
type Output = HardSoftDecimalScore
+ operator.Source§fn add(self, other: HardSoftDecimalScore) -> HardSoftDecimalScore
fn add(self, other: HardSoftDecimalScore) -> HardSoftDecimalScore
+ operation. Read moreSource§impl Clone for HardSoftDecimalScore
impl Clone for HardSoftDecimalScore
Source§fn clone(&self) -> HardSoftDecimalScore
fn clone(&self) -> HardSoftDecimalScore
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for HardSoftDecimalScore
impl Debug for HardSoftDecimalScore
Source§impl Default for HardSoftDecimalScore
impl Default for HardSoftDecimalScore
Source§fn default() -> HardSoftDecimalScore
fn default() -> HardSoftDecimalScore
Source§impl Display for HardSoftDecimalScore
impl Display for HardSoftDecimalScore
Source§impl Hash for HardSoftDecimalScore
impl Hash for HardSoftDecimalScore
Source§impl Neg for HardSoftDecimalScore
impl Neg for HardSoftDecimalScore
Source§type Output = HardSoftDecimalScore
type Output = HardSoftDecimalScore
- operator.Source§fn neg(self) -> HardSoftDecimalScore
fn neg(self) -> HardSoftDecimalScore
- operation. Read moreSource§impl Ord for HardSoftDecimalScore
impl Ord for HardSoftDecimalScore
Source§fn cmp(&self, other: &HardSoftDecimalScore) -> Ordering
fn cmp(&self, other: &HardSoftDecimalScore) -> Ordering
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl ParseableScore for HardSoftDecimalScore
impl ParseableScore for HardSoftDecimalScore
Source§fn parse(s: &str) -> Result<HardSoftDecimalScore, ScoreParseError>
fn parse(s: &str) -> Result<HardSoftDecimalScore, ScoreParseError>
Source§fn to_string_repr(&self) -> String
fn to_string_repr(&self) -> String
Source§impl PartialEq for HardSoftDecimalScore
impl PartialEq for HardSoftDecimalScore
Source§impl PartialOrd for HardSoftDecimalScore
impl PartialOrd for HardSoftDecimalScore
Source§impl Score for HardSoftDecimalScore
impl Score for HardSoftDecimalScore
Source§fn is_feasible(&self) -> bool
fn is_feasible(&self) -> bool
Source§fn zero() -> HardSoftDecimalScore
fn zero() -> HardSoftDecimalScore
Source§fn levels_count() -> usize
fn levels_count() -> usize
Source§fn from_level_numbers(levels: &[i64]) -> HardSoftDecimalScore
fn from_level_numbers(levels: &[i64]) -> HardSoftDecimalScore
Source§fn multiply(&self, multiplicand: f64) -> HardSoftDecimalScore
fn multiply(&self, multiplicand: f64) -> HardSoftDecimalScore
Source§fn divide(&self, divisor: f64) -> HardSoftDecimalScore
fn divide(&self, divisor: f64) -> HardSoftDecimalScore
Source§fn abs(&self) -> HardSoftDecimalScore
fn abs(&self) -> HardSoftDecimalScore
Source§fn level_label(index: usize) -> ScoreLevel
fn level_label(index: usize) -> ScoreLevel
Source§fn compare(&self, other: &Self) -> Ordering
fn compare(&self, other: &Self) -> Ordering
Source§fn is_better_than(&self, other: &Self) -> bool
fn is_better_than(&self, other: &Self) -> bool
Source§fn is_worse_than(&self, other: &Self) -> bool
fn is_worse_than(&self, other: &Self) -> bool
Source§fn is_equal_to(&self, other: &Self) -> bool
fn is_equal_to(&self, other: &Self) -> bool
Source§impl Sub for HardSoftDecimalScore
impl Sub for HardSoftDecimalScore
Source§type Output = HardSoftDecimalScore
type Output = HardSoftDecimalScore
- operator.Source§fn sub(self, other: HardSoftDecimalScore) -> HardSoftDecimalScore
fn sub(self, other: HardSoftDecimalScore) -> HardSoftDecimalScore
- operation. Read moreimpl Copy for HardSoftDecimalScore
impl Eq for HardSoftDecimalScore
impl StructuralPartialEq for HardSoftDecimalScore
Auto Trait Implementations§
impl Freeze for HardSoftDecimalScore
impl RefUnwindSafe for HardSoftDecimalScore
impl Send for HardSoftDecimalScore
impl Sync for HardSoftDecimalScore
impl Unpin for HardSoftDecimalScore
impl UnsafeUnpin for HardSoftDecimalScore
impl UnwindSafe for HardSoftDecimalScore
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more