-1

For example, if I use the code below on APMonitor Modeling Language

 Variables
   x2 >=0, <=100
   x3 >=0, <=100
 End Variables

 Equations
   x2>=0
   x3>=0

   ! best known objective = 
   minimize ((0.5-x2)/(0.5-x2+x3))/0.3
 End Equations
End Model

I get:

    Successful Solution
    Objective Value = 3.33333333
Name    Lower   Value   Upper
ss.x2   0.0000E+00  1.4333E+01  1.0000E+02
ss.x3   0.0000E+00  0.0000E+00  1.0000E+02
ss.slk_1    0.0000E+00  0.0000E+00  ---

But when I try doing the same optimization in R using DEoptim

f<- function(x){
x2 <- x[2]    #should be x[1]
x3 <- x[3]    #should be x[2]
(((0.5-x2)/(0.5-x2+x3))/0.2)  #note the minor but inconsequential difference
}

set.seed(1234)
DEoptim(f, lower = c(0,0), upper = c(100,100), DEoptim.control(NP = 100))
outDEoptim <- DEoptim(f, lower = c(0,0), upper = c(100,100),DEoptim.control(trace = TRUE, NP = 80,
itermax = 1000, F = 1.2, CR = 0.7))
plot(outDEoptim)
outDEoptim

I get very different and strange results:

$`optim`
$`optim`$`bestmem`
    par1     par2 
46.57015 46.07015 

$`optim`$bestval
[1] -Inf

$`optim`$nfeval
[1] 330

$`optim`$iter
[1] 164

Obviously, there is something I am missing. Thanks in advance for any help.

IRTFM
  • 258,963
  • 21
  • 364
  • 487
Krantz
  • 1,424
  • 1
  • 12
  • 31
  • The APmodeling result is clearly wrong (or perhaps addressing a different problem?) The objective is clearly not minimized at that set of values, whereas DEoptim did find one of the infinite possible minima. – IRTFM May 06 '19 at 14:44
  • There’s a CRAN Task View on Optimization. – IRTFM May 06 '19 at 17:16
  • Very helpful. Thanks! – Krantz May 06 '19 at 17:33

1 Answers1

1

Consider;

x2=0
x3=0
((0.5-x2)/(0.5-x2+x3))
#[1] 1
x2=0.9367799;x3= 0.4367799
((0.5-x2)/(0.5-x2+x3))
[#1] -Inf

Maybe you should look at a grid of values for that objective across the space of permitted domain. ISTR that the Rosenbrock function is kind of "banana"-shaped: https://en.wikipedia.org/wiki/Rosenbrock_function . Doesn't look like the Rosenbrock function. For the modified function, the DEoptim is finding a solution when (5-x2+x3) == 0, which is true anytime that x2-x3==0.5 and there are an infinite number of such all in a straight line.

x2= seq(0,0.9999,len=10)
x3= seq(0,0.9999,len=10)
round(outer(x2,x3, FUN=function(x2,x3) {(0.5-x2)/(0.5-x2+x3)} ) ,2)
#----------------------------------------
      [,1]  [,2]  [,3]  [,4]  [,5]  [,6]  [,7]  [,8]  [,9] [,10]
 [1,]    1  0.82  0.69  0.60  0.53  0.47  0.43  0.39  0.36  0.33
 [2,]    1  0.78  0.64  0.54  0.47  0.41  0.37  0.33  0.30  0.28
 [3,]    1  0.71  0.56  0.45  0.38  0.33  0.29  0.26  0.24  0.22
 [4,]    1  0.60  0.43  0.33  0.27  0.23  0.20  0.18  0.16  0.14
 [5,]    1  0.33  0.20  0.14  0.11  0.09  0.08  0.07  0.06  0.05
 [6,]    1 -1.00 -0.33 -0.20 -0.14 -0.11 -0.09 -0.08 -0.07 -0.06
 [7,]    1  3.00 -3.00 -1.00 -0.60 -0.43 -0.33 -0.27 -0.23 -0.20
 [8,]    1  1.67  5.00 -4.99 -1.67 -1.00 -0.71 -0.56 -0.45 -0.38
 [9,]    1  1.40  2.33  7.01 -6.99 -2.33 -1.40 -1.00 -0.78 -0.64
[10,]    1  1.29  1.80  3.00  9.01 -8.99 -3.00 -1.80 -1.29 -1.00

I suppose it's possible there is some aspect of the phrase "best known objective" with which I am entirely ignorant, and if so, I'm guessing that DEoptim has not been informed of that knowledge either.

IRTFM
  • 258,963
  • 21
  • 364
  • 487
  • Thanks, Hans. I know this is your domain of expertise and I recommend anyone viewing this to heed your advice. Do you not think it would be informative to create a grid across the domain? – IRTFM May 06 '19 at 03:04
  • Agree with the comments by Hans W. Your `f`-function code is incorrect, as well. There are only 2 parameters so asking for x[3] should have thrown an error. There will be division by zero any time that (0.5-x2+x3)==0. And there will be an infinite number of such instances. Again you should use `outer` or a loop to get a rough idea of the behavior of your function. – IRTFM May 06 '19 at 14:32
  • I agree with the points raised about my objective function. Nevertheless, that was only a test objective function to easily visualize the problem I was facing. True - I should have come up with a better test objective function. Nevertheless, after seeing this post https://stackoverflow.com/questions/48037805/nonlinear-optimization-with-r-for-grouped-variables I have been able to solve my problem. Also, thanks @42- for the idea of grid. That was really helpful in solving my problem. Regards. – Krantz May 06 '19 at 16:57