Struct ConstraintBuilder

Source
pub struct ConstraintBuilder<S: Score> {
    pub factory: Rc<RefCell<ConstraintFactory<S>>>,
    pub weights: Rc<RefCell<ConstraintWeights>>,
    pub _phantom: PhantomData<S>,
}
Expand description

High-level builder for constraint satisfaction problems.

Fields§

§factory: Rc<RefCell<ConstraintFactory<S>>>§weights: Rc<RefCell<ConstraintWeights>>§_phantom: PhantomData<S>

Implementations§

Source§

impl<S: Score + 'static> ConstraintBuilder<S>

Source

pub fn new() -> Self

Source

pub fn with_limits(limits: ResourceLimits) -> Self

Source

pub fn for_each<T: GreynetFact + 'static>(&self) -> Stream<Arity1, S>

Starts a stream definition for any fact type, not tied to a specific constraint.

Source

pub fn build(self) -> Result<Session<S>>

Consumes the builder and constructs the Session.

Source

pub fn add_constraint( &mut self, id: &str, weight: f64, ) -> ConstraintStreamBuilder<'_, S>

Starts the definition of a new constraint with a fluent API. This is the recommended way to define constraints.

Source

pub fn constraint( self, id: &str, weight: f64, recipe_fn: impl Fn(ConstraintId) -> ConstraintRecipe<S>, ) -> Self

Defines a constraint using a closure. This method is kept for backward compatibility but add_constraint is preferred. The closure now receives the ConstraintId to pass to penalize().

Source

pub fn bulk_constraints( self, constraints: Vec<(&str, f64, Box<dyn Fn(ConstraintId) -> ConstraintRecipe<S>>)>, ) -> Self

Defines a batch of constraints using closures.

Trait Implementations§

Source§

impl<S: Score> Default for ConstraintBuilder<S>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<S> Freeze for ConstraintBuilder<S>

§

impl<S> !RefUnwindSafe for ConstraintBuilder<S>

§

impl<S> !Send for ConstraintBuilder<S>

§

impl<S> !Sync for ConstraintBuilder<S>

§

impl<S> Unpin for ConstraintBuilder<S>
where S: Unpin,

§

impl<S> !UnwindSafe for ConstraintBuilder<S>

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.