nlopt icon indicating copy to clipboard operation
nlopt copied to clipboard

Provide API to compute Lagrange multipliers

Open waiyujack opened this issue 4 years ago • 5 comments

I am using the package mainly via python API, I am wondering if there is a way I could get the Lagrangian multiplier from the auglag().

waiyujack avatar Jul 26 '21 15:07 waiyujack

No, the C API doesn't provide this.

Note that, given a local optimum (i.e. the NLopt result), you can easily compute Lagrange multipliers simply by solving a small least-squares problem. See e.g. https://discourse.julialang.org/t/lagrangian-function/38287/19?u=stevengj

stevengj avatar Jul 26 '21 20:07 stevengj

@stevengj Thank you for your answer!

When you mentioned local optimum, does the type of solver relevant here? Can it be a local optimum found by solvers (say MMA) other than the AUGLAG solver?

waiyujack avatar Jul 29 '21 12:07 waiyujack

The type of solver doesn't matter. For any solver that returns a local optimum, the KKT equations tell you how to compute Lagrange multipliers.

stevengj avatar Jul 30 '21 16:07 stevengj

I've renamed this issue and marked it as an "enhancement", as it would be nice to have a built-in API for this.

stevengj avatar Jul 30 '21 16:07 stevengj

@stevengj Thanks for marking this as an "enhancement".

I have a quick question on lagrangian optimisation and hope you could share some insights.

Let's say we have a maximisation problem with one inequality constraint.

Instead of solving it as a constraint problem, is there any problem of solving this as a non-constraint problem (i.e. max objective_function + lambda * constraint_function)? We solve this multiple times with different lambda values and at the end pick a lambda that suits our needs?

The reason I asked this is because solving a non-constraint problem is usually much faster than a constraint problem.

waiyujack avatar Sep 14 '21 13:09 waiyujack