Skip to content

Commit

Permalink
Added separate module for external penalty function
Browse files Browse the repository at this point in the history
  • Loading branch information
rolfjl committed Jul 8, 2024
1 parent 6b0524b commit 751171d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
10 changes: 10 additions & 0 deletions popt/cost_functions/epf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import numpy as np

def epf(r, c_eq=0, c_iq=0):
r"""
The external penalty function, given as
.. math::
0.5r(\sum(c_eq^2) + \sum(\max(c_iq,0)^2)
"""

return r*0.5*( np.sum(c_eq**2) + np.sum(np.maximum(-c_iq,0)**2) )
3 changes: 2 additions & 1 deletion popt/cost_functions/quadratic.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import numpy as np
from popt.cost_functions.epf import epf


def quadratic(state, *args, **kwargs):
Expand All @@ -23,7 +24,7 @@ def quadratic(state, *args, **kwargs):
if r >= 0:
c_eq = g(x[:, i])
c_iq = h(x[:, i])
f[i] += r*0.5*( np.sum(c_eq**2) + np.sum(np.maximum(-c_iq,0)**2) )
f[i] += epf(r, c_eq=c_eq, c_iq=c_iq)

return f

Expand Down

0 comments on commit 751171d

Please sign in to comment.