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) -> 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 hard-only score from an unscaled value.
use solverforge_core::HardSoftDecimalScore;
const LIMIT: HardSoftDecimalScore = HardSoftDecimalScore::of_hard(-1_000_000_000);
assert_eq!(LIMIT.hard_scaled(), -100_000_000_000_000);§Panics
Panics when hard * 100_000 overflows i64; in a const context the
overflow is a compile error:
use solverforge_core::HardSoftDecimalScore;
const LIMIT: HardSoftDecimalScore = HardSoftDecimalScore::of_hard(-100_000_000_000_000);
assert!(LIMIT.hard_scaled() < 0);Sourcepub fn parse_level(text: &str) -> Result<i64, ScoreParseError>
pub fn parse_level(text: &str) -> Result<i64, ScoreParseError>
Parses one level written in decimal units (-12, 3.25, at most five
fractional digits) into its scaled value, with the same rules as
ParseableScore::parse.
use solverforge_core::HardSoftDecimalScore;
assert_eq!(HardSoftDecimalScore::parse_level("-1.5").unwrap(), -150_000);
assert!(HardSoftDecimalScore::parse_level("NaN").is_err());Sourcepub const fn of_hard_scaled(hard: i64) -> Self
pub const fn of_hard_scaled(hard: i64) -> Self
Creates a hard-only score from a pre-scaled value (100_000 is one hard unit).
Sourcepub const fn of_soft_scaled(soft: i64) -> Self
pub const fn of_soft_scaled(soft: i64) -> Self
Creates a soft-only score from a pre-scaled value (100_000 is one soft unit).
Sourcepub const fn hard_scaled(&self) -> i64
pub const fn hard_scaled(&self) -> i64
Returns the hard level scaled by 100_000.
Sourcepub const fn soft_scaled(&self) -> i64
pub const fn soft_scaled(&self) -> i64
Returns the soft level scaled by 100_000.
Sourcepub const fn hard_score(&self) -> HardSoftDecimalScore
pub const fn hard_score(&self) -> HardSoftDecimalScore
Returns this score with the soft level zeroed.
Sourcepub const fn soft_score(&self) -> HardSoftDecimalScore
pub const fn soft_score(&self) -> HardSoftDecimalScore
Returns this score with the hard level zeroed.
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
impl Copy for HardSoftDecimalScore
Source§impl Debug for HardSoftDecimalScore
impl Debug for HardSoftDecimalScore
Source§impl Default for HardSoftDecimalScore
impl Default for HardSoftDecimalScore
Source§impl Display for HardSoftDecimalScore
impl Display for HardSoftDecimalScore
impl Eq for HardSoftDecimalScore
Source§impl Hash for HardSoftDecimalScore
impl Hash for HardSoftDecimalScore
Source§impl Neg for HardSoftDecimalScore
impl Neg for HardSoftDecimalScore
Source§impl Ord for HardSoftDecimalScore
impl Ord for HardSoftDecimalScore
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
1.21.0 (const: unstable) · Source§fn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
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 levels_count() -> usize
fn levels_count() -> usize
Source§fn level_number(&self, index: usize) -> i64
fn level_number(&self, index: usize) -> i64
Source§fn from_level_numbers(levels: &[i64]) -> Self
fn from_level_numbers(levels: &[i64]) -> Self
Source§fn multiply(&self, multiplicand: f64) -> Self
fn multiply(&self, multiplicand: f64) -> Self
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
Source§fn scale(&self, factor: i64) -> Self
fn scale(&self, factor: i64) -> Self
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)
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)
other without panicking; see overflowing_add.Source§fn overflowing_neg(self) -> (Self, bool)
fn overflowing_neg(self) -> (Self, bool)
overflowing_add.