Skip to main content

A Python library for linear, nonlinear, and integer programming

Project description

Optimization Library

A Python library for solving linear, nonlinear, and integer programming problems. The library provides a collection of optimization algorithms for tasks such as the diet problem, model parameter optimization, and the 0-1 knapsack problem.

Features

  • Linear Programming: Solve problems like the diet problem using methods such as Simplex, Relaxation, Column Generation, ADMM, and Mirror Descent.
  • Nonlinear Programming: Optimize model parameters with methods like Gradient Descent, Newton's Method, Steepest Descent, Adam, and Nelder-Mead.
  • Integer Programming: Solve the 0-1 knapsack problem using Branch and Bound, Gomory Cuts, Cutting Planes, Lagrangian Relaxation, and Sherali-Adams (Level 1).
  • Visualization and logging of optimization results using Matplotlib and Pandas.

Installation

Install the library using pip:

pip install optimization-library

Requirements

  • numpy~=2.3.0
  • cvxpy~=1.6.5
  • pandas~=2.3.0
  • matplotlib~=3.10.3
  • PuLP~=3.2.1
  • scipy~=1.15.3
  • openpyxl~=3.1.5

Usage

Linear Programming

import numpy as np
from optimization_library import solve_lp, post_processing_linear_approximation_logs

c = np.array([3, 2], dtype=float)
A = np.array([[1, 1], [2, 1]], dtype=float)
b = np.array([4, 5], dtype=float)
methods = ["simplex", "ADMM"]

results = [solve_lp(method, c, A, b, epsi=1e-6, is_maximization=True) for method in methods]
post_processing_linear_approximation_logs(results, visual=True, file_print=True)

Nonlinear Programming

import numpy as np
from optimization_library import solve_nlp, post_processing_non_linear_approximation_logs

t = np.linspace(0, 2 * np.pi, 10)
y = np.exp(-0.5 * t) + np.sin(-1.2 * t)
model = lambda x, t: np.exp(-x[0] * t) + np.sin(x[1] * t)
x0 = [0.25, 0.25]
bounds = [(-3.5, 2.5), (-4.2, 2.8)]
methods = ["adam", "nelder-mead"]

results = [solve_nlp(method, x0, t, y, model=model, bounds=bounds, epsilon=1e-6) for method in methods]
post_processing_non_linear_approximation_logs(results, visual=True, file_print=True)

Integer Programming

from optimization_library import solve_ip, post_processing_integer_approximation_logs

weights = [2, 3, 4, 5]
values = [3, 4, 5, 6]
capacity = 10
methods = ["branch_and_bound", "gomory"]

results = [solve_ip(method, weights, values, capacity, epsilon=1e-4) for method in methods]
post_processing_integer_approximation_logs(results, visual=True, file_print=True)

Examples

A console application demonstrating the usage of the library is available in the GitHub repository under the examples/ directory. Run it with:

git clone https://github.com/UWFms/optimization-library.git
cd optimization-library
python -m venv venv
venv\Scripts\activate
pip install -r requirements.txt
python example\main.py

License

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

Contributing

Contributions are welcome! Please submit issues or pull requests to the GitHub repository https://github.com/UWFms/optimization-library.

Documentation

Full documentation is available at https://disk.yandex.ru/i/k7wqcUCCx1Ym9Q.

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

optimization_library-1.0.4.tar.gz (18.9 kB view details)

Uploaded Source

Built Distribution

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

optimization_library-1.0.4-py3-none-any.whl (21.3 kB view details)

Uploaded Python 3

File details

Details for the file optimization_library-1.0.4.tar.gz.

File metadata

  • Download URL: optimization_library-1.0.4.tar.gz
  • Upload date:
  • Size: 18.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.0

File hashes

Hashes for optimization_library-1.0.4.tar.gz
Algorithm Hash digest
SHA256 accb979351c447f8e7aa4961869c4e2eb0ec5a235815f6ef0044ffe5b3b18530
MD5 a4c1d7d97abcac8d9b3531b89b745404
BLAKE2b-256 ac238250049b751fe5716b4fa93b37f085dd014a4e6b67520aac53e5b4598cb1

See more details on using hashes here.

File details

Details for the file optimization_library-1.0.4-py3-none-any.whl.

File metadata

File hashes

Hashes for optimization_library-1.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 180532809e191cabd9dbcbaf81ecc2e3e03202611a4e646732095eac4c7a6e30
MD5 d3fba62b0f3c75436594a2611dfefa00
BLAKE2b-256 9da0d0bc014d801049d72bbe54791d528ad4cf409b9ba8246f7f02efbbf3f03b

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