pub struct SolverState {
pub assignments: Vec<f32>,
pub velocities: Vec<f32>,
pub gradients: Vec<f32>,
}Expand description
Internal state during CLS optimization.
Tracks the continuous variable assignments, momentum velocities, and computed gradients throughout the optimization process.
§Memory Layout
Each vector has length equal to the number of variables:
assignments: Current continuous values in [0,1]velocities: Momentum velocities (accumulated gradient history)gradients: Computed gradients for the current iteration
Fields§
§assignments: Vec<f32>Continuous variable assignments in [0,1].
Index i corresponds to variable i. Values close to 1.0 indicate the variable should be true, values close to 0.0 indicate false.
velocities: Vec<f32>Momentum velocities for each variable.
Accumulates gradient history to help escape local minima and smooth the optimization trajectory.
gradients: Vec<f32>Computed gradients for the current iteration.
The gradient of the unsatisfied clause penalty with respect to each variable. Negative gradients indicate the variable should increase to reduce unsatisfaction.
Implementations§
Source§impl SolverState
impl SolverState
Sourcepub fn new(num_vars: u32) -> Self
pub fn new(num_vars: u32) -> Self
Creates a new solver state for the given number of variables.
Variables are initialized with values near 0.5 using a deterministic pseudo-random pattern based on index to break symmetry while maintaining reproducibility.
§Arguments
num_vars- Number of variables in the SAT instance
§Example
use xlog_solve::SolverState;
let state = SolverState::new(10);
assert_eq!(state.assignments.len(), 10);
assert_eq!(state.velocities.len(), 10);
assert_eq!(state.gradients.len(), 10);Sourcepub fn with_assignments(assignments: Vec<f32>) -> Self
pub fn with_assignments(assignments: Vec<f32>) -> Self
Creates a solver state with specific initial assignments.
Useful for warm-starting from a known assignment or for testing.
§Arguments
assignments- Initial continuous assignments in [0,1]
Sourcepub fn discretize(&self, threshold: f32) -> Vec<bool>
pub fn discretize(&self, threshold: f32) -> Vec<bool>
Discretizes the continuous assignments to boolean values.
Values >= threshold become true, values < threshold become false.
§Arguments
threshold- The threshold for boolean conversion (typically 0.5)
§Returns
A vector of boolean values, one per variable.
§Example
use xlog_solve::SolverState;
let mut state = SolverState::new(3);
state.assignments = vec![0.3, 0.7, 0.5];
let discrete = state.discretize(0.5);
assert_eq!(discrete, vec![false, true, true]);Sourcepub fn reset_velocities(&mut self)
pub fn reset_velocities(&mut self)
Resets all velocities to zero.
Useful for restarting the optimization with a fresh momentum state.
Sourcepub fn clear_gradients(&mut self)
pub fn clear_gradients(&mut self)
Clears the gradients buffer.
Trait Implementations§
Source§impl Clone for SolverState
impl Clone for SolverState
Source§fn clone(&self) -> SolverState
fn clone(&self) -> SolverState
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more