software R

© All Rights Reserved

5 views

software R

© All Rights Reserved

- B Simplex Method
- 4. Linear Programming (1)
- Class Work 8 Solutions
- ADS - A Fortran Program for Automated Design Synthesis
- 50
- hw1
- Linear and Nonlinear Programming
- lineer
- The Lost Art of Planning.pdf
- Mb00 48operaton Research
- Simplex Algorithm
- Motion Optimization EBM
- BE Strategic Bidding
- TopTenSecretstosuccess WithOptimization
- 716-11 Linear Programming II.pdf
- Warehouse Design Review
- Modeling and Linera Programming With R
- Jabari 2015
- Linear Programming
- Optimization of Injection Molding Design. Part II: Molding Conditions Optimization

You are on page 1of 11

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

Description

This method prints the results of the Linear Programming algorithm.

Usage

## S3 method for class 'solveLP'

print( x, digits=6, ...)

Arguments

x an object returned by solveLP.

digits number of digits to print.

... currently ignored.

Value

print.solveLP invisibly returns the object given in argument x.

Author(s)

Arne Henningsen

See Also

solveLP, summary.solveLP, readMps, writeMps

Examples

## Not run: library( linprog )

## Production activities

cvec <- c(1800, 600, 600) # gross margins

names(cvec) <- c("Milk","Bulls","Pigs")

bvec <- c(40, 90, 2500) # endowment

names(bvec) <- c("Land","Stable","Labor")

Amat <- rbind( c( 0.7, 0.35, 0 ),

c( 1.5, 1, 3 ),

c( 50, 12.5, 20 ) )

readMps 3

res <- solveLP( cvec, bvec, Amat, TRUE )

print( res )

Description

This function reads MPS files - the standard format for Linear Programming problems.

Usage

readMps( file, solve=FALSE, maximum=FALSE )

Arguments

file 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)?

Details

Equality constraints and ’greater than’-bounds are not implemented yet.

Value

readMps returns a list containing following objects:

cvec vector c.

bvec vector b.

Amat matrix A.

res if solve is TRUE, it contains the results of the solving process (an object of

class solveLP).

Author(s)

Arne Henningsen

See Also

solveLP, writeMps

4 solveLP

Examples

## Production activities

cvec <- c(1800, 600, 600) # gross margins

names(cvec) <- c("Cows","Bulls","Pigs")

bvec <- c(40, 90, 2500) # endowment

names(bvec) <- c("Land","Stable","Labor")

Amat <- rbind( c( 0.7, 0.35, 0 ),

c( 1.5, 1, 3 ),

c( 50, 12.5, 20 ) )

writeMps( "steinh.mps", cvec, bvec, Amat, "Steinhauser" )

rm( cvec, bvec, Amat )

lp <- readMps( "steinh.mps", TRUE, TRUE )

lp$res

Description

Note that the inequality signs <= of the individual linear constraints in Ax <= b can be changed

with argument const.dir.

Usage

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 vector c (containing n elements).

bvec vector b (containing m elements).

Amat matrix A (of dimension m × n).

maximum logical. Should we maximize or minimize (the default)?

const.dir 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.)

maxiter maximum number of iterations.

zero numbers smaller than this value (in absolute terms) are set to zero.

tol if the constraints are violated by more than this number, the returned component

status is set to 3.

dualtol if the constraints in the dual problem are violated by more than this number, the

returned status is non-zero.

lpSolve logical. Should the package ’lpSolve’ be used to solve the LP problem?

solve.dual logical value indicating if the dual problem should also be solved.

verbose 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 installa-

tion 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:

solution vector of optimal values of the variables.

iter1 iterations of Simplex algorithm in phase 1.

6 solveLP

basvar vector of basic (=non-zero) variables (at optimum).

con 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.

allvar 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.

status 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 speci-

fied by argument maxiter.

lpStatus numeric. Return code of lp (only if argument lpSolve is TRUE).

dualStatus numeric. Return code from solving the dual problem (only if argument solve.dual

is TRUE).

maximum logical. Indicates whether the objective function was maximized or minimized.

Tab final ’Tableau’ of the Simplex algorith.

lpSolve logical. Has the package ’lpSolve’ been used to solve the LP problem.

solve.dual logical. Argument solve.dual.

