Package lpsolve. September 19, 2015

Similar documents
Mixed Integer Linear Programming in R

CPLEX Tutorial Handout

Package retrosheet. April 13, 2015

Arithmetic and Algebra of Matrices

Package bigdata. R topics documented: February 19, 2015

Package TSfame. February 15, 2013

Package neuralnet. February 20, 2015

MAT 242 Test 2 SOLUTIONS, FORM T

5 INTEGER LINEAR PROGRAMMING (ILP) E. Amaldi Fondamenti di R.O. Politecnico di Milano 1

EXCEL SOLVER TUTORIAL

Package HadoopStreaming

Package sjdbc. R topics documented: February 20, 2015

Package hoarder. June 30, 2015

Package uptimerobot. October 22, 2015

7. LU factorization. factor-solve method. LU factorization. solving Ax = b with A nonsingular. the inverse of a nonsingular matrix

Linear Programming. March 14, 2014

4.6 Linear Programming duality

6. Cholesky factorization

Package HHG. July 14, 2015

Solving Systems of Linear Equations Using Matrices

Package hive. January 10, 2011

Package survpresmooth

Using CPLEX. =5 has objective value 150.

Package RCassandra. R topics documented: February 19, Version Title R/Cassandra interface

Package tagcloud. R topics documented: July 3, 2015

Package GSA. R topics documented: February 19, 2015

Optimization in R n Introduction

Chapter 6: Sensitivity Analysis

Package empiricalfdr.deseq2

A =

Package erp.easy. September 26, 2015

Package treemap. February 15, 2013

Package plan. R topics documented: February 20, 2015

Package png. February 20, 2015

Package sendmailr. February 20, 2015

Package dunn.test. January 6, 2016

Matrix Multiplication

IEOR 4404 Homework #2 Intro OR: Deterministic Models February 14, 2011 Prof. Jay Sethuraman Page 1 of 5. Homework #2

Package biganalytics

Discrete Optimization

Solution to Homework 2

Notes on Determinant

Package fimport. February 19, 2015

Chapter 6. Linear Programming: The Simplex Method. Introduction to the Big M Method. Section 4 Maximization and Minimization with Problem Constraints

Special Situations in the Simplex Algorithm

Linear Program Solver

Package optirum. December 31, 2015

Package sudoku. February 20, 2015

Lecture 1: Systems of Linear Equations

Package missforest. February 20, 2015

Package dsstatsclient

Package MBA. February 19, Index 7. Canopy LIDAR data

Solving polynomial least squares problems via semidefinite programming relaxations

MATLAB and Big Data: Illustrative Example

MATRIX ALGEBRA AND SYSTEMS OF EQUATIONS. + + x 2. x n. a 11 a 12 a 1n b 1 a 21 a 22 a 2n b 2 a 31 a 32 a 3n b 3. a m1 a m2 a mn b m

by the matrix A results in a vector which is a reflection of the given

Package R4CDISC. September 5, 2015

A Branch and Bound Algorithm for Solving the Binary Bi-level Linear Programming Problem

Package polynom. R topics documented: June 24, Version 1.3-8

Dantzig-Wolfe bound and Dantzig-Wolfe cookbook

Modeling and solving linear programming with R. Jose M Sallan Oriol Lordan Vicenc Fernandez

Lecture 15 An Arithmetic Circuit Lowerbound and Flows in Graphs

1 Introduction. Linear Programming. Questions. A general optimization problem is of the form: choose x to. max f(x) subject to x S. where.

8 Square matrices continued: Determinants

Linear Codes. Chapter Basics

Package Benchmarking

Spreadsheets have become the principal software application for teaching decision models in most business

Package benford.analysis

Transportation Polytopes: a Twenty year Update

MAT 200, Midterm Exam Solution. a. (5 points) Compute the determinant of the matrix A =

Package EstCRM. July 13, 2015

Chapter 6. Orthogonality

2+2 Just type and press enter and the answer comes up ans = 4

Simple File Input & Output

Package hive. July 3, 2015

