pub trait ValueRangeProvider<S, V>: Send + Sync {
// Required method
fn get_values(&self, solution: &S) -> Vec<V>;
// Provided methods
fn value_count(&self, solution: &S) -> usize { ... }
fn is_empty(&self, solution: &S) -> bool { ... }
}Expand description
Provides values for a planning variable.
This trait is implemented for types that can produce a list of valid values for a planning variable. The values can be static or computed dynamically based on the solution state.
§Type Parameters
S- The solution typeV- The value type (must match the planning variable’s type)
§Example
use solverforge_core::domain::ValueRangeProvider;
// Define a solution with a size field
struct NQueensSolution {
n: i32,
}
// Implement a value range provider that computes row values
struct RowRangeProvider;
impl ValueRangeProvider<NQueensSolution, i32> for RowRangeProvider {
fn get_values(&self, solution: &NQueensSolution) -> Vec<i32> {
(0..solution.n).collect()
}
}
let solution = NQueensSolution { n: 8 };
let provider = RowRangeProvider;
assert_eq!(provider.get_values(&solution), vec![0, 1, 2, 3, 4, 5, 6, 7]);
assert_eq!(provider.value_count(&solution), 8);Required Methods§
Sourcefn get_values(&self, solution: &S) -> Vec<V>
fn get_values(&self, solution: &S) -> Vec<V>
Returns all possible values for the variable.
This method is called during move generation to determine which values can be assigned to a planning variable.
Provided Methods§
Sourcefn value_count(&self, solution: &S) -> usize
fn value_count(&self, solution: &S) -> usize
Returns the number of possible values.
The default implementation calls get_values and returns the length,
but implementations may override this for efficiency if the count
can be computed without materializing the values.