Skip to main content

PbConstraint

Struct PbConstraint 

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

A normalized pseudo-Boolean constraint Σ coeff·lit ≥ degree: every coeff > 0, every variable appears at most once, and the literal sign rides the entry — (coeff, positive) with positive == false meaning the literal ¬x. degree may be ≤ 0 (then the constraint is trivially true) or exceed the coefficient sum (then it is a contradiction).

Implementations§

Source§

impl PbConstraint

Source

pub fn at_least(lits: &[(usize, bool)], k: i64) -> PbConstraint

Σ ℓ ≥ k over the given literals (each coefficient 1). Literals must be over distinct variables (the caller’s responsibility — true for clause/cardinality inputs).

Source

pub fn clause(lits: &[(usize, bool)]) -> PbConstraint

A CNF clause ℓ₁ ∨ … ∨ ℓₖ as the PB constraint Σ ℓ ≥ 1 — the bridge that lets the cutting plane engine consume ordinary SAT clauses (and p-simulate resolution on them).

Source

pub fn at_most(lits: &[(usize, bool)], k: i64) -> PbConstraint

Σ ℓ ≤ k, normalized to form by flipping every literal: Σ ¬ℓ ≥ n − k.

Source

pub fn degree(&self) -> i64

The degree (right-hand side).

Source

pub fn len(&self) -> usize

Number of (non-cancelled) terms.

Source

pub fn is_empty(&self) -> bool

Source

pub fn add(&self, other: &PbConstraint) -> PbConstraint

AdditionLHS₁ + LHS₂ ≥ d₁ + d₂, then re-normalized. A variable that is x in one and ¬x in the other partially cancels (a·x + b·¬x = (a−b)·x + b), so the shared minimum min(a,b) leaves the literal and is moved to the right, dropping the degree by min(a,b). Sound: the sum of two valid constraints is valid, and x + ¬x = 1 is exact for 0/1.

Source

pub fn multiply(&self, c: i64) -> PbConstraint

Multiplication by a positive integer — c·LHS ≥ c·degree. Trivially sound (scaling a valid constraint by c > 0).

Source

pub fn divide_round(&self, d: i64) -> PbConstraint

Division with rounding-up (the Gomory–Chvátal cut) — Σ ⌈aᵢ/d⌉·ℓᵢ ≥ ⌈degree/d⌉. Sound ONLY because variables are integral: ⌈aᵢ/d⌉ ≥ aᵢ/d so the LHS only grows (≥ degree/d), and being an integer it is ≥ ⌈degree/d⌉. This rounding of the fractional slack is exactly what makes cutting planes stronger than resolution.

Source

pub fn saturate(&self) -> PbConstraint

Saturation — clamp every coefficient to the degree (min(aᵢ, degree)). A single 0/1 variable can contribute at most degree toward the bound, so the excess is redundant. Sound, and it keeps coefficients from blowing up across many additions.

Source

pub fn is_contradiction(&self) -> bool

A constraint NO 0/1 assignment can satisfy: the maximum possible LHS (every coefficient counted) is still below the degree. The terminal of a refutation — e.g. 0 ≥ 1.

Source

pub fn is_satisfied(&self, assign: &dyn Fn(usize) -> bool) -> bool

Evaluate under assign (a variable → bool map; unmentioned variables are false): does Σ coeff·[literal true] ≥ degree hold? The oracle the rule soundness tests check against.

Source

pub fn new_weighted(terms: &[(usize, i64, bool)], degree: i64) -> PbConstraint

Σ coeffᵢ·litᵢ ≥ degree directly from weighted terms (var, coeff, positive) — for constraints whose coefficients are not all 1.

Source

pub fn term(&self, v: usize) -> Option<(i64, bool)>

The (coeff, positive) term on variable v, or None if v does not occur.

Source

pub fn terms(&self) -> impl Iterator<Item = (usize, i64, bool)> + '_

Iterate the constraint’s terms as (variable, coeff, positive) — the public view of the otherwise-private normalized map, so a live theory can read a constraint without owning it.

Trait Implementations§

Source§

impl Clone for PbConstraint

Source§

fn clone(&self) -> PbConstraint

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 PbConstraint

Source§

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

Formats the value using the given formatter. Read more
Source§

impl PartialEq for PbConstraint

Source§

fn eq(&self, other: &PbConstraint) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for PbConstraint

Source§

impl StructuralPartialEq for PbConstraint

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.