问题
For the following minimization with objective function and constraints, boot.simplex
returns an error:
Error in tab[-pr, ] <- tab[-pr, ] - (tab[-pr, pc]/pv) %o% tab[pr, ] :
NAs are not allowed in subscripted assignments
The code is here:
library(boot)
a = c(1, 1, 1)
A2 = rbind(c(2, 7.5, 3), c(20, 5, 10))
b2 = c(10000, 30000)
simplex(a=a, A2=A2, b2=b2, maxi=FALSE)
Note that the constraints are only of the greater-than-equal-to type.
But, if a bogus less-than-or-equal-to constraint is added as shown below, a valid result is returned.
A1 = c(1, 0, 0)
b1 = 1000000
simplex(a=a, A1=A1, b1=b1, A2=A2, b2=b2, maxi=FALSE)
The optimal solution to the second attempt is below
Optimal solution has the following values
x1 x2 x3
1250 1000 0
The optimal value of the objective function is 2250.
Why is there an error with the first attempt? Is it not allowed to only use >=
type of constraints? What is a good way to approach this problem?
来源:https://stackoverflow.com/questions/55054304/r-simplex-error-nas-are-not-allowed-in-subscripted-assignments