-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Description
Original ticket http://projects.scipy.org/scipy/ticket/1231 on 2010-07-12 by trac user stevenj, assigned to unknown.
I was adapting the SLSQP code for use in another library (NLopt, ab-initio.mit.edu/nlopt), and I noticed a bug that you might want to fix. In the case where the number of equality constraints equals the dimension of the problem, valgrind reported the use of an uninitialized variable in a conditional statement. I tracked the source of the uninitialized value down to line 813 of slsqp_optmz.f in SUBROUTINE lsei:
CALL dcopy_ (mg-mc,w(mc1),0,w(mc1),1)
I believe that this should be:
CALL dcopy_ (mg,w(mc1),0,w(mc1),1)
This initializes part of the work array w to 0. If the number of inequality constraints differs from the number of dimensions (mc.NE.n in lsei), then this statement doesn't matter because w(mc1...mc1+mg-1) get overwritten anyway by the Lagrange multipliers when lsi is called a little later. But if mc.EQ.n, then the GOTO statment on line 815 jumps to the end, where w(mc1...mc1+mg-1) is used in a dot product.
I've verified that, with the above fix, it correctly solves a test problem with various numbers of equality and/or inequality constraints, and valgrind no longer complains.
PS. I should also mention that, because of rounding errors, SLSQP will occasionally evaluate the objective/constraints slightly outside of the bounding box. I'm not sure if you care about this; my NLopt library guarantees that the bound constraints are strictly honored (unlike nonlinear constraints), so I had to tweak SLSQP in a couple of places to check that rounding errors don't push the solution out of bounds.