Learn R Programming

lpSolveAPI (version 5.5.0.12-3)

lp.assign: The Assignment Problem

Description

An integer program solving the assignment problem

Usage

lp.assign(cost.mat, direction = c("min", "max"), presolve = 0,
          compute.sens = 0)

Arguments

cost.mat
a numeric matrix containing the costs: the ij-th element is the cost of assigning source i to destination j.
direction
a character string specifying the direction of optimization: "min" (default) or "max."
presolve
currently ignored.
compute.sens
compute sensitivity? Default 0 (no); any non-zero value means yes.

Value

  • An lp object. See documentation for details.

Details

This is a particular integer programming problem. All the decision variables are assumed to be integers; each row has the constraint that its entries must add up to 1 (so that there is one 1 and the remaining entries are 0) and each column has the same constraint. This is assumed to be a minimization problem.

Examples

Run this code
assign.costs <- matrix (c(2, 7, 7, 2, 7, 7, 3, 2, 7, 2, 8, 10, 1, 9, 8, 2), 4, 4)
> assign.costs
     [,1] [,2] [,3] [,4]
[1,]    2    7    7    1
[2,]    7    7    2    9
[3,]    7    3    8    8
[4,]    2    2   10    2
lp.assign (assign.costs)
Success: the objective function is 8
lp.assign (assign.costs)$solution
[,1] [,2] [,3] [,4]
[1,]    0    0    0    1
[2,]    0    0    1    0
[3,]    0    1    0    0
[4,]    1    0    0    0

Run the code above in your browser using DataLab