| assignment | R Documentation |
Solve the linear assignment problem (minimum- or maximum-cost matching)
using several algorithms. Forbidden edges can be marked as NA or Inf.
assignment(
cost,
maximize = FALSE,
method = c("auto", "jv", "hungarian", "auction", "auction_gs", "auction_scaled", "sap",
"ssp", "csflow", "hk01", "bruteforce", "ssap_bucket", "cycle_cancel", "gabow_tarjan",
"lapmod", "csa", "ramshaw_tarjan", "push_relabel", "orlin", "network_simplex"),
auction_eps = NULL,
eps = NULL
)
cost |
Numeric matrix; rows = tasks, columns = agents. |
maximize |
Logical; if |
method |
Character string indicating the algorithm to use. Options: General-purpose solvers:
Auction-based solvers:
Specialized solvers:
Advanced solvers:
|
auction_eps |
Optional numeric epsilon for the 'Auction'/'Auction-GS' methods.
If |
eps |
Deprecated. Use |
method = "auto" selects an algorithm based on problem size/shape and data
characteristics:
Very small (n <= 8): "bruteforce" — exact enumeration
Binary/constant costs: "hk01" — specialized for 0/1 costs
Large sparse (n>100, >50\
Sparse or very rectangular: "sap" — handles sparsity well
Small-medium (8 < n <= 50): "hungarian" — provides exact dual solutions
Medium (50 < n <= 75): "jv" — fast general-purpose solver
Large (n>75): "auction_scaled" — fastest for large dense problems
Benchmarks show 'Auction-scaled' and 'JV' are 100-1500x faster than 'Hungarian' at n=500.
An object of class lap_solve_result, a list with elements:
match — integer vector of length min(nrow(cost), ncol(cost))
giving the assigned column for each row (0 if unassigned).
total_cost — numeric scalar, the objective value.
status — character scalar, e.g. "optimal".
method_used — character scalar, the algorithm actually used.
lap_solve() — Tidy interface returning tibbles
lap_solve_kbest() — Find k-best assignments ('Murty' algorithm)
assignment_duals() — Extract dual variables for sensitivity analysis
bottleneck_assignment() — Minimize maximum edge cost (minimax)
sinkhorn() — Entropy-regularized optimal transport
cost <- matrix(c(4,2,5, 3,3,6, 7,5,4), nrow = 3, byrow = TRUE)
res <- assignment(cost)
res$match; res$total_cost
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.