Skip to main content

SoftLambdaConstraint

Struct SoftLambdaConstraint 

Source
pub struct SoftLambdaConstraint<D: Domain> { /* private fields */ }
Expand description

A soft constraint backed by a closure, analogous to LambdaConstraint.

When the checker returns false, the constraint is “violated” and its penalty is added to the objective during optimization search.

Implementations§

Source§

impl<D: Domain> SoftLambdaConstraint<D>

Source

pub fn new( scope: Vec<VarId>, checker: impl Fn(&[Option<D::Value>]) -> bool + 'static, penalty: f64, label: impl Into<String>, ) -> Self

Source§

impl<D: Domain> SoftLambdaConstraint<D>

Source

pub fn is_satisfied(&self, assignment: &[Option<D::Value>]) -> bool

Check whether the underlying predicate is satisfied. This is separate from Constraint::check (which always returns true so that soft constraints don’t prune) — use this to compute penalty costs.

Trait Implementations§

Source§

impl<D: Domain> Constraint<D> for SoftLambdaConstraint<D>

Source§

fn check(&self, _assignment: &[Option<D::Value>]) -> bool

Soft constraints always “pass” — they never prune domains. Their violation is tracked as cost, not as infeasibility.

Source§

fn scope(&self) -> &[VarId]

The variables this constraint involves (its “scope”).
Source§

fn revise(&self, vars: &mut [Variable<D>], depth: usize) -> Revision

AC-3 style revision: prune unsupported values from domains.
Source§

impl<D: Domain> Debug for SoftLambdaConstraint<D>

Source§

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

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

impl<D: Domain> SoftConstraint<D> for SoftLambdaConstraint<D>

Source§

fn penalty(&self) -> f64

Penalty added to the objective when this constraint is violated.

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> 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, 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.