ValueRangeProvider

Trait ValueRangeProvider 

Source
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 type
  • V - 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§

Source

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§

Source

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.

Source

fn is_empty(&self, solution: &S) -> bool

Returns whether the value range is empty.

Implementors§

Source§

impl<S> ValueRangeProvider<S, i32> for IntegerRange
where S: Send + Sync,

Source§

impl<S> ValueRangeProvider<S, i64> for IntegerRange
where S: Send + Sync,

Source§

impl<S, V> ValueRangeProvider<S, V> for StaticValueRange<V>
where S: Send + Sync, V: Clone + Send + Sync,

Source§

impl<S, V, F> ValueRangeProvider<S, V> for ComputedValueRangeProvider<S, V, F>
where S: Send + Sync, V: Send + Sync, F: Fn(&S) -> Vec<V> + Send + Sync,

Source§

impl<S, V, F> ValueRangeProvider<S, V> for FieldValueRangeProvider<S, V, F>
where S: Send + Sync, V: Clone + Send + Sync, F: Fn(&S) -> &Vec<V> + Send + Sync,