maxiter numeric. Argument maxiter.

Author(s)

Arne Henningsen

References

Dantzig, George B. (1951), Maximization of a linear function of variables subject to linear inequal-

ities, 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

## Production activities

cvec <- c(1800, 600, 600) # gross margins

names(cvec) <- c("Cows","Bulls","Pigs")

bvec <- c(40, 90, 2500) # endowment

names(bvec) <- c("Land","Stable","Labor")

Amat <- rbind( c( 0.7, 0.35, 0 ),

c( 1.5, 1, 3 ),

c( 50, 12.5, 20 ) )

solveLP( cvec, bvec, Amat, TRUE )

## Two types of Feed

cvec <- c(2.5, 2 ) # prices of feed

names(cvec) <- c("Feed1","Feed2")

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 ) )

solveLP( cvec, bvec, Amat )

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

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 )

Description

These methods prepare and print summary results of the Linear Programming algorithm.

Usage

summary(object,...)

## S3 method for class 'summary.solveLP'

print(x,...)

Arguments

x an object returned by summary.solveLP.

... currently ignored.

Value

bly returns the object given in argument x.

Author(s)

Arne Henningsen

See Also

writeMps 9

Examples

## Not run: library( linprog )

## Production activities

cvec <- c(1800, 600, 600) # gross margins

names(cvec) <- c("Milk","Bulls","Pigs")

bvec <- c(40, 90, 2500) # endowment

names(bvec) <- c("Land","Stable","Labor")

Amat <- rbind( c( 0.7, 0.35, 0 ),

c( 1.5, 1, 3 ),

c( 50, 12.5, 20 ) )

res <- solveLP( cvec, bvec, Amat, TRUE )

summary( res )

Description

This function writes MPS files - the standard format for Linear Programming problems.

Usage

writeMps( file, cvec, bvec, Amat, name="LP" )

Arguments

file a character string naming the file to write.

cvec vector c.

bvec vector b.

Amat matrix A.

name an optional name for the Linear Programming problem.

Details

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

## Production activities

cvec <- c(1800, 600, 600) # gross margins

names(cvec) <- c("Cows","Bulls","Pigs")

bvec <- c(40, 90, 2500) # endowment

names(bvec) <- c("Land","Stable","Labor")

Amat <- rbind( c( 0.7, 0.35, 0 ),

c( 1.5, 1, 3 ),

c( 50, 12.5, 20 ) )

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

- B Simplex MethodUploaded byUtkarsh Sethi
- 4. Linear Programming (1)Uploaded byBench Gueco
- Class Work 8 SolutionsUploaded bykhairun hafizah
- ADS - A Fortran Program for Automated Design SynthesisUploaded bydavebrackett
- 50Uploaded byazzzami
- hw1Uploaded bySouleymane Coulibaly
- Linear and Nonlinear ProgrammingUploaded byLogan J. Rabuogi
- lineerUploaded byسلطان الورررد
- The Lost Art of Planning.pdfUploaded bySandip Ghosh
- Mb00 48operaton ResearchUploaded byDevendra Kachhi
- Simplex AlgorithmUploaded byVaibhav Sharma
- Motion Optimization EBMUploaded byAvk Sanjeevan
- BE Strategic BiddingUploaded bykaren dejo
- TopTenSecretstosuccess WithOptimizationUploaded byPaula Ignacia Romero Matus
- 716-11 Linear Programming II.pdfUploaded byTanveerAhmad
- Warehouse Design ReviewUploaded byDiogoMorgado
- Modeling and Linera Programming With RUploaded byabdulahmed1018
- Jabari 2015Uploaded byMuhamadFaisalAli
- Linear ProgrammingUploaded byJhia Andrada
- Optimization of Injection Molding Design. Part II: Molding Conditions OptimizationUploaded byaenyma
- Exercises 2 Opt R1Uploaded byWala' Saleh
- Application of a Simplex Method to Find the Optimal SolutionUploaded byInternational Journal of Innovations in Engineering and Science
- Unbounded SolutionUploaded byHunain Memon
- Linear Programming 1Uploaded byDrRitu Malik
- resuleltosalex1Uploaded byChristian Inga Vallejos
- LP Detailed Solution Simplex 1Uploaded byDio Nolasco
- 3.4-16 edited.docxUploaded byKricel Maquera
- Lexicographic multi-objective programs.pdfUploaded byRavit Anand
- WRITTEN VISUAL REPORT.docxUploaded byNicolas Ohina
- Week3-Assignment-Solutions.pdfUploaded byshubh

