NLopt return flag: is there a simple way to check for success?

NLopt.optimize returns a tuple (objvalue, xopt, flag), and flag is a symbol that can hold strings such as FTOL_REACHED or SUCCESS. The C API mentions that positive return values indicate success. Is there a similar way to test for success or failure with the Julia package? I can’t figure out how to get beyond a string, which I obtain using println("$flag"). I don’t see how to find an associated numerical value.

You can see the return codes here:

but unfortunately NLopt returns a Symbol instead of the enum:

So you probably just need to deal with each of the possible return values.

Or something like

is_success(ret::Symbol) = ret == :SUCCESS || endswith("$ret", "_REACHED")

Thanks, I will use this option.

1 Like