Two classes of ternary codes and their weight distributions

Similarity and Diagonalization. Similar Matrices

Package Rdsm. February 19, 2015

Package trimtrees. February 20, 2015

1 Solving LPs: The Simplex Algorithm of George Dantzig

Package translater. R topics documented: February 20, Type Package

The Characteristic Polynomial

A Robust Formulation of the Uncertain Set Covering Problem

Package pxr. February 20, 2015

Linear Programs: Variables, Objectives and Constraints

Solving Linear Programs using Microsoft EXCEL Solver

Nonlinear Programming Methods.S2 Quadratic Programming

Mathematical finance and linear programming (optimization)

How to speed-up hard problem resolution using GLPK?

Package forensic. February 19, 2015

Lecture Notes 2: Matrices as Systems of Linear Equations

Package support.ces. R topics documented: August 27, Type Package

I PUC - Computer Science. Practical s Syllabus. Contents

Package acrm. R topics documented: February 19, 2015

( ) which must be a vector

Typical Linear Equation Set and Corresponding Matrices

Transcription:

Package lpsolve September 19, 2015 Version 5.6.13 Date 2015-09-18 Title Interface to 'Lp_solve' v. 5.5 to Solve Linear/Integer Programs Author Michel Berkelaar and others Maintainer Samuel E. Buttrey <buttrey@nps.edu> Lp_solve is freely available (under LGPL 2) software for solving linear, integer and mixed integer programs. In this implementation we supply a ``wrapper'' function in C and some R functions that solve general linear/integer problems, assignment problems, and transportation problems. This version calls lp_solve version 5.5. License LGPL-2 NeedsCompilation yes Repository CRAN Date/Publication 2015-09-19 10:00:23 R topics documented: lp.............................................. 2 lp.assign........................................... 4 lp.object........................................... 6 lp.transport......................................... 7 make.q8........................................... 8 print.lp............................................ 9 Index 11 1

2 lp lp Linear and Integer Programming Usage Interface to lp\_solve linear/integer programming system lp (direction = "min", objective.in, const.mat, const.dir, const.rhs, transpose.constraints = TRUE, int.vec, presolve=0, compute.sens=0, binary.vec, all.int=false, all.bin=false, scale = 196, dense.const, num.bin.solns=1, use.rw=false) Arguments direction objective.in const.mat const.dir Character string giving direction of optimization: "min" (default) or "max." Numeric vector of coefficients of objective function Matrix of numeric constraint coefficients, one row per constraint, one column per variable (unless transpose.constraints = FALSE; see below). Vector of character strings giving the direction of the constraint: each value should be one of "<," "<=," "=," "==," ">," or ">=". (In each pair the two values are identical.) const.rhs Vector of numeric values for the right-hand sides of the constraints. transpose.constraints By default each constraint occupies a row of const.mat, and that matrix needs to be transposed before being passed to the optimizing code. For very large constraint matrices it may be wiser to construct the constraints in a matrix columnby-column. In that case set transpose.constraints to FALSE. int.vec presolve compute.sens binary.vec all.int all.bin scale dense.const Numeric vector giving the indices of variables that are required to be integer. The length of this vector will therefore be the number of integer variables. Numeric: presolve? Default 0 (no); any non-zero value means "yes." Currently ignored. Numeric: compute sensitivity? Default 0 (no); any non-zero value means "yes." Numeric vector like int.vec giving the indices of variables that are required to be binary. Logical: should all variables be integer? Default: FALSE. Logical: should all variables be binary? Default: FALSE. Integer: value for lpsolve scaling. Details can be found in the lpsolve documentation. Set to 0 for no scaling. Default: 196 Three column dense constraint array. This is ignored if const.mat is supplied. Otherwise the columns are constraint number, column number, and value; there should be one row for each non-zero entry in the constraint matrix.

