Skip to main content

AssignmentBuilder

Struct AssignmentBuilder 

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

Fluent builder for bipartite assignment COPs.

Construct via assignment() (preferred) or Default::default. All setters consume self and return self, allowing chained configuration. The terminal AssignmentBuilder::solve call validates the configuration, materializes the underlying Csp<CostFiniteDomain>, runs branch-and-bound, and returns an AssignmentSolution (or an AssignmentError on mis-configuration / infeasibility).

Implementations§

Source§

impl AssignmentBuilder

Source

pub fn rows(self, n: usize) -> Self

Set the number of source rows.

Source

pub fn cols(self, n: usize) -> Self

Set the number of target columns.

Source

pub fn cost(self, f: impl Fn(usize, usize) -> f64) -> Self

Eagerly populate the row-major cost matrix.

Calls f(i, k) exactly once per (row, col) cell during this method, stores the result in an internal Vec<f64>, and returns self. No closure is retained, which keeps the builder Send + Sync even when constructed from non-'static captures.

§Panics

Panics if AssignmentBuilder::rows or AssignmentBuilder::cols has not been called yet — both dimensions are required to know how to walk f.

Source

pub fn row_group(self, f: impl Fn(usize) -> u8) -> Self

Tag each row with a u8 group identifier.

Rows in different groups are placed in independent AllDifferentExcept scopes, and a row may only be assigned to a column whose group identifier matches. Omitting the call (or supplying |_| 0) puts every row in a single group, which is the standard bipartite-assignment shape.

Source

pub fn col_group(self, f: impl Fn(usize) -> u8) -> Self

Tag each column with a u8 group identifier.

See AssignmentBuilder::row_group for the semantics.

Source

pub fn pin(self, row: usize, col: i32) -> Self

Hard-pin row row to column col.

col may be SENTINEL to force the row unmatched. Multiple pins are accumulated; conflicting pins on the same row are detected at AssignmentBuilder::solve time as AssignmentError::Infeasible.

Source

pub fn unmatch_penalty(self, penalty: f64) -> Self

Set the per-row cost paid when a row is assigned to SENTINEL (left unmatched).

Source

pub fn node_budget(self, budget: Option<u64>) -> Self

Override the underlying branch-and-bound node budget.

Passing None here is not the same as never calling this method: None requests an unbounded search, while the default (no call) installs a 1_000_000 node guard so a pathological problem cannot hang the caller. See crate::SolveConfig::node_budget.

Source

pub fn solve(self) -> Result<AssignmentSolution, AssignmentError>

Validate the configuration, build the underlying CSP, and run branch-and-bound to find the minimum-cost assignment.

Trait Implementations§

Source§

impl Debug for AssignmentBuilder

Source§

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

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

impl Default for AssignmentBuilder

Source§

fn default() -> AssignmentBuilder

Returns the “default value” for a type. 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> 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.