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 of(hard: i64, soft: i64) -> HardSoftScore
pub const fn of(hard: i64, soft: i64) -> HardSoftScore
Creates a new HardSoftScore.
Sourcepub const fn of_hard(hard: i64) -> HardSoftScore
pub const fn of_hard(hard: i64) -> HardSoftScore
Creates a score with only a hard component.
Sourcepub const fn of_soft(soft: i64) -> HardSoftScore
pub const fn of_soft(soft: i64) -> HardSoftScore
Creates a score with only a soft component.
Sourcepub const fn hard_score(&self) -> HardSoftScore
pub const fn hard_score(&self) -> HardSoftScore
Returns the hard score as a new HardSoftScore.
Sourcepub const fn soft_score(&self) -> HardSoftScore
pub const fn soft_score(&self) -> HardSoftScore
Returns the soft score as a new HardSoftScore.
Trait Implementations§
Source§impl Add for HardSoftScore
impl Add for HardSoftScore
Source§type Output = HardSoftScore
type Output = HardSoftScore
The resulting type after applying the
+ operator.Source§fn add(self, other: HardSoftScore) -> HardSoftScore
fn add(self, other: HardSoftScore) -> HardSoftScore
Performs the
+ operation. Read moreSource§impl Clone for HardSoftScore
impl Clone for HardSoftScore
Source§fn clone(&self) -> HardSoftScore
fn clone(&self) -> HardSoftScore
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for HardSoftScore
impl Debug for HardSoftScore
Source§impl Default for HardSoftScore
impl Default for HardSoftScore
Source§fn default() -> HardSoftScore
fn default() -> HardSoftScore
Returns the “default value” for a type. Read more
Source§impl Display for HardSoftScore
impl Display for HardSoftScore
Source§impl Hash for HardSoftScore
impl Hash for HardSoftScore
Source§impl Neg for HardSoftScore
impl Neg for HardSoftScore
Source§type Output = HardSoftScore
type Output = HardSoftScore
The resulting type after applying the
- operator.Source§fn neg(self) -> HardSoftScore
fn neg(self) -> HardSoftScore
Performs the unary
- operation. Read moreSource§impl Ord for HardSoftScore
impl Ord for HardSoftScore
Source§fn cmp(&self, other: &HardSoftScore) -> Ordering
fn cmp(&self, other: &HardSoftScore) -> Ordering
1.21.0 · 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
Source§impl ParseableScore for HardSoftScore
impl ParseableScore for HardSoftScore
Source§fn parse(s: &str) -> Result<HardSoftScore, ScoreParseError>
fn parse(s: &str) -> Result<HardSoftScore, ScoreParseError>
Parses a score from a string representation. Read more
Source§fn to_string_repr(&self) -> String
fn to_string_repr(&self) -> String
Returns the string representation of this score.
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 zero() -> HardSoftScore
fn zero() -> HardSoftScore
Returns the zero score (identity element for addition).
Source§fn levels_count() -> usize
fn levels_count() -> usize
Returns the number of score levels. Read more
Source§fn from_level_numbers(levels: &[i64]) -> HardSoftScore
fn from_level_numbers(levels: &[i64]) -> HardSoftScore
Creates a score from level numbers. Read more
Source§fn multiply(&self, multiplicand: f64) -> HardSoftScore
fn multiply(&self, multiplicand: f64) -> HardSoftScore
Multiplies this score by a scalar.
Source§fn divide(&self, divisor: f64) -> HardSoftScore
fn divide(&self, divisor: f64) -> HardSoftScore
Divides this score by a scalar.
Source§fn abs(&self) -> HardSoftScore
fn abs(&self) -> HardSoftScore
Returns the absolute value of this score.
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§impl Sub for HardSoftScore
impl Sub for HardSoftScore
Source§type Output = HardSoftScore
type Output = HardSoftScore
The resulting type after applying the
- operator.Source§fn sub(self, other: HardSoftScore) -> HardSoftScore
fn sub(self, other: HardSoftScore) -> HardSoftScore
Performs the
- operation. Read moreimpl Copy for HardSoftScore
impl Eq for HardSoftScore
impl StructuralPartialEq for HardSoftScore
Auto Trait Implementations§
impl Freeze 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
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
Compare self to
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>
Converts
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>
Converts
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