lp 3 num.bin.solns use.rw Integer: if all.bin=true, the user can request up to num.bin.solns optimal solutions to be returned. Logical: if TRUE and num.bin.solns > 1, write the lp out to a file and read it back in for each solution after the first. This is just to defeat a bug somewhere. Although the default is FALSE, we recommend you set this to TRUE if you need num.bin.solns > 1, until the bug is found. Details This function calls the lp\_solve 5.5 solver. That system has many options not supported here. The current version is maintained at http://lpsolve.sourceforge.net/5.5 Note that every variable is assumed to be >= 0! An lp object. See lp.object for details. lp.assign, lp.transport Examples 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, 1) 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) Not run: Success: the objective function is 40.5 lp ("max", f.obj, f.con, f.dir, f.rhs)$solution Not run: [1] 0.0 4.5 0.0 The same problem using the dense constraint approach: f.con.d <- matrix (c(rep (1:2,each=3), rep (1:3, 2), t(f.con)), ncol=3) lp ("max", f.obj,, f.dir, f.rhs, dense.const=f.con.d) Not run: Success: the objective function is 40.5

4 lp.assign Get sensitivities lp ("max", f.obj, f.con, f.dir, f.rhs, compute.sens=true)$sens.coef.from Not run: [1] -1e+30 2e+00-1e+30 lp ("max", f.obj, f.con, f.dir, f.rhs, compute.sens=true)$sens.coef.to Not run: [1] 4.50e+00 1.00e+30 1.35e+01 Right now the dual values for the constraints and the variables are combined, constraints coming first. So in this example... lp ("max", f.obj, f.con, f.dir, f.rhs, compute.sens=true)$duals Not run: [1] 4.5 0.0-3.5 0.0-10.5...the duals of the constraints are 4.5 and 0, and of the variables, -3.5, 0.0, -10.5. Here are the lower and upper limits on these: lp ("max", f.obj, f.con, f.dir, f.rhs, compute.sens=true)$duals.from Not run: [1] 0e+00-1e+30-1e+30-1e+30-6e+00 lp ("max", f.obj, f.con, f.dir, f.rhs, compute.sens=true)$duals.to Not run: [1] 1.5e+01 1.0e+30 3.0e+00 1.0e+30 3.0e+00 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) Not run: Success: the objective function is 37 lp ("max", f.obj, f.con, f.dir, f.rhs, int.vec=1:3)$solution Not run: [1] 1 4 0 You can get sensitivities in the integer case, but they re harder to interpret. lp ("max", f.obj, f.con, f.dir, f.rhs, int.vec=1:3, compute.sens=true)$duals Not run: [1] 1 0 0 7 0 Here s an example in which we want more than one solution to a problem in which all variables are binary: the 8-queens problem, with dense constraints. chess.obj <- rep (1, 64) q8 <- make.q8 () chess.dir <- rep (c("=", "<"), c(16, 26)) chess.rhs <- rep (1, 42) lp ( max, chess.obj,, chess.dir, chess.rhs, dense.const = q8, all.bin=true, num.bin.solns=3) lp.assign Integer Programming for the Assignment Problem

lp.assign 5 Usage Interface to lp\_solve linear/integer programming system specifically for solving assignment problems lp.assign (cost.mat, direction = "min", presolve = 0, compute.sens = 0) Arguments cost.mat direction presolve compute.sens Matrix of costs: the ij-th element is the cost of assigning source i to destination j. Character vector, length 1, containing either "min" (the default) or "max" Numeric: presolve? Default 0 (no); any non-zero value means "yes." Currently ignored. Numeric: compute sensitivity? Default 0 (no); any non-zero value means "yes." In that case presolving is attempted. 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. An lp object. See documentation for details. The constraints are assumed (each row adds to 1, each column adds to 1, and no others) and are not returned. lp, lp.transport Examples assign.costs <- matrix (c(2, 7, 7, 2, 7, 7, 3, 2, 7, 2, 8, 10, 1, 9, 8, 2), 4, 4) Not run: > 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

