Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simple Academic Use Case with unexpected MMA behavior. #482

Open
SimoneConiglio opened this issue Dec 1, 2022 · 0 comments
Open

Simple Academic Use Case with unexpected MMA behavior. #482

SimoneConiglio opened this issue Dec 1, 2022 · 0 comments

Comments

@SimoneConiglio
Copy link

Hello,
Doing some tests on multiple starting guess and multiple optimization algorithm I found a case on which your solver behaves unexpectedly.
This is luckily a simple analytical example easily reproducible.

import nlopt
from numpy import array

def f(x, grad):
if grad.size > 0:
grad[0] = 2. * (x[0] - 1.)
grad[1] = 2. * (x[1] - 1.)
return (x[0] - 1.) ** 2. + (x[1] - 1.) ** 2.

def g(x, grad):
if grad.size > 0:
grad[0] = 1.
grad[1] = 1.
return x[0] + x[1] - 1.

if name == "main":
algorithm = nlopt.LD_MMA
n = 2
opt = nlopt.opt(algorithm, n)
lb = array([0., 0.])
ub = array([1., 1.])
x0 = array([0.25, 1])
opt.set_min_objective(f)
opt.set_lower_bounds(lb)
opt.set_upper_bounds(ub)
opt.add_inequality_constraint(g, 1e-3)
tol = 1e-6
maxeval = 50
opt.set_ftol_rel(tol)
opt.set_ftol_abs(tol)
opt.set_xtol_rel(tol)
opt.set_xtol_rel(tol)
opt.set_maxeval(maxeval)
opt.set_param("verbosity", 10000)
opt.set_param("inner_maxeval",10)
xopt = opt.optimize(x0)
print(xopt)
opt_val = opt.last_optimum_value()
print(opt_val)
result = opt.last_optimize_result()
print(result)

The solution to this problem is simply [0.5, 0.5] correctly spotted by LD_MMA from most initial guess but not with the starting guess [0.25,1].

In this case the log looks like that:

MMA dual converged in 6 iterations to g=0.914369:
MMA y[0]=1e+40, gc[0]=0.116025
MMA outer iteration: rho -> 0.1
MMA rhoc[0] -> 0.1
MMA dual converged in 3 iterations to g=1.34431:
MMA y[0]=1e+40, gc[0]=-0.269712
MMA outer iteration: rho -> 0.01
MMA rhoc[0] -> 0.01
MMA sigma[0] -> 0.6
MMA sigma[1] -> 0.6
MMA dual converged in 3 iterations to g=2.23837:
MMA y[0]=1e+40, gc[0]=-0.378669
MMA outer iteration: rho -> 0.001
MMA rhoc[0] -> 0.001
MMA sigma[0] -> 0.6
MMA sigma[1] -> 0.72
MMA dual converged in 3 iterations to g=2.79213:
MMA y[0]=1e+40, gc[0]=-0.454075
MMA outer iteration: rho -> 0.0001
MMA rhoc[0] -> 0.0001
MMA sigma[0] -> 0.6
MMA sigma[1] -> 0.864
MMA dual converged in 3 iterations to g=3.13745:
MMA y[0]=1e+40, gc[0]=-0.524222
MMA outer iteration: rho -> 1e-05
MMA rhoc[0] -> 1e-05
MMA sigma[0] -> 0.6
MMA sigma[1] -> 1.0368
MMA dual converged in 3 iterations to g=2.46249:
MMA y[0]=1e+40, gc[0]=-0.587037
MMA outer iteration: rho -> 1e-05
MMA rhoc[0] -> 1e-05
MMA sigma[0] -> 0.6
MMA sigma[1] -> 1.24416
MMA dual converged in 3 iterations to g=1.81718:
MMA y[0]=1e+40, gc[0]=-0.625775
MMA inner iteration: rho -> 0.0001
MMA rhoc[0] -> 1e-05
MMA dual converged in 3 iterations to g=1.81722:
MMA y[0]=1e+40, gc[0]=-0.625775
MMA inner iteration: rho -> 0.001
MMA rhoc[0] -> 1e-05
MMA dual converged in 3 iterations to g=1.81766:
MMA y[0]=1e+40, gc[0]=-0.625775
MMA inner iteration: rho -> 0.01
MMA rhoc[0] -> 1e-05
MMA dual converged in 3 iterations to g=1.82206:
MMA y[0]=1e+40, gc[0]=-0.625775
MMA inner iteration: rho -> 0.1
MMA rhoc[0] -> 1e-05
MMA dual converged in 3 iterations to g=1.86611:
MMA y[0]=1e+40, gc[0]=-0.625775
MMA inner iteration: rho -> 0.410949
MMA rhoc[0] -> 1e-05
MMA dual converged in 3 iterations to g=2.01828:
MMA y[0]=1e+40, gc[0]=-0.625775
[0.1160254 0.8660254]
0.7993602791855875
3

Your solver stops to the design point [0.1160254 0.8660254] that is nor a local minimum, nor a saddle point for the objective neither a kkt point .
I would like to have your insight on this behavior.
BRs
Simone Coniglio

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant