0

I use nloptr to model a non linear optimization problem using R.Net . I pass initial values of the parameters to the Rscript where I define lb and ubto the variables.

lb for all the variables is 0 whereas ubis "1" for some & "Inf" for some variables.

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. 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#.

Some details are below: Example: Parameters are in the form of Matrix as below (called my.data.var)

enter image description here

The constraints are such that sum of the second col and third col should be <=1 respectively. i.e, enter image description here

The lb for all parameters is 0 and i define it as:

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

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!

Modi
  • 143
  • 1
  • 13
  • 3
    can you make this reproducible? – shayaa Aug 17 '16 at 04:45
  • 2
    You are basically posting _only_ an error message and asking us what went wrong. – IRTFM Aug 17 '16 at 05:55
  • Interesting problem! I'll be happy to look at it as soon as I can reproduce it :D – renato vitolo Aug 17 '16 at 08:28
  • @renatovitolo : added code. – Modi Aug 17 '16 at 14:27
  • @42- : Added code. – Modi Aug 17 '16 at 14:27
  • @shayaa: added more information with code. – Modi Aug 17 '16 at 14:29
  • 1
    We are closer to reproducibility, but not quite there yet. `my.data.matrix.prod` and `my.data.matrix.inj` are defined as integers, but in fact they should be matrices: you call `ncol()` on them both to construct `ub` and within the constraint function. Also: do I see it correctly that `my.data.var <- matrix(c(30,25,0.3,0.5,0.2,0.6,30,60), nrow=2)`? Lastly: could you also please add the call (or sequence of commands) where you "run the model", resulting in the error in `is.nloptr(ret)`? – renato vitolo Aug 17 '16 at 17:22
  • Good catch. I updated the code. It's actually ncol(my.data.matrix.prod) = 2 and ncol(my.data.matrix.inj) = 2. Yes your understanding of my.data.var is correct! @renatovitolo – Modi Aug 17 '16 at 18:36
  • 1. I still do not see the call (or sequence of commands) where you "run the model", resulting in the error in `is.nloptr(ret)`; therefore, I cannot reproduce your problem. 2. `ncol(my.data.matrix.prod) = 2` is not correct; for the purposes of this example you probably intend to define an auxiliary variable `ncol.my.data.matrix.prod = 2` and substitute `ncol.my.data.matrix.prod` to all occurrences of `ncol(my.data.matrix.prod)` -- and the same for `ncol(my.data.matrix.inj)` should this be correct, could you please update your code? – renato vitolo Aug 17 '16 at 18:47
  • @renatovitolo : Modified sir. See the last section of the code. That's where I call the function. – Modi Aug 22 '16 at 22:07
  • The definition of `Error.func` is still missing: example is not reproducible. – renato vitolo Aug 24 '16 at 00:20

1 Answers1

0

Currently the "Inf" limit solves my problem at hand.

Modi
  • 143
  • 1
  • 13