Skip to main content

SolverState

Struct SolverState 

Source
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

Source

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);
Source

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]
Source

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]);
Source

pub fn num_vars(&self) -> usize

Returns the number of variables in this state.

Source

pub fn reset_velocities(&mut self)

Resets all velocities to zero.

Useful for restarting the optimization with a fresh momentum state.

Source

pub fn clear_gradients(&mut self)

Clears the gradients buffer.

Trait Implementations§

Source§

impl Clone for SolverState

Source§

fn clone(&self) -> SolverState

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for SolverState

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> Allocation for T
where T: RefUnwindSafe + Send + Sync,