简体   繁体   English

nloptr的上限误差

[英]Upper Bound Error in nloptr

I use nloptr to model a non linear optimization problem using R.Net . 我用nloptr用来模拟一个非线性优化问题R.Net I pass initial values of the parameters to the Rscript where I define lb and ub to the variables. 我将参数的初始值传递给Rscript,然后将lbub定义为变量。

lb for all the variables is 0 whereas ub is "1" for some & "Inf" for some variables. 所有变量的lb为0,而某些变量的ub为“ 1”,某些变量的ub为“ Inf”。

When I run the model, I am continuously getting an error as 当我运行模型时,不断出现错误,因为

Additional information: Error in is.nloptr(ret) : at least one element in x0 > ub

Interestingly if I provide the same initial input data from EXCEL to "R.Script", it runs fine and I never get error about x0>ub . 有趣的是,如果我从EXCEL向“ R.Script”提供相同的初始输入数据,则它运行良好,并且我永远不会收到有关x0>ub错误。 Any insights on how to debug this or know what might be wrong? 是否有关于如何调试此功能的任何见解或可能出什么问题的见解? I can'f fathom why it would work with excel but not with C#. 我无法理解为什么它可以与excel一起使用,但不适用于C#。

Some details are below: Example: Parameters are in the form of Matrix as below (called my.data.var) 下面是一些详细信息:示例:参数采用Matrix形式,如下所示(称为my.data.var)

在此处输入图片说明

The constraints are such that sum of the second col and third col should be <=1 respectively. 约束使得第二个col和第三个col的总和分别应<= 1 ie, 在此处输入图片说明

The lb for all parameters is 0 and i define it as: 所有参数的lb为0,我将其定义为:

lb = vector("numeric",length= length(my.data.var))

ub as: ub as:

ub.matrix <- matrix(,nrow = 2, ncol=4)  
ub.matrix
for(rownum in 1:2)  
{
  ub.matrix[rownum,1] = Inf                     
  ub.matrix[rownum,4] = Inf    
  for(colnum in 2:3) 
  {
    ub.matrix[rownum,colnum] = 1              
  }
}

The constraint func is defined as: 约束函数定义为:

constraint.func <- function(my.data.var)
{
  column = 1

  constr <- vector("numeric",length = 2)   
  my.data.var.mat <- matrix(my.data.var,nrow = 2,ncol = 4,byrow = TRUE)  


  for(index in 2:3)
  {
    sum.constraint = 0
    for(prodwells in 1:2)
    {
      sum.constraint <- sum.constraint + my.data.var.mat[prodwells,index]

    }
    constr[column] <- sum.constraint - 1
    column = column+1
  }
  return(constr)

}

result <- nloptr(my.data.var,eval_f = Error.func, lb=lb,
                 ub = ub,eval_g_ineq=constraint.func,
                 opts = opts)

When I run the script, I noticed that "sum" of the first col is >1 and hence the error! 运行脚本时,我注意到第一个col的“和”> 1,因此出现错误!

目前,“ Inf”限制解决了我眼前的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM