**Features new to 5.7: **

- There are now "all integers" and "all binary" indicators, so that you don't have to set up and supply an integer vector.
- (Experimental) Dense constraint setup. Instead of the constraint matrix having to have
(# of constraints) rows and (# of variables) columns, or vice versa, you can now specify
the matrix in a set of (constraint number, variable number, value) rows. All the rows for
a specific constraint must be contiguous. Your set of signs and RHS values is supplied in a separate
two-column matrix. Dense problems must be oriented column-wise (see example).
**I do very little error checking in this mode!**#### Read the original paper,

*J. Stat. Software*vol. 14, issue 4 (2005)#### For Excel: You'll need:

1.) The Excel Add-In (v. 5.7) Download this.

2.) The lpsolve (version 5.7) DLL. Download this, too.

3.) (Optional) The "Tester" workbook (for Excel pre-2007 versions). Download this (don't "open" or "run it in place").

#### Setting the location of the DLL

The Excel code expects your DLL to be "on your path." If you know what that means, place the DLL on your path. If not, copy the DLL over to the "c:\Windows\System32" directory, since that's on your path for sure.#### Using the Add-in.

Now start Excel (use the Tester, if you'd like). Choose Tools | Add-Ins and Browse...; this opens up a file selection window. Use that window to navigate to the place where you saved the add-in. When you find the add-in, click on it, then press Ok. (You will be asked if you want to copy the lpSolve.5.7.Xla add-in to a particular folder. This will make it available automatically, at the cost of increasing your profile size a bit. Personally I have noticed that this menu item often disappears when I close Excel. I get it back by clicking on Tools | Add-Ins again. lpSolve is clicked, so I unclick it, press Ok, click it again, and press Ok again. I don't know why this happens and I apologize for the hassle.#### Using the Add-in with the "Tester57" workbook.

Open the Tester workbook and position yourself on the "Simple Examples" sheet. Choose Tools | lpSolve (older Excel) or Add-Ins | lpSolve (Excel 2007). You'll see the "problem selection" window. Choose linear/integer program. You will see a window with radio buttons marked "Max" and "Min" at the top, and four areas to be filled in. Do the following:

The checkboxes allow you to set set all variables to be integers, or all to be binary. These over-ride any choice you make in the box -- and of course binary over-rides integer.

All the boxes are required to be filled in, except for the integer one. However you can fool the spreadsheet by putting something that isn't a valid range into a box. Right now I don't try to catch that. Don't do that.

When you're ready, press the "Run Lp_solve" button and your results should appear. If there's an error, you
should see a pop-up box giving the error's number. There are two sorts of errors: lpSolve's own internal errors
and VB errors. Happily, their numbers rarely overlap. Error codes include:

2: "No feasible solution."

3: "Problem is unbounded."

4: "Problem is degenerate."

5: "Numeric failure."

13: "Type mismatch." This VBA error might occur when you select only one cell where I expected a range.

48: "Error in loading DLL." The DLL is not on your path or not named lpslink57.dll.

49: "Bad DLL calling convention." You're using the R dll for Excel.

For an assignment problem, make that choice on the problem selection window. Enter a matrix of costs and a space for decision variables into the appropriate places. We assume each row and column need to add up to 1 and that all variables are integers. The optimal value will be placed one row and one column past the bottom right-hand corner of the cost matrix. See the workbook for examples.

For a transportation problem, make that choice on the problem selection window. Enter a matrix of costs and a space for decision variables into the appropriate places. The decision variable matrix should have two extra rows giving signs and right-hand sides of constraints, and likewise two extra columns. We assume that all variables are integers. The optimal value will be placed in the bottom right-hand corner of the cost matrix. See the workbook for examples.

Old (v. 5.6) Excel stuff: Excel addin; DLL; Tester.

`lp()` example:

# # Set up problem: maximize # x1 + 9 x2 + x3 subject to # x1 + 2 x2 + 3 x3 <= 9 # 3 x1 + 2 x2 + 2 x3 <= 15 # > f.obj <- c(1, 9, 3) > f.con <- matrix (c(1, 2, 3, 3, 2, 2), nrow=2, byrow=TRUE) > f.dir <- c("<=", "<=") > f.rhs <- c(9, 15) # # Now run. # > lp ("max", f.obj, f.con, f.dir, f.rhs) Success: the objective function is 40.5 > lp ("max", f.obj, f.con, f.dir, f.rhs)$solution [1] 0.0 4.5 0.0 # # Run again, this time requiring that all three variables be integer # > lp ("max", f.obj, f.con, f.dir, f.rhs, int.vec=1:3) Success: the objective function is 37 > lp ("max", f.obj, f.con, f.dir, f.rhs, int.vec=1:3)$solution [1] 1 4 0

`lp.assign()` example:

> 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

`lp.transport()` example:

# # Transportation problem, Bronson, problem 9.1, p. 86 # # Set up cost matrix # > costs <- matrix (10000, 8, 5); costs[4,1] <- costs[-4,5] <- 0 > costs[1,2] <- costs[2,3] <- costs[3,4] <- 7; costs[1,3] <- costs[2,4] <- 7.7 > costs[5,1] <- costs[7,3] <- 8; costs[1,4] <- 8.4; costs[6,2] <- 9 > costs[8,4] <- 10; costs[4,2:4] <- c(.7, 1.4, 2.1) # # Set up constraint signs and right-hand sides. # > row.signs <- rep ("<", 8) > row.rhs <- c(200, 300, 350, 200, 100, 50, 100, 150) > col.signs <- rep (">", 5) > col.rhs <- c(250, 100, 400, 500, 200) # # Run # > lp.transport (costs, row.signs, row.rhs, col.signs, col.rhs) Success: the objective function is 7790 > lp.transport (costs, row.signs, row.rhs, col.signs, col.rhs)$solution [,1] [,2] [,3] [,4] [,5] [1,] 0 100 0 100 0 [2,] 0 0 300 0 0 [3,] 0 0 0 350 0 [4,] 200 0 0 0 0 [5,] 50 0 0 0 50 [6,] 0 0 0 0 50 [7,] 0 0 100 0 0 [8,] 0 0 0 50 100