Skip to main content

Module assignment

Module assignment 

Source
Expand description

Bipartite assignment COP builder.

Fluent API for the common pattern of “assign N source rows to M target columns with per-cell costs, role-based AllDifferent groups, and optional hard pin constraints.” Internally constructs a Csp<CostFiniteDomain> with one variable per row, an AllDifferentExcept per row-group, and -1 as the unmatched sentinel; the underlying branch-and-bound search is invoked through Csp::solve_optimized with OptimizationMode::MinimizeCost and Pruning::AcFc.

AssignmentBuilder is intended for n ≤ ~100 rows / cols. The branch-and-bound search degrades super-linearly past that point; larger problems should prefer a specialized Hungarian algorithm and feed the resulting permutation back into a Csp only if additional constraints (groups, pins) make the closed-form solution infeasible.

§Example

use csp_solver::assignment;

let sol = assignment()
    .rows(3)
    .cols(3)
    .cost(|i, k| if i == k { 0.0 } else { 10.0 })
    .unmatch_penalty(100.0)
    .solve()
    .expect("solvable");

assert_eq!(sol.assign, vec![0, 1, 2]);
assert_eq!(sol.cost, 0.0);

Structs§

AssignmentBuilder
Fluent builder for bipartite assignment COPs.
AssignmentSolution
Result of a successful AssignmentBuilder::solve call.

Enums§

AssignmentError
Errors from AssignmentBuilder::solve.

Constants§

SENTINEL
Sentinel value used in AssignmentSolution::assign to denote an unmatched row.

Functions§

assignment
Top-level constructor for an empty AssignmentBuilder.