Skip to content

Commit

Permalink
Strongly enforce SLSQP Bounds
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewellis55 committed Sep 14, 2024
1 parent bc021e4 commit 874e821
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
4 changes: 2 additions & 2 deletions pyoptsparse/pySLSQP/pySLSQP.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ def __call__(
# SLSQP - Objective/Constraint Values Function
# =================================================================
def slfunc(m, me, la, n, f, g, x):
fobj, fcon, fail = self._masterFunc(x, ["fobj", "fcon"])
fobj, fcon, fail = self._masterFunc(np.clip(x, blx, bux), ["fobj", "fcon"])
f = fobj
g[0:m] = -fcon
slsqp.pyflush(self.getOption("IOUT"))
Expand All @@ -176,7 +176,7 @@ def slfunc(m, me, la, n, f, g, x):
# SLSQP - Objective/Constraint Gradients Function
# =================================================================
def slgrad(m, me, la, n, f, g, df, dg, x):
gobj, gcon, fail = self._masterFunc(x, ["gobj", "gcon"])
gobj, gcon, fail = self._masterFunc(np.clip(x, blx, bux), ["gobj", "gcon"])
df[0:n] = gobj.copy()
dg[0:m, 0:n] = -gcon.copy()
slsqp.pyflush(self.getOption("IOUT"))
Expand Down
14 changes: 13 additions & 1 deletion pyoptsparse/pySLSQP/source/lsq.f
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,20 @@ SUBROUTINE LSQ(M,MEQ,N,NL,LA,L,G,A,B,XL,XU,X,Y,W,JW,MODE)
CALL DCOPY (N3, W(IW+M+N), 1, Y(M+N3+1), 1)

ENDIF
call bound(n, x, xl, xu)

C END OF SUBROUTINE LSQ

END


subroutine bound(n, x, xl, xu)
integer n, i
double precision x(n), xl(n), xu(n)
do i = 1, n
if(x(i) < xl(i))then
x(i) = xl(i)
else if(x(i) > xu(i))then
x(i) = xu(i)
end if
end do
end subroutine bound

0 comments on commit 874e821

Please sign in to comment.