6 lp.object End(Not run) lp.assign (assign.costs) Not run: Success: the objective function is 8 lp.assign (assign.costs)$solution Not run: [,1] [,2] [,3] [,4] [1,] 0 0 0 1 [2,] 0 0 1 0 [3,] 0 1 0 0 [4,] 1 0 0 0 End(Not run) lp.object LP (linear programming) object Structure of lp object An lp.object is a list containing the following elements: direction x.count objective const.count constraints int.count int.vec objval solution num.bin.solns status Optimization direction, as entered Number of variables in objective function Vector of objective function coefficients, as entered Number of constraints entered Constraint matrix, as entered (not returned by lp.assign or lp.transport) Number of integer variables Vector of integer variables indices, as entered of objective function at optimum Vector of optimal coefficients Numeric indicator of number of solutions returned Numeric indicator: 0 = success, 2 = no feasible solution lp, lp.assign, lp.transport

lp.transport 7 lp.transport Integer Programming for the Transportation Problem Usage Interface to lp\_solve linear/integer programming system specifically for solving transportation problems lp.transport (cost.mat, direction="min", row.signs, row.rhs, col.signs, col.rhs, presolve=0, compute.sens=0, integers = 1:(nc*nr) ) Arguments cost.mat direction row.signs row.rhs col.signs col.rhs presolve compute.sens integers Matrix of costs; ij-th element is the cost of transporting one item from source i to destination j. Character, length 1: "min" or "max" Vector of character strings giving the direction of the row constraints: each value should be one of "<," "<=," "=," "==," ">," or ">=." (In each pair the two values are identical.) Vector of numeric values for the right-hand sides of the row constraints. Vector of character strings giving the direction of the column constraints: each value should be one of "<," "<=," "=," "==," ">," or ">=." Vector of numeric values for the right-hand sides of the column constraints. Numeric: presolve? Default 0 (no); any non-zero value means "yes." Currently ignored. Numeric: compute sensitivity? Default 0 (no); any non-zero value means "yes." Vector of integers whose ith element gives the index of the ith integer variable. Its length will be the number of integer variables. Default: all variables are integer. Set to NULL to have no variables be integer. Details This is a particular integer programming problem. All the decision variables are assumed to be integers, and there is one constraint per row and one per column (and no others). This is assumed to be a minimization problem. An lp object. Constraints are implicit and not returned. See documentation for details.

8 make.q8 References Example problem from Bronson (1981), Operations Research, Scahum s Outline Series, McGraw- Hill. lp.assign, lp.transport Examples 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, "min", row.signs, row.rhs, col.signs, col.rhs) Not run: Success: the objective function is 7790 lp.transport (costs, "min", row.signs, row.rhs, col.signs, col.rhs)$solution Not run: [,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 End(Not run) make.q8 Generate sparse constraint matrix for 8-queens problem

print.lp 9 Generate sparse constraint matrix for 8-queens problem Usage make.q8 () Arguments None. Details Sparse constraints come in a three-column matrix or data frame. Each row gives the row number, column number, and value of a particular non-zero entry in the constraint matrix. This function produces the sparse constraint matrix for the 8-queens problem (in which the object is to place eight queens on a chessboard with no two sharing a row, column or diagonal). The resulting sparse representation is 252 x 3, compared to 42 x 64 for the usual representation. A 252 x 3 numeric matrix. See lp for the complete example. lp print.lp Print an lp object Usage Print method for lp objects S3 method for class lp print(x,...) Arguments x List with items named objval and status. Normally this will have been called by lp, lp.assign, or lp.transport.... Other arguments, all currently ignored

10 print.lp Details This function prints the objective function value, together with the word "Success" if the operation is successful, or an indication of the error if not. If multiple solutions have been produced (because this was an all-binary problem and lp was called with num.bin.solns > 1) the number of solutions is also displayed. None lp, lp.assign, lp.transport

Index Topic optimize lp, 2 lp.assign, 4 lp.object, 6 lp.transport, 7 make.q8, 8 print.lp, 9 8-queens problem (make.q8), 8 lp, 2, 5 7, 9, 10 lp.assign, 3, 4, 6, 8 10 lp.object, 3, 6 lp.transport, 3, 5, 6, 7, 8 10 make.q8, 8 print.lp, 9 11