APMonitor solves nonlinear complex, large-scale optimization problems with a flexible modeling language. The following is a brief introduction to the modeling language. Other features are discussed at the APMonitor Homepage.
Example #1: Hock-Schittkowsky Test Suite #71 shown in IPOPT documentation - (Download hs71.apm).
! Hock-Schittkowsky Test Suite #71
! Save this snippet to a text file for submission
Model hs71
Variables
x1 = 1, >=1, <=5
x2 = 5, >=1, <=5
x3 = 5, >=1, <=5
x4 = 1, >=1, <=5
obj = 20
End Variables
Equations
x1*x2*x3*x4 > 25
x1^2 + x2^2 + x3^2 + x4^2 = 40
obj = x1*x4*(x1+x2+x3) + x3
End Equations
End Model
! Vectors and Intermediate Variables
! Save this snippet to a text file for submission
Model vector
Variables
x[1:10]
obj
End Variables
Intermediates
y[1] = x[1]^2
y[2:10] = y[1:9] + x[2:10]^2
z[1] = x[1]
z[2:10] = z[1:9] + x[2:10]
End Intermediates
Equations
y[10] <= 1
obj = -z[10]
End Equations
End Model
In the most basic terms, a model consists of parameters, variables, and equations. Parameters are fixed and cannot be modified by the optimizer. Variables are adjusted to satisfy constraints and meet an objective.
Model example
Parameters
p1 = 1
p2 = 5
End Parameters
Variables
v1
v2
End Variables
Equations
v1 = 2 * p1
v2 + v1 < p2
End Equations
End Model
These elements are combined to form the model named test.apm. While the variables can be adjusted by the optimizer, the parameters remain constant. The equations may be posed in terms of inequality or equality constraints.
Step 2: The Objective Function
When there are additional degrees of freedom (more variables than equations), the variables are also adjusted to minimize an objective function subject to the equations. The objective function is a linear summation of select model variables. Variables that begin with obj are included in the objective summation. Thus, variables such as objective, obj(1), and objx would all be classified as objective function terms. The optimal solution is defined as the minimum objective function subject to the model constraints. A minimum objective function is obtained by manipulating the variables, subject to the model.
Model example
Parameters
p1 = 1
p2 = 5
End Parameters
Variables
v1
v2
objective
End Variables
Equations
v1 = 2 * p1
p1 < v2+v1 < p2
objective = v2^2 + v1^2
End Equations
End Model
Step 3: Slack Variables (optional)
Slack variables are defined to transform inequality equations into equality constraints. The inequality constraint v2+v1 < p2 is transformed into v2+v1 - p2 + slk = 0 and slk>=0. Variables that begin with slk are also included in the objective summation and are automatically given a lower bound of zero. Thus, user defined variables such as slk_1, slk(1), and slkx would all be classified as slack variables.
Step 4: Variable Upper and Lower Bounds and Initial Conditions (optional)
Simple upper and lower bounds are placed on the variables in the variable declaration section. Initial conditions can also be provided to aide the optimizer in finding a solution. In the example below the initial conditions are v1=1, v2=2, and objective=0.
Model example
Parameters
p1 = 1
p2 = 5
End Parameters
Variables
v1 = 1, <3, >=0
v2 = 2*v1, >1
objective = 0
End Variables
Equations
v1 = 2 * p1
p1 < v2+v1 < p2
objective = v2^2 + v1^2
End Equations
End Model
Step 5: Running the Optimization Problem
To run the optimization problem, return to the top of this page and upload the test problem from a text file on your computer. You can download a copy of test.apm. Save this text file to your computer. You can modify the model by adding variables or equations.
When you select the button Upload File, the file is transferred to the server for calculation. You'll see something similar to the following text. For this example, the solution is with large-scale interior point NLP solver IPOPT using MUMPS as the linear solver.
Contents of uploaded file
Model example
Parameters
p1 = 1
p2 = 5
End Parameters
Variables
v1 = 1, <3, >=0
v2 = 2*v1, >1
objective = 0
End Variables
Equations
v1 = 2 * p1
p1 < v2+v1 < p2
objective = v2^2 + v1^2
End Equations
End Model
Starting. . .
************ Custom model ************
Each node contains
Objects : 0
Variables : 7
Intermediates: 0
Connections : 0
Equations : 12
Residuals : 4
Number of state variables: 5
Number of total equations: 4
Degrees of freedom : 1
**********************************************
Steady State Optimization with Interior Point Solver
**********************************************
******************************************************************************
This program contains Ipopt, a library for large-scale nonlinear optimization.
Ipopt is released as open source code under the Common Public License (CPL).
For more information visit http://projects.coin-or.org/Ipopt
******************************************************************************
NOTE: You are using Ipopt only with the MUMPS linear solver.
Other linear solvers might be more efficient (see Ipopt documentation).
Number of nonzeros in equality constraint Jacobian...: 10
Number of nonzeros in inequality constraint Jacobian.: 0
Number of nonzeros in Lagrangian Hessian.............: 0
Total number of variables............................: 5
variables with only lower bounds: 3
variables with lower and upper bounds: 1
variables with only upper bounds: 0
Total number of equality constraints.................: 4
Total number of inequality constraints...............: 0
inequality constraints with only lower bounds: 0
inequality constraints with lower and upper bounds: 0
inequality constraints with only upper bounds: 0
iter objective inf_pr inf_du lg(mu) ||d|| lg(rg) alpha_du alpha_pr ls
0 1.7999982e-002 5.56e+000 5.47e-001 0.0 0.00e+000 - 0.00e+000 0.00e+000 0
1 6.3105213e+000 2.43e+000 2.09e+002 -1.2 3.06e+000 - 4.44e-003 9.34e-001h 1
2 9.0909009e+000 6.44e-003 1.21e+000 -1.0 2.80e+000 - 1.00e+000 1.00e+000h 1
3 9.0603208e+000 3.35e-004 3.81e-002 -2.8 3.40e-002 - 9.98e-001 1.00e+000h 1
4 8.9997229e+000 9.72e-004 3.56e-004 -4.0 6.74e-002 - 1.00e+000 9.99e-001f 1
5 8.9999999e+000 7.78e-007 3.65e-008 -9.7 3.32e-004 - 9.99e-001 9.99e-001h 1
6 9.0000000e+000 9.28e-014 3.89e-010 -11.0 3.22e-007 - 1.00e+000 1.00e+000h 1
Number of Iterations....: 6
(scaled) (unscaled)
Objective...............: 8.9999999800101129e+000 8.9999999800101129e+000
Dual infeasibility......: 3.8900083154658205e-010 3.8900083154658205e-010
Constraint violation....: 9.2765301613124190e-014 9.2765301613124190e-014
Complementarity.........: 1.0197043100182696e-011 1.0197043100182696e-011
Overall NLP error.......: 3.8900083154658205e-010 3.8900083154658205e-010
Number of objective function evaluations = 7
Number of objective gradient evaluations = 7
Number of equality constraint evaluations = 7
Number of inequality constraint evaluations = 0
Number of equality constraint Jacobian evaluations = 7
Number of inequality constraint Jacobian evaluations = 0
Number of Lagrangian Hessian evaluations = 0
Total CPU secs in IPOPT (w/o function evaluations) = 0.000
Total CPU secs in NLP function evaluations = 0.010
EXIT: Optimal Solution Found.
The solution was found.
The final value of the objective function is 8.999999980010113
Step 6: View the Solution
At the bottom of the run log, there is a link that states Click to View Solution. This takes you to a table view of the solution. The solution file displays the object oriented naming convention that is used with APMonitor. The object hierarchy is denoted by successive periods in the name. The variable ss.web.example.objective is a reference to variable "objective" in the "example" model in the "web" interface in a steady state ("ss") optimization flowsheet. Parameters, variables, active constraints, and objective function contributions are highlighted with colors given in the color key.
Color Key
Parameter
Variable
Override
Active Constraint
Objective Variable
Name
Lower
Value
Upper
ss.web.example.p1
---
1.0000E+00
---
ss.web.example.p2
---
5.0000E+00
---
ss.web.example.v1
0.0000E+00
2.0000E+00
3.0000E+00
ss.web.example.v2
1.0000E+00
1.0000E+00
---
ss.web.example.objective
---
5.0000E+00
---
ss.web.example.slk_2
0.0000E+00
2.0000E+00
---
ss.web.example.slk_3
0.0000E+00
2.0000E+00
---
Other Capabilities
The online interface only includes the steady state optimization features of APMonitor. The full product includes features for parameter fitting from data, dynamic simulation, moving horizon estimation, and nonlinear model predictive control. The same model is used in all of these simulations without modification. The model can be synchronized to live data with ODBC, OPC, and Modbus communication.