Cutting Plane method to solve convex NLP with affine constratins
Project description
Durandal
Durandal is a convex NLP solver based on a successive linear programming technique. Uses the principle of supporting hyperplanes of convex functions to solve the problem. This cutting procedure is where we get the solver's name from, the legendary sword Durandal.
Currently, Durandal is very experimental and is a personal project.
Features
- - Solve NLPs via a series of converging LPs
- - Dynamic removal of cuts as they become redundant
- - Trust Region
- - A more generic LP interface for other LP solvers
Requriments (Restrictions)
- Only affine constraints are supported
- Feasible space must be bounded
- The objective function must be bounded above inside the feasible space
- The objective function must be convex (nonconvex are allowed, but no convergence guarantees are given)
How does it work?
This algorithm forms a converging sequence of upper and lower bounds on the objective function by introducing cuts in the form of supporting hyperplanes of the objective function. Additionally, the candidate solution is always feasible so that it can be interrupted at any point in the method and still yeild a feasible approximate optimum. The core kernel of this routine is the generation of supporting hyperplanes and re-optimizing the central LP problem. This re-optimization warm started as the dual of the central LP is feasible after introducing the cut. Each visited point generates a supporting hyperplane which translates to a constraint/cut in the LP.
This procedure can basically be viewed as making approximations over the epigraph of the objective function over the feasible region and refining the approximation per iteration.
Should I use it?
Is it free?
Yes
Does it work?
Yes
Example code of solving a 1D NLP
from durandal.nlp import NLP
import numpy
import matplotlib.pyplot as plt
# define the convex nonlinear objective
def f(x):
return numpy.exp(x) + x ** 2
# define the gradiant of the objective
def grad_f(x):
return numpy.exp(x) + 2 * x
# Constrain x to have mangitude up to 2, |x| <= 2
A = numpy.array([[1], [-1]])
b = numpy.array([[2], [2]])
# construct the nlp solver object
nlp = NLP(f, grad_f, A, b)
# solve the NLP with up to 3 cuts while showing output
x_approx = nlp.solve(max_cuts=3, output=True)
# start from where the last solve started off and solve for another 10 cuts while again showing outputs
x_sol = nlp.solve(max_cuts= 10, output = True)
# reconstruct the nlp solver object
nlp = NLP(f, grad_f, A, b)
# here we use a callback to record the upper and lower bounds per iteration
lower_bounds = []
upper_bounds = []
def my_callback(cb_nlp:NLP):
lower_bounds.append(cb_nlp.lb)
upper_bounds.append(cb_nlp.ub)
nlp.solve(max_cuts=5, output=False, gen_callback=my_callback)
#show the change in lower bound w.r.t. iteration
plt.plot(upper_bounds,marker='x')
plt.plot(lower_bounds,marker='o')
plt.title('Upper and Lower Bound of the optimal solution w.r.t Iteration')
plt.ylabel('f(x)')
plt.xlabel('Iteration count')
plt.legend(['Upper Bound','Lower Bound'])
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file durandal-0.0.1.tar.gz
.
File metadata
- Download URL: durandal-0.0.1.tar.gz
- Upload date:
- Size: 6.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.0 CPython/3.9.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 435907a4d0c5f6840d00e875cce5b400fd92ad161c93bcf082fadbcafbf730aa |
|
MD5 | eaaa20ac06401d627875ab9a8dfe7eba |
|
BLAKE2b-256 | 5d2f924e04c6c842b3e6e96e945007cc6eefad21e2006647698d722dcc27a204 |
File details
Details for the file durandal-0.0.1-py3-none-any.whl
.
File metadata
- Download URL: durandal-0.0.1-py3-none-any.whl
- Upload date:
- Size: 5.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.0 CPython/3.9.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7cb6a0a1cf15d5fff1a98055c17f863a7301e8ac9d1d6d8f27d84f0b279d2547 |
|
MD5 | 366ea27e54141d3617f5ef2ef25a52ef |
|
BLAKE2b-256 | f00af6b595129a13b053e7335b5ad429ceb93ea06a93fb14502d424d4c98165d |