Optimizing with IPOPT

IPOPT (Interior Point OPTimizer) is a software package for large-scale ​nonlinear optimization, designed to find local solutions of mathematical optimization problems.

IPOPTLink is a Wolfram System application that uses Wolfram LibraryLink to link to IPOPT functions. IPOPTLink provides, among others, the functions IPOPTMinimize and ParametricIPOPTMinimize. These functions can be used for local minimization with or without parameters. They may be automatically called by optimization functions such as FindMinimum.

Use FindMinimum with the IPOPT solver.
In[1]:=
Click for copyable input
Out[1]=

However, IPOPTLink functions can also be called directly providing a more flexible way to use the functionality implemented in IPOPT.

IPOPTMinimizecompute local minimum using IPOPT
IPOPTDatadata expression returned by IPOPTMinimize
IPOPTMinValuegets the minimal objective value from IPOPTData expression
IPOPTArgMingets the local minimum position from IPOPTData expression
ParametricIPOPTMinimizecompute local minimum with parameters using IPOPT

Basic IPOPTLink functions.

IPOPT is designed to find local solutions of mathematical constrained optimization problems in dimensions. Constrained optimization problems are problems for which a real valued function of several variables , referred to as the objective function, is to be minimized subject to constraints. Two types of constraints may be specified -- either variable bound constraints or constraints defined by functions. Variable bound constraints are of the form where x=(x1,,xn). Function constraints are of the form .

Depending on the type of constraints IPOPTMinimize can be used in the following three ways :

IPOPTMinimize[f(x),x,x0]unconstrained minimization
IPOPTMinimize[f(x),x,x0,xbounds]bound constrained minimization
IPOPTMinimize[f(x),x,x0,xbounds,g(x),gbounds]constrained minimization by function constraints and variable bounds

IPOPTMinimize usages.

Maximizing an objective function can be done by minimizing the negative of the function to maximize.

Unconstrained minimization

IPOPTMinimize[f,{x1,},{x1i0,}]unconstrained minimization

IPOPTMinimize unconstrained minimization.

In order to use IPOPTLink the package needs to be loaded.

Load the IPOPTLink package.
In[2]:=
Click for copyable input

As an initial example, find a local minimum of starting from .

Plot the objective function.
In[3]:=
Click for copyable input
Out[3]=

Call the IPOPT solver using IPOPTMinimize with objective function , argument variables {} and initial value }.

Minimize starting from x=10.
In[4]:=
Click for copyable input
Out[4]=

IPOPTMinimize returns an IPOPTData object. This object contains the minimal value.

Extract the minimal objective function value from the IPOPTData object.
In[5]:=
Click for copyable input
Out[5]=

The IPOPTData object also contains the coordinate point at which the minimum was found.

Extract the minimization point from the IPOPTData object.
In[6]:=
Click for copyable input
Out[6]=
Plot the objective function with the location of the local minimum found.
In[7]:=
Click for copyable input
Out[7]=

Bound constrained minimization

IPOPTMinimize[f,{x1,},{x1i0,},{{x1min,x1max},}]bound constrained minimization

IPOPTMinimize bound constrained minimization.

Find a local minimum of with x constrained in the interval , starting from . We can again use IPOPTMinimize with objective function , argument variable and initial value . We also need to specify the variable bounds :

Minimize with x between 10 and 20 starting from x=11.
In[8]:=
Click for copyable input
Out[8]=

IPOPTMinimize returns an IPOPTData object. This object contains the minimal value and the minimization point.

Extract the minimum objective function value and position from the IPOPTData object.
In[9]:=
Click for copyable input
Out[9]=
Plot the objective function with the location of the local minimum found.
In[10]:=
Click for copyable input
Out[10]=

Note that bound constraints are a special case of function constraints.

Express the same problem using a function constraint with constraint function x:
In[11]:=
Click for copyable input
Out[11]=
Extract the minimal value and minimization point from the IPOPTData object.
In[12]:=
Click for copyable input
Out[12]=

Function constrained minimization

IPOPTMinimize[f,{x1,},{x1i0,},{{x1min,x1max},},{g1,},{{g1min,g1max},}]constrained minimization with function constraints and variable bounds

IPOPTMinimize constrained minimization with function constraints and variable bounds.

Minimize over the circle , described by a constraint function with lower and upper constraint bounds both equal to 1.

Minimize subject to , starting from {x,y}={0,1}.
In[13]:=
Click for copyable input
Out[14]=
Extract the minimal value and minimization point from the IPOPTData object.
In[15]:=
Click for copyable input
Out[15]=
Plot the solution:
In[16]:=
Click for copyable input
Out[16]=

ParametricIPOPTMinimize

