Package linprog. February 20, 2015

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

Package retrosheet. April 13, 2015

Linear Programming I

Nonlinear Programming Methods.S2 Quadratic Programming

GENERALIZED INTEGER PROGRAMMING

1 Solving LPs: The Simplex Algorithm of George Dantzig

Lecture 3. Linear Programming. 3B1B Optimization Michaelmas 2015 A. Zisserman. Extreme solutions. Simplex method. Interior point method

Package missforest. February 20, 2015

Practical Guide to the Simplex Method of Linear Programming

Package hive. January 10, 2011

Linear Programming Problems

Package uptimerobot. October 22, 2015

Chapter 6: Sensitivity Analysis

LU Factorization Method to Solve Linear Programming Problem

4.6 Linear Programming duality

Linear Programming. March 14, 2014

Using EXCEL Solver October, 2000

Using the Simplex Method to Solve Linear Programming Maximization Problems J. Reeb and S. Leavengood

Package decompr. August 17, 2016

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

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

Package neuralnet. February 20, 2015

Using CPLEX. =5 has objective value 150.

Package TSfame. February 15, 2013

Package ATE. R topics documented: February 19, Type Package Title Inference for Average Treatment Effects using Covariate. balancing.

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

Linear Programming Notes V Problem Transformations

Simplex method summary

Standard Form of a Linear Programming Problem

Mixed Integer Linear Programming in R

LECTURE 5: DUALITY AND SENSITIVITY ANALYSIS. 1. Dual linear program 2. Duality theory 3. Sensitivity analysis 4. Dual simplex method

Special Situations in the Simplex Algorithm

A numerically adaptive implementation of the simplex method

Sensitivity Analysis 3.1 AN EXAMPLE FOR ANALYSIS

Chapter 2 Solving Linear Programs

Linear Programming in Matrix Form

Package bigdata. R topics documented: February 19, 2015

Linear Programming for Optimization. Mark A. Schulze, Ph.D. Perceptive Scientific Instruments, Inc.

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

Package jrvfinance. R topics documented: October 6, 2015

9.4 THE SIMPLEX METHOD: MINIMIZATION

56:171 Operations Research Midterm Exam Solutions Fall 2001

This exposition of linear programming

International Doctoral School Algorithmic Decision Theory: MCDA and MOO

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

MATLAB and Big Data: Illustrative Example

Package httprequest. R topics documented: February 20, 2015

LECTURE: INTRO TO LINEAR PROGRAMMING AND THE SIMPLEX METHOD, KEVIN ROSS MARCH 31, 2005

Mathematical finance and linear programming (optimization)

Linear Programming. April 12, 2005

Package EstCRM. July 13, 2015

Lecture 2: August 29. Linear Programming (part I)

Package hoarder. June 30, 2015

Applied Algorithm Design Lecture 5

Can linear programs solve NP-hard problems?

Duality in Linear Programming

CPLEX Tutorial Handout

Creating a More Efficient Course Schedule at WPI Using Linear Optimization

Package hive. July 3, 2015

Linear Programming: Theory and Applications

Package sjdbc. R topics documented: February 20, 2015

Chapter 2: Linear Equations and Inequalities Lecture notes Math 1010

Solving Linear Programs in Excel

3.1 Solving Systems Using Tables and Graphs

Approximation Algorithms

Package tagcloud. R topics documented: July 3, 2015

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

Linear Program Solver

Package plan. R topics documented: February 20, 2015

Nonlinear Optimization: Algorithms 3: Interior-point methods

Sensitivity Report in Excel

Proximal mapping via network optimization

Package bigrf. February 19, 2015

! Solve problem to optimality. ! Solve problem in poly-time. ! Solve arbitrary instances of the problem. #-approximation algorithm.

Package HadoopStreaming

Package CoImp. February 19, 2015

Package sudoku. February 20, 2015

Package dsstatsclient

What is Linear Programming?

Adaptive Stable Additive Methods for Linear Algebraic Calculations

Package png. February 20, 2015

Package TimeWarp. R topics documented: April 1, 2015

3. Evaluate the objective function at each vertex. Put the vertices into a table: Vertex P=3x+2y (0, 0) 0 min (0, 5) 10 (15, 0) 45 (12, 2) 40 Max

Package empiricalfdr.deseq2

Elementary Number Theory and Methods of Proof. CSE 215, Foundations of Computer Science Stony Brook University

MATH 423 Linear Algebra II Lecture 38: Generalized eigenvectors. Jordan canonical form (continued).

