Hello,
I created a simple example with an always violated constraint, which
leads to result_code = 4
The simple problem reads
f = 1.0
g = 1.0
The python code
#----- START
import nlopt
from numpy import *
def f(x, grad):
print "f(",x,") = 1.0"
if grad.size > 0:
grad[0] = 0.0
return 1.0
def g(x, grad):
""" a always violated constraint
"""
print "g(",x,") = 1.0"
if grad.size > 0:
grad[0] = 0.0
return 1.0
opt = nlopt.opt(nlopt.LN_COBYLA, 1)
opt.set_min_objective(f)
opt.add_inequality_constraint(g, 1e-8)
opt.set_xtol_rel(1e-4)
x = opt.optimize([0.])
minf = opt.last_optimum_value()
print "===="
print "optimum at ", x[0]
print "minimum value = ", minf
print "result code = ", opt.last_optimize_result()
#----- END
leads to
f( [ 0.] ) = 1.0
g( [ 0.] ) = 1.0
f( [ 1.] ) = 1.0
g( [ 1.] ) = 1.0
f( [ 0.06484107] ) = 1.0
g( [ 0.06484107] ) = 1.0
f( [ 0.00277096] ) = 1.0
g( [ 0.00277096] ) = 1.0
f( [ 0.00515376] ) = 1.0
g( [ 0.00515376] ) = 1.0
f( [ 0.00068367] ) = 1.0
g( [ 0.00068367] ) = 1.0
f( [ 0.00010929] ) = 1.0
g( [ 0.00010929] ) = 1.0
====
optimum at 0.0
minimum value = 1.0
result code = 4
Why is there no information about the violated constraint?
Result code NLOPT_XTOL_REACHED = 4: Optimization stopped because
xtol_rel or xtol_abs (above) was reached.
I use NLOPT 2.2.4.
Kind regards
Alexander Riess
_______________________________________________
NLopt-discuss mailing list
[email protected]
http://ab-initio.mit.edu/cgi-bin/mailman/listinfo/nlopt-discuss