R:单纯形错误:下标分配中不允许使用NA [英] R: Simplex error: NAs are not allowed in subscripted assignments

查看:97
本文介绍了R:单纯形错误:下标分配中不允许使用NA的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于以下具有目标功能和约束的最小化, boot.simplex 返回错误:

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

代码在这里:

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?

推荐答案

我更改了默认eps的值,它对我有用.默认值为 eps = 1e-10 ,请尝试增加它.

I changed the value of the default eps, and it works for me. The default is eps=1e-10, try to increase it.

simplex(a=a, A2=A2, b2=b2, maxi=FALSE, eps=1e-6)

这篇关于R:单纯形错误:下标分配中不允许使用NA的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