From 4bb42dc3bc4b3da87ab5c8be100d39b0ceb9e8ac Mon Sep 17 00:00:00 2001 From: stevenj Date: Thu, 15 Jul 2010 16:23:15 -0400 Subject: [PATCH] fix SLSQP to work with unbounded dimensions darcs-hash:20100715202315-c8de0-e93f00932885115f2a0f036bc27f5d8e7334bcfc.gz --- slsqp/README | 4 +++- slsqp/slsqp.c | 24 ++++++++++++++++-------- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/slsqp/README b/slsqp/README index 730988e..6da5fe4 100644 --- a/slsqp/README +++ b/slsqp/README @@ -35,7 +35,9 @@ Since roundoff errors sometimes pushed SLSQP's parameters slightly outside the bound constraints (not allowed by NLopt), we added checks to force the parameters within the bounds. Fixed a bug in LSEI (use of uninitialized variables) for the case where the number of equality -constraints equals the dimension of the problem. +constraints equals the dimension of the problem. The LSQ subroutine +was modified to handle infinite lower/upper bounds (in which case +those constraints are omitted). The exact line-search option is currently disabled; if we want to re-enable this (although exact line-search is usually overkill in diff --git a/slsqp/slsqp.c b/slsqp/slsqp.c index 632e261..daa472d 100644 --- a/slsqp/slsqp.c +++ b/slsqp/slsqp.c @@ -1377,9 +1377,11 @@ static void lsq_(int *m, int *meq, int *n, int *nl, dcopy___(n, &w[ip - 1 + i__], 0, &w[ip - 1 + i__], m1); /* L40: */ } - w[ip] = one; i__1 = m1 + 1; - dcopy___(n, &w[ip], 0, &w[ip], i__1); + /* SGJ, 2010: skip constraints for infinite bounds */ + for (i__ = 1; i__ <= *n; ++i__) + if (!nlopt_isinf(xl[i__])) w[(ip - i__1) + i__ * i__1] = +1.0; + /* Old code: w[ip] = one; dcopy___(n, &w[ip], 0, &w[ip], i__1); */ im = ip + *n; i__1 = *n; for (i__ = 1; i__ <= i__1; ++i__) { @@ -1387,9 +1389,11 @@ static void lsq_(int *m, int *meq, int *n, int *nl, dcopy___(n, &w[im - 1 + i__], 0, &w[im - 1 + i__], m1); /* L50: */ } - w[im] = -one; i__1 = m1 + 1; - dcopy___(n, &w[im], 0, &w[im], i__1); + /* SGJ, 2010: skip constraints for infinite bounds */ + for (i__ = 1; i__ <= *n; ++i__) + if (!nlopt_isinf(xu[i__])) w[(im - i__1) + i__ * i__1] = -1.0; + /* Old code: w[im] = -one; dcopy___(n, &w[im], 0, &w[im], i__1); */ ih = ig + m1 * *n; if (mineq > 0) { /* RECOVER H FROM LOWER PART OF B */ @@ -1399,11 +1403,15 @@ static void lsq_(int *m, int *meq, int *n, int *nl, } /* AUGMENT VECTOR H BY XL AND XU */ il = ih + mineq; - dcopy___(n, &xl[1], 1, &w[il], 1); iu = il + *n; - dcopy___(n, &xu[1], 1, &w[iu], 1); - d__1 = -one; - dscal_sl__(n, &d__1, &w[iu], 1); + /* SGJ, 2010: skip constraints for infinite bounds */ + for (i__ = 1; i__ <= *n; ++i__) { + w[(il-1) + i__] = nlopt_isinf(xl[i__]) ? 0 : xl[i__]; + w[(iu-1) + i__] = nlopt_isinf(xu[i__]) ? 0 : -xu[i__]; + } + /* Old code: dcopy___(n, &xl[1], 1, &w[il], 1); + dcopy___(n, &xu[1], 1, &w[iu], 1); + d__1 = -one; dscal_sl__(n, &d__1, &w[iu], 1); */ iw = iu + *n; i__1 = max(1,*meq); lsei_(&w[ic], &w[id], &w[ie], &w[if__], &w[ig], &w[ih], &i__1, meq, n, n, -- 2.30.2