ParametricIPOPTMinimize can be used to set up a minimization problem with parameters present anywhere in the problem formulation. The optimization problem may then be solved repeatedly with different parameter values. ParametricIPOPTMinimize has all of the arguments of IPOPTMinimize with the addition of the parameter variables argument {p1,} given last.

ParametricIPOPTMinimize[f,{x1,},{x1i0,},{{x1min,x1max},},{g1,},{{g1min,g1max},},{p1,}]parametric constrained minimization

ParametricIPOPTMinimize parametric constrained minimization.

Set up a minimization problem over the circle , where r is a parameter.

Minimize subject to , starting from {x,y}={0,-r}.
In[17]:=
Click for copyable input
Out[17]=

The previous step performs the preprocessing of the functions and all necessary derivatives and returns a ParametricFunction object awaiting parameter values.

The actual minimization begins after providing parameter values and the solution is stored in an IPOPTData expression.

Minimize for a given parameter value r=1.
In[18]:=
Click for copyable input
Out[18]=
Extract the minimal value and minimization point from the IPOPTData expression.
In[19]:=
Click for copyable input
Out[19]=

Compute other solutions for different parameter values.

Solve the problem for different parameter values of the circle radius r.
In[20]:=
Click for copyable input
Minimize with all of the above parameter values:
In[21]:=
Click for copyable input
Extract the minimal value from all IPOPTData objects.
In[22]:=
Click for copyable input
Plot the minimal value for the all the parameter values used.
In[23]:=
Click for copyable input
Out[23]=
Observe the solution with Manipulate for different parameter values:
In[24]:=
Click for copyable input

Using ParametricIPOPTMinimize instead of IPOPTMinimize with multiple parameter values reduces the overhead of repeatedly preprocessing the objective and constraint functions as well as all necessary derivatives, which can be significant depending on their complexity.

Compare timings with IPOPTMinimize and ParametricIPOPTMinimize.
In[25]:=
Click for copyable input
In[26]:=
Click for copyable input
Out[26]=
In[27]:=
Click for copyable input
Out[27]=

Maximizing with IPOPTMinimize

A maximum value can be found by minimizing the negative of the objective function.

Find a local maximum of over the circle .

Maximize subject to , starting from {x,y}={1,0}.
In[28]:=
Click for copyable input
Out[28]=

The minimum value of -f should then be negated again to obtain the maximum value of f.

Get the maximal value of and the maximization point:
In[29]:=
Click for copyable input
Out[29]=

Engineering example

Design a cam to maximize the area of the valve opening for one rotation of the convex cam with constraints on the curvature and the radius of the cam. The problem formulation is from the COPS test suite and is summarized below.

We assume that the shape of the cam is circular over an angle of 6π/5 of its circumference with radius rmin. The design variables ri,i=1,,n, represent the radius of the cam at equally spaced angles θ distributed over an angle of 2π/5. Symmetry is used in the remaining angle of 2π/5.

The following constraints are specified. Each radius ri is constrained in the interval {rmin, rmax}. Additionally we have convexity constraints expressed by A(ri-1,ri+1)A(ri-1,ri)+ A(ri,ri+1), where A(ri,rj) is the area of the triangle defined by the origin and the points ri and rj on the cam surface. There is also a curvature requirement -α (ri+1-ri)/θ α depending on the parameter α.

To define the objective function the valve opening area is assumed to have a simple linear relationship with the design variables ri given as: π rv 2(r1++rn)/n, where rv is a constant related to the geometry of the valve.

We can set this as a parametric problem with parameters rmin,rmax, α. The number of design variables is chosen to be n=20 and we assume .

Load the package.
In[30]:=
Click for copyable input
Set up the variables, initial values, constraints and the objective function.
In[31]:=
Click for copyable input
Set up the parametric problem.
In[41]:=
Click for copyable input
Out[41]=
Find a solution for given parameter values.
In[42]:=
Click for copyable input
Out[42]=
In[43]:=
Click for copyable input
Out[43]=
In[44]:=
Click for copyable input
Out[44]=
Plot the cam shape.
In[45]:=
Click for copyable input
In[46]:=
Click for copyable input
In[47]:=
Click for copyable input
In[48]:=
Click for copyable input
Out[48]=
Use the parametric formulation to easily recompute with different parameter values.
In[49]:=
Click for copyable input
Out[49]=
In[50]:=
Click for copyable input
Out[50]=

References

IPOPT is written by ​Andreas Wächter, ​Carl Laird and others as part of the COIN-OR Initiative. It is based on the following paper: A. Wächter and L. T. Biegler, ​On the Implementation of a Primal-Dual Interior Point Filter Line Search Algorithm for Large-Scale Nonlinear Programming, Mathematical Programming 106(1), pp. 25-57, 2006.