Chapter Load Balancing. Approximation Algorithms. Load Balancing. Load Balancing on 2 Machines. Load Balancing: Greedy Scheduling

INTEGER PROGRAMMING. Integer Programming. Prototype example. BIP model. BIP models

Package fimport. February 19, 2015

Linear Programming II: Minimization 2006 Samuel L. Baker Assignment 11 is on page 16.

Package survpresmooth

Transportation Polytopes: a Twenty year Update

Package cgdsr. August 27, 2015

Package pdfetch. R topics documented: July 19, 2015

Package PACVB. R topics documented: July 10, Type Package

EXCEL SOLVER TUTORIAL

Transcription:

Package linprog February 20, 2015 Version 0.9-2 Date 2012/10/17 Title Linear Programming / Optimization Author Arne Henningsen Maintainer Arne Henningsen <arne.henningsen@gmail.com> Depends R (>= 2.4.0), lpsolve Description This package can be used to solve Linear Programming / Linear Optimization problems by using the simplex algorithm. License GPL (>= 2) URL http://linprog.r-forge.r-project.org/ Repository CRAN Date/Publication 2012-10-17 11:03:12 NeedsCompilation no R topics documented: print.solvelp........................................ 2 readmps........................................... 3 solvelp........................................... 4 summary.solvelp...................................... 8 writemps.......................................... 9 Index 11 1

2 print.solvelp print.solvelp Print Objects of Class solvelp Description Usage This method prints the results of the Linear Programming algorithm. ## S3 method for class solvelp print( x, digits=6,...) Arguments x Value digits an object returned by solvelp. number of digits to print.... currently ignored. print.solvelp invisibly returns the object given in argument x. Author(s) See Also Arne Henningsen solvelp, summary.solvelp, readmps, writemps Examples ## example of Steinhauser, Langbehn and Peters (1992) ## Not run: library( linprog ) ## Production activities cvec <- c(1800, 600, 600) # gross margins names(cvec) <- c("milk","bulls","pigs") ## Constraints (quasi-fix factors) bvec <- c(40, 90, 2500) # endowment names(bvec) <- c("land","stable","labor") ## Needs of Production activities Amat <- rbind( c( 0.7, 0.35, 0 ), c( 1.5, 1, 3 ), c( 50, 12.5, 20 ) )

readmps 3 ## Maximize the gross margin res <- solvelp( cvec, bvec, Amat, TRUE ) ## print the results print( res ) readmps Read MPS Files Description Usage This function reads MPS files - the standard format for Linear Programming problems. Arguments file Details Value readmps( file, solve=false, maximum=false ) a character string naming the file to read. solve logical. Should the problem be solved after reading it from the file (using solvelp)? maximum logical. Should we maximize or minimize (the default)? Equality constraints and greater than -bounds are not implemented yet. readmps returns a list containing following objects: name cvec vector c. bvec vector b. Amat matrix A. res Author(s) See Also Arne Henningsen solvelp, writemps the name of the Linear Programming problem. if solve is TRUE, it contains the results of the solving process (an object of class solvelp).

4 solvelp Examples ## example of Steinhauser, Langbehn and Peters (1992) ## Production activities cvec <- c(1800, 600, 600) # gross margins names(cvec) <- c("cows","bulls","pigs") ## Constraints (quasi-fix factors) bvec <- c(40, 90, 2500) # endowment names(bvec) <- c("land","stable","labor") ## Needs of Production activities Amat <- rbind( c( 0.7, 0.35, 0 ), c( 1.5, 1, 3 ), c( 50, 12.5, 20 ) ) ## Write to MPS file writemps( "steinh.mps", cvec, bvec, Amat, "Steinhauser" ) ## delete all LP objects rm( cvec, bvec, Amat ) ## Read LP data from MPS file and solve it. lp <- readmps( "steinh.mps", TRUE, TRUE ) ## Print the results lp$res solvelp Solve Linear Programming / Optimization Problems Description Minimizes (or maximizes) c x, subject to Ax <= b and x >= 0. Note that the inequality signs <= of the individual linear constraints in Ax <= b can be changed with argument const.dir. Usage solvelp( cvec, bvec, Amat, maximum = FALSE, const.dir = rep( "<=", length( bvec ) ), maxiter = 1000, zero = 1e-9, tol = 1e-6, dualtol = tol, lpsolve = FALSE, solve.dual = FALSE, verbose = 0 )

solvelp 5 Arguments cvec bvec Amat maximum const.dir maxiter zero tol dualtol lpsolve solve.dual verbose vector c (containing n elements). vector b (containing m elements). matrix A (of dimension m n). logical. Should we maximize or minimize (the default)? vector of character strings giving the directions of the constraints: each value should be one of "<," "<=," "=," "==," ">," or ">=". (In each pair the two values are identical.) maximum number of iterations. numbers smaller than this value (in absolute terms) are set to zero. if the constraints are violated by more than this number, the returned component status is set to 3. if the constraints in the dual problem are violated by more than this number, the returned status is non-zero. logical. Should the package lpsolve be used to solve the LP problem? logical value indicating if the dual problem should also be solved. an optional integer variable to indicate how many intermediate results should be printed (0 = no output; 4 = maximum output). Details This function uses the Simplex algorithm of George B. Dantzig (1947) and provides detailed results (e.g. dual prices, sensitivity analysis and stability analysis). If the solution x = 0 is not feasible, a 2-phase procedure is applied. Values of the simplex tableau that are actually zero might get small (positive or negative) numbers due to rounding errors, which might lead to artificial restrictions. Therefore, all values that are smaller (in absolute terms) than the value of zero (default is 1e-10) are set to 0. Solving the Linear Programming problem by the package lpsolve (of course) requires the installation of this package, which is available on CRAN (http://cran.r-project.org/src/contrib/ PACKAGES.html#lpSolve). Since the lpsolve package uses C-code and this (linprog) package is not optimized for speed, the former is much faster. However, this package provides more detailed results (e.g. dual values, stability and sensitivity analysis). This function has not been tested extensively and might not solve all feasible problems (or might even lead to wrong results). However, you can export your LP to a standard MPS file via writemps and check it with other software (e.g. lp_solve, see ftp://ftp.es.ele.tue.nl/pub/lp_solve). Equality constraints are not implemented yet. Value solvelp returns a list of the class solvelp containing following objects: opt optimal value (minimum or maximum) of the objective function. solution vector of optimal values of the variables. iter1 iterations of Simplex algorithm in phase 1.

6 solvelp iter2 iterations of Simplex algorithm in phase 2. basvar con allvar status lpstatus dualstatus maximum Tab lpsolve solve.dual maxiter Author(s) Arne Henningsen vector of basic (=non-zero) variables (at optimum). matrix of results regarding the constraints: 1st column = maximum values (=vector b); 2nd column = actual values; 3rd column = differences between maximum and actual values; 4th column = dual prices (shadow prices); 5th column = valid region for dual prices. matrix of results regarding all variables (including slack variables): 1st column = optimal values; 2nd column = values of vector c; 3rd column = minimum of vector c that does not change the solution; 4th column = maximum of vector c that does not change the solution; 5th column = derivatives to the objective function; 6th column = valid region for these derivatives. numeric. Indicates if the optimization did succeed: 0 = success; 1 = lpsolve did not succeed; 2 = solving the dual problem did not succeed; 3 = constraints are violated at the solution (internal error or large rounding errors); 4 = simplex algorithm phase 1 did not find a solution within the number of iterations specified by argument maxiter; 5 = simplex algorithm phase 2 did not find the optimal solution within the number of iterations specified by argument maxiter. numeric. Return code of lp (only if argument lpsolve is TRUE). numeric. Return code from solving the dual problem (only if argument solve.dual is TRUE). logical. Indicates whether the objective function was maximized or minimized. final Tableau of the Simplex algorith. logical. Has the package lpsolve been used to solve the LP problem. logical. Argument solve.dual. numeric. Argument maxiter. References Dantzig, George B. (1951), Maximization of a linear function of variables subject to linear inequalities, in Koopmans, T.C. (ed.), Activity analysis of production and allocation, John Wiley \& Sons, New York, p. 339-347. Steinhauser, Hugo; Cay Langbehn and Uwe Peters (1992), Einfuehrung in die landwirtschaftliche Betriebslehre. Allgemeiner Teil, 5th ed., Ulmer, Stuttgart. Witte, Thomas; Joerg-Frieder Deppe and Axel Born (1975), Lineare Programmierung. Einfuehrung fuer Wirtschaftswissenschaftler, Gabler-Verlag, Wiesbaden.

solvelp 7 See Also readmps and writemps Examples ## example of Steinhauser, Langbehn and Peters (1992) ## Production activities cvec <- c(1800, 600, 600) # gross margins names(cvec) <- c("cows","bulls","pigs") ## Constraints (quasi-fix factors) bvec <- c(40, 90, 2500) # endowment names(bvec) <- c("land","stable","labor") ## Needs of Production activities Amat <- rbind( c( 0.7, 0.35, 0 ), c( 1.5, 1, 3 ), c( 50, 12.5, 20 ) ) ## Maximize the gross margin solvelp( cvec, bvec, Amat, TRUE ) ## example 1.1.3 of Witte, Deppe and Born (1975) ## Two types of Feed cvec <- c(2.5, 2 ) # prices of feed names(cvec) <- c("feed1","feed2") ## Constraints (minimum (<0) and maximum (>0) contents) bvec <- c(-10, -1.5, 12) names(bvec) <- c("protein","fat","fibre") ## Matrix A Amat <- rbind( c( -1.6, -2.4 ), c( -0.5, -0.2 ), c( 2.0, 2.0 ) ) ## Minimize the cost solvelp( cvec, bvec, Amat ) # the same optimisation using argument const.dir solvelp( cvec, abs( bvec ), abs( Amat ), const.dir = c( ">=", ">=", "<=" ) ) ## There are also several other ways to put the data into the arrays, e.g.: bvec <- c( Protein = -10.0, Fat = -1.5, Fibre = 12.0 ) cvec <- c( Feed1 = 2.5, Feed2 = 2.0 ) Amat <- matrix( 0, length(bvec), length(cvec) )

8 summary.solvelp rownames(amat) <- names(bvec) colnames(amat) <- names(cvec) Amat[ "Protein", "Feed1" ] <- -1.6 Amat[ "Fat", "Feed1" ] <- -0.5 Amat[ "Fibre", "Feed1" ] <- 2.0 Amat[ "Protein", "Feed2" ] <- -2.4 Amat[ "Fat", "Feed2" ] <- -0.2 Amat[ "Fibre", "Feed2" ] <- 2.0 solvelp( cvec, bvec, Amat ) summary.solvelp Summary Results for Objects of Class solvelp Description These methods prepare and print summary results of the Linear Programming algorithm. Usage ## S3 method for class solvelp summary(object,...) ## S3 method for class summary.solvelp print(x,...) Arguments object an object returned by solvelp. x an object returned by summary.solvelp.... currently ignored. Value summary.solvelp returns an object of class summary.solvelp. print.summary.solvelp invisibly returns the object given in argument x. Author(s) Arne Henningsen See Also solvelp, print.solvelp, readmps, writemps

writemps 9 Examples ## example of Steinhauser, Langbehn and Peters (1992) ## Not run: library( linprog ) ## Production activities cvec <- c(1800, 600, 600) # gross margins names(cvec) <- c("milk","bulls","pigs") ## Constraints (quasi-fix factors) bvec <- c(40, 90, 2500) # endowment names(bvec) <- c("land","stable","labor") ## Needs of Production activities Amat <- rbind( c( 0.7, 0.35, 0 ), c( 1.5, 1, 3 ), c( 50, 12.5, 20 ) ) ## Maximize the gross margin res <- solvelp( cvec, bvec, Amat, TRUE ) ## prepare and print the summary results summary( res ) writemps Write MPS Files Description Usage This function writes MPS files - the standard format for Linear Programming problems. writemps( file, cvec, bvec, Amat, name="lp" ) Arguments file cvec vector c. bvec vector b. Amat matrix A. name Details a character string naming the file to write. an optional name for the Linear Programming problem. The exported LP can be solved by running other software on this MPS file (e.g. lp_solve, see ftp://ftp.es.ele.tue.nl/pub/lp_solve).

10 writemps Author(s) Arne Henningsen See Also solvelp, readmps Examples ## example of Steinhauser, Langbehn and Peters (1992) ## Production activities cvec <- c(1800, 600, 600) # gross margins names(cvec) <- c("cows","bulls","pigs") ## Constraints (quasi-fix factors) bvec <- c(40, 90, 2500) # endowment names(bvec) <- c("land","stable","labor") ## Needs of Production activities Amat <- rbind( c( 0.7, 0.35, 0 ), c( 1.5, 1, 3 ), c( 50, 12.5, 20 ) ) ## Write to MPS file writemps( "steinh.mps", cvec, bvec, Amat, "Steinhauser" )

Index Topic optimize print.solvelp, 2 readmps, 3 solvelp, 4 summary.solvelp, 8 writemps, 9 lp, 6 print.solvelp, 2, 8 print.summary.solvelp (summary.solvelp), 8 readmps, 2, 3, 7, 8, 10 solvelp, 2, 3, 4, 8, 10 summary.solvelp, 2, 8 writemps, 2, 3, 5, 7, 8, 9 11