pub struct HardSoftDecimalScore { /* private fields */ }Expand description
A score with separate hard and soft constraint levels, using i64 with ×100000 scaling.
This provides 5 decimal places of precision (matching Timefold’s BigDecimal display) 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) -> Self
pub const fn of(hard: i64, soft: i64) -> Self
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) -> Self
pub const fn of_scaled(hard: i64, soft: i64) -> Self
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) -> Self
pub const fn of_hard(hard: i64) -> Self
Creates a score with only a hard component (unscaled input).
Sourcepub const fn of_soft(soft: i64) -> Self
pub const fn of_soft(soft: i64) -> Self
Creates a score with only a soft component (unscaled input).
Sourcepub const fn of_hard_scaled(hard: i64) -> Self
pub const fn of_hard_scaled(hard: i64) -> Self
Creates a score with only a hard component (pre-scaled input).
Sourcepub const fn of_soft_scaled(soft: i64) -> Self
pub const fn of_soft_scaled(soft: i64) -> Self
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§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 more