Skip to main content

A Python implementation of the Augmented Lagrangian method for constrained optimization

Project description

Augmented Lagrangian

A Python implementation of the Augmented Lagrangian method for constrained optimization problems.

Overview

The Augmented Lagrangian method is a powerful technique for solving constrained optimization problems of the form:

minimize   f(x)
subject to c_i(x) = 0  for i = 1, ..., m

This package provides a flexible and easy-to-use implementation that can handle both single and multiple equality constraints.

Features

  • Flexible constraint handling: Support for single or multiple equality constraints
  • Customizable parameters: Control penalty parameters, tolerances, and iteration limits
  • Convergence monitoring: Track optimization progress with detailed history
  • Easy-to-use API: Simple interface for defining objective and constraint functions
  • Robust implementation: Built on top of SciPy's optimization routines

Installation

pip install augmented-lagrangian

Quick Start

Here's a simple example of using the Augmented Lagrangian solver:

import numpy as np
from augmented_lagrangian import AugmentedLagrangian

# Define objective function: minimize (x1 - 1)^2 + (x2 - 2)^2
def objective(x):
    return (x[0] - 1)**2 + (x[1] - 2)**2

# Define constraint: x1 + x2 - 3 = 0
def constraint(x):
    return x[0] + x[1] - 3

# Create solver instance
solver = AugmentedLagrangian(
    objective_func=objective,
    constraint_funcs=constraint,
    tolerance=1e-6,
    verbose=True
)

# Solve the problem
x0 = np.array([0.0, 0.0])  # Initial guess
result = solver.solve(x0)

print(f"Solution: x = {result['x']}")
print(f"Objective value: {result['fun']}")
print(f"Constraint violation: {result['constraint_violation']}")

API Reference

AugmentedLagrangian Class

Constructor Parameters

  • objective_func: Function to minimize f(x)
  • constraint_funcs: Single constraint function or list of constraint functions
  • mu_0: Initial penalty parameter (default: 1.0)
  • tolerance: Convergence tolerance (default: 1e-6)
  • mu_increase_factor: Factor to increase penalty parameter (default: 1.5)
  • max_mu: Maximum penalty parameter value (default: 1000.0)
  • constraint_tolerance: Tolerance for constraint satisfaction (default: 1e-4)
  • max_outer_iterations: Maximum outer iterations (default: 20)
  • max_inner_iterations: Maximum inner iterations per subproblem (default: 50)
  • verbose: Whether to print optimization progress (default: True)

Methods

  • solve(x0, max_outer_iterations=100, tolerance=1e-6): Solve the optimization problem
  • set_functions(objective_func, constraint_funcs): Set objective and constraint functions

Multiple Constraints Example

import numpy as np
from augmented_lagrangian import AugmentedLagrangian

# Objective function
def objective(x):
    return x[0]**2 + x[1]**2

# Multiple constraints
def constraint1(x):
    return x[0] + x[1] - 1

def constraint2(x):
    return x[0] - x[1]

# Create solver with multiple constraints
solver = AugmentedLagrangian(
    objective_func=objective,
    constraint_funcs=[constraint1, constraint2]
)

# Solve
x0 = np.array([0.0, 0.0])
result = solver.solve(x0)

Algorithm Details

The Augmented Lagrangian method combines the objective function with penalty terms for constraint violations:

L_A(x, λ, μ) = f(x) - Σ λ_i * c_i(x) + (μ/2) * Σ c_i(x)²

Where:

  • f(x) is the objective function
  • c_i(x) are the constraint functions
  • λ_i are the Lagrange multipliers
  • μ is the penalty parameter

The algorithm iteratively:

  1. Minimizes the augmented Lagrangian with respect to x
  2. Updates the Lagrange multipliers: λ := λ - μ * c(x)
  3. Increases the penalty parameter if needed
  4. Repeats until convergence

Requirements

  • Python >= 3.8
  • NumPy >= 1.20.0
  • SciPy >= 1.7.0

License

This project is licensed under the MIT License - see the LICENSE file for details.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Citation

If you use this package in your research, please consider citing:

@software{augmented_lagrangian,
  title={Augmented Lagrangian: A Python Implementation},
  author={Hongwei Jin},
  year={2025},
  url={https://github.com/cshjin/augmented-lagrangian}
}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

augmented_lagrangian-0.1.0.tar.gz (11.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

augmented_lagrangian-0.1.0-py3-none-any.whl (4.1 kB view details)

Uploaded Python 3

File details

Details for the file augmented_lagrangian-0.1.0.tar.gz.

File metadata

  • Download URL: augmented_lagrangian-0.1.0.tar.gz
  • Upload date:
  • Size: 11.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.9

File hashes

Hashes for augmented_lagrangian-0.1.0.tar.gz
Algorithm Hash digest
SHA256 4b07f49960cd2e4c6474334ac8f60183198abae8520f0fb9faca84a1607fb90c
MD5 16707b95bff4a0837328117bbd729929
BLAKE2b-256 7a9244e5b5830d00e09522420abebc142de46d23d6f2418068d4c1f49c13f1ba

See more details on using hashes here.

File details

Details for the file augmented_lagrangian-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for augmented_lagrangian-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e25b0b3819c4bfbb5f2031847f37d2e010d665adf1f3caa1d70d9190318f979d
MD5 4bf2ce4e49621180b802e1995f561e24
BLAKE2b-256 cb599dfc6fe738f7007630aa921cf6ac7e107e2d55c8cdf93ea98abd1cdf5567

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page