A basic example of the simplex function in R with errors

巧了我就是萌 提交于 2019-12-02 10:42:57

问题


Good morning, I have a question to an optimization problem I can't solve in R but in Excel:

I would like to optimize the following situation (Transportation of material and people):
Airline x1 can transport 50t of material and 500 people
Airline x2 can transport 150t of material and 250 people

50x1 + 150x2 >= 900 -> Transportation of material min. 900
500x1 + 250x2 >= 2500 -> Transportation of people min. 2500

x1 is an airline with flight costs of 2500 per flight x2 is an airline with flight costs of 3500 per flight The costs should be minimized!

x1>=0
x2>=0

Here is my solution in R (function simplex from the package "boot"):

library("boot")    
a <- c(2500, 3500)
A2 <- matrix(c(50, 150, 500, 250), ncol=2, nrow=2, byrow=TRUE)
b2 <- c(900, 2500)
simplex(a, A2 = A2, b2 = b2, maxi=FALSE)

I get the following error:
Fehler in pivot(tableau, prow, pcol) : NAs nicht zugelassen in Teilbereichszuweisungen

Excels Solver gives me the exact solution: x1 = 2.4 and x2 = 5.2

Where is my error in R? I have to use the arguments A2 and b2 because of >= ... Thank's for any help!

Just a short extension: I solved the given problem using the function "solveLP" from the package "linprog" using the following syntax:

solveLP(cvec = a, bvec = b, Amat = A, 
    maximum=FALSE, const.dir=c(">=",">="))

and:

A <- matrix(c(-50,-150,-500,-250),nrow=2,ncol=2,byrow=TRUE)
a <- c(2500, 3500)
b <- c(-900, -2500)
solveLP(a,b,A,maximum=FALSE)

Still wondering why the function simplex gives me this errors?


回答1:


I don't know an exact reason (so this isn't an essential solution). But I know the error is solved when you set an upper limit with A1 and b1 even if b1 is a enormous value.

For example;
simplex(a, A1 = c(1, 1), b1 = 1.0E+12, A2 = A2, b2 = b2, maxi = FALSE)


来源:https://stackoverflow.com/questions/40437781/a-basic-example-of-the-simplex-function-in-r-with-errors

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!