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?
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.
simplex(a, A1 = c(1, 1), b1 = 1.0E+12, A2 = A2, b2 = b2, maxi = FALSE)