- Simulation Moduling & Analysis 1Uploaded byMario Filino
- ADS 33E RotorcraftUploaded byEmmanuel
- Numerical Linear.pdfUploaded byPurushotham Prasad K
- Beamer IntroUploaded bykapil2604
- lpSolveUploaded byMauricio Azálgara Bedoya
- MCADUploaded byEmmanuel
- Simulation practical exemplesUploaded byEmmanuel
- MainUploaded byEmmanuel
- Health - Target Heart RateUploaded byEmmanuel
- Optimisation of the Simona Research Simulator’s Motion Filter Settings for Handling Qualities ExperimentsUploaded byEmmanuel
- nahon1990Uploaded bydaos28
- Math - Pythagorean Theorem.txtUploaded byEmmanuel
- AC2147 - Flight Test SafetyUploaded byEmmanuel
- AppDUploaded byArvind Shukla
- R-intro.pdfUploaded byPrathap Veera
- SAS BigData FinalUploaded byDevika Radjkoemar
- lpSolveAPIUploaded byEmmanuel
- Scheduling and Routing Models for Airline Systems - Simpson - MITUploaded byEmmanuel
- Ada 402711Uploaded byEmmanuel
- Mistura.txtUploaded byEmmanuel
- MIL PRF 5096FUploaded byEmmanuel
- as-332_rev 5 - MASTER MELUploaded byEmmanuel
- as-350_rev 6b - Master MELUploaded byEmmanuel
- Master MEL (as-365 r4)Uploaded byEmmanuel
- Washout Filter Design for a Motorcycle SimulatorUploaded byEmmanuel
- Answer Key - Practice Test 2Uploaded byEmre Özarslan
- Missing PagesUploaded byGoktug Atik
- HVDC notes.pdfUploaded byBMS_SOFTGUY

- FiberLinX OverviewUploaded byConstantin Tuca
- AUTOMATIC RAILWAY GATE CONTROLUploaded byThamarai Ramu
- ETL Testing CV(1)Uploaded byhemanth kumar p
- Using Multiple CursorsUploaded byCatalina Achim
- Ban Notification Maharashtra. CB1198675309Uploaded bygiri xda
- Saptechnical Com Tutorials ExitsBADIs ME21N Index HtmUploaded bytttas
- Allen and Overy Litigation Support Officer JDUploaded byJack Sawyer
- Caepipe RoadmapUploaded byDanem Halas
- SSOWPUploaded bymbhangale
- Met a Cam BrochureUploaded byKevin Baxter
- at_apiUploaded bySreenivasa_Kam_2307
- Superb O-c CycleUploaded bySurendra Babu
- Icm System Rev-draft2Uploaded byFreddy Odon Flores
- DBASEIIIPlusLevel1.HtmUploaded bychelitas15
- group1.docxUploaded byNiranjan Godage
- Erp Demystified eBook PDFUploaded byVictoria
- IT Revolution DevOps Guide v1Uploaded byaaht143195
- 50b7535e-bf7c-0010-82c7-eda71af511fa.pdfUploaded bysridhar
- 20PM manual.pdfUploaded byBarrera Orlando
- 3900 Series Multi-Mode Base Station Commissioning Guide (PDF)-ENUploaded byadramat1085
- EE390Uploaded bykundan_pandey_3
- Load Testing Best Practices Using Web LoadUploaded byaustinfru7
- ETSI TS 102 361-3Uploaded byraytahmasebi77
- MRPUploaded byPrashant Kalaskar
- SAP Data ArchivingUploaded bygowthamigamidi
- Cat Ethernet Converter UkUploaded byNour Elimane
- KIDDElit Literature LibraryUploaded bykukuh_subiarto
- Nokia 2330c UG EnhkUploaded byarun_cavale
- Installation Guide R18 EnUploaded byudindaur
- CSS3 IntroductionUploaded byguruannamalai

## Much more than documents.

Discover everything Scribd has to offer, including books and audiobooks from major publishers.

Cancel anytime.