Source code for gemseo.algos.opt.augmented_lagrangian.penalty_heuristic

# Copyright 2021 IRT Saint Exupéry, https://www.irt-saintexupery.com
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License version 3 as published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
"""Augmented Lagrangian penalty update scheme."""

from __future__ import annotations

from typing import TYPE_CHECKING
from typing import TypeVar

if TYPE_CHECKING:
    from gemseo.typing import RealArray

from gemseo.algos.opt.augmented_lagrangian.base_augmented_lagrangian import (
    BaseAugmentedLagrangian,
)
from gemseo.algos.opt.augmented_lagrangian.settings.penalty_heuristic_settings import (  # noqa: E501
    PenaltyHeuristicSettings,
)

T = TypeVar("T", bound=PenaltyHeuristicSettings)


[docs] class AugmentedLagrangianPenaltyHeuristic(BaseAugmentedLagrangian[T]): """This class implements the penalty update scheme of :cite:`birgin2014practical`. This class must be inherited in order to implement the function :func:`_update_lagrange_multipliers`. """ def _update_penalty( self, constraint_violation_current_iteration: float | RealArray, objective_function_current_iteration: float | RealArray, constraint_violation_previous_iteration: float | RealArray, current_penalty: float | RealArray, iteration: int, ) -> float: if iteration == 0 and constraint_violation_current_iteration > 1e-9: gamma = max( abs(objective_function_current_iteration) / constraint_violation_current_iteration, self._settings.gamma, ) elif ( constraint_violation_current_iteration > self._settings.tau * constraint_violation_previous_iteration ): gamma = self._settings.gamma else: gamma = 1.0 return min(gamma * current_penalty, self._settings.max_rho)