Skip to main content

Solver

Struct Solver 

Source
pub struct Solver { /* private fields */ }
Expand description

A compiled, counted constraint problem, ready to sample.

Implementations§

Source§

impl Solver

Source

pub fn new( var_tys: &[Ty], states: &[Option<BigUint>], conjuncts: &[Expr], ) -> Result<Solver, SolveError>

Compiles the conjunction of conjuncts with the default node budget.

Source

pub fn with_budget( var_tys: &[Ty], states: &[Option<BigUint>], conjuncts: &[Expr], budget: usize, ) -> Result<Solver, SolveError>

As Solver::new with an explicit per-BDD node budget.

Source

pub fn count(&self) -> &SatCount

The exact number of legal assignments.

Source

pub fn compiled(&self) -> &Compiled

The underlying BDD and variable layout.

Source

pub fn sample( &self, order: &[VarId], seed: &mut u64, ) -> Result<Vec<BigUint>, SolveError>

Draws one assignment uniformly from all models (module docs), fixing variables in order, then any variable order omits in id order. Returns one value per variable, indexed by VarId.

Source

pub fn sample_groups( &self, groups: &[Vec<VarId>], seed: &mut u64, ) -> Result<Vec<BigUint>, SolveError>

Draws one assignment solving the variables group by group, in the order of groups (solve ... before, LRM 18.5.9; super::order builds them).

Each group is sampled uniformly over its own distinct feasible value tuples: the variables of every later group are existentially projected away, so a group value is feasible when some assignment of the later groups completes it, and its probability does not depend on how many completions it has. That is the LRM’s solve s before d (Table 18-2: s is 50/50 although s == 1 has a single completion and s == 0 has 2^32). The chosen values are then fixed in the full constraint set and the next group is drawn from what remains. Inside a group the per-bit walk of Solver::sample applies, so a group is uniform over its tuples whatever its internal order.

Any variable groups omits is solved with the last group (LRM 18.5.9: unordered variables are solved with the last set of ordered variables), in id order. A variable listed twice is SolveError::BadOrder.

Source

pub fn sample_plan( &self, plan: &Plan, randc_states: &mut [RandcState], seed: &mut u64, ) -> Result<Vec<BigUint>, SolveError>

Draws one assignment following plan (see Plan): first the randc variables, each from its own cycle state (randc_states[i] belongs to plan.randc[i]; super::randc), then the ordered groups, each with its weighted variables before its uniform ones. A state is only advanced for a variable that was drawn, so a caller that must not commit a failed call clones the states first.

Trait Implementations§

Source§

impl Clone for Solver

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Solver

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V