@@ -4,8 +4,6 @@ use std::cmp::Ordering;
44use std:: fmt:: { Debug , Display } ;
55use std:: ops:: { Add , Neg , Sub } ;
66
7- use super :: ScoreLevel ;
8-
97/// Core trait for all score types in SolverForge.
108///
119/// Scores represent the quality of a planning solution. They are used to:
@@ -79,14 +77,28 @@ pub trait Score:
7977 /// Returns the absolute value of this score.
8078 fn abs ( & self ) -> Self ;
8179
82- /// Returns the semantic label for the score level at the given index.
83- ///
84- /// Level indices follow the same order as `to_level_numbers()`:
85- /// highest priority first.
80+ /// Converts this score to a single scalar f64 for algorithms like
81+ /// Simulated Annealing that need a continuous representation.
8682 ///
87- /// # Panics
88- /// Panics if `index >= levels_count()`.
89- fn level_label ( index : usize ) -> ScoreLevel ;
83+ /// Higher-priority levels are weighted exponentially more (10^6 per level).
84+ /// Override for zero-allocation implementations on fixed-level score types.
85+ #[ inline]
86+ fn to_scalar ( & self ) -> f64 {
87+ let levels = self . to_level_numbers ( ) ;
88+ if levels. is_empty ( ) {
89+ return 0.0 ;
90+ }
91+ if levels. len ( ) == 1 {
92+ return levels[ 0 ] as f64 ;
93+ }
94+ let n = levels. len ( ) ;
95+ let mut scalar = 0.0f64 ;
96+ for ( i, & level) in levels. iter ( ) . enumerate ( ) {
97+ let weight = 10.0f64 . powi ( 6 * ( n - 1 - i) as i32 ) ;
98+ scalar += level as f64 * weight;
99+ }
100+ scalar
101+ }
90102
91103 /// Compares two scores, returning the ordering.
92104 ///
0 commit comments