R: Simplex error: NAs are not allowed in subscripted assignments

一笑奈何 提交于 2020-01-04 18:01:52

问题


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

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