Dynamic Optimization Basics

Two tools used in this course are MATLAB and Python. APMonitor is used as a toolbox in MATLAB or as a package within Python to provide support for solution of dynamic simulation, estimation, and control.

There are many tools for simulation and optimization of dynamic systems. There are also many factors to consider when selecting the appropriate tool for a particular task. Some of the considerations for a dynamic optimization tool are size (scaling with number equations and degrees of freedom), speed (use in real-time estimation or control), usability (training requirements and ease of adaptation), extensibility (ability to modify for new or complex systems), support (commercial sustainment or open-source community), and portability (ability to embed on a system or communicate with a particular platform).

The objective of this section is to introduce MATLAB and Python. This is not intended to be a general tutorial but more specifically to cover topics that are relevant for dynamic optimization. Topics of interest for dynamic optimization are listed below.

Introduction to Programming Languages

Many programming languages can be used in this course with examples in both MATLAB and Python programming languages. There are many resources to get started in MATLAB or get started with Python. There are also excellent resources for experienced MATLAB programmers who would like to learn Python such as Numpy for Matlab Users. Introductory material on programming with MATLAB or Python is in the Computational Tools Course.

Introduction to Nonlinear Optimization

This course uses principles from nonlinear programming but does not delve into the details of solution strategies. Instead of detailing how a nonlinear programming solver iterates to find a solution, this course focuses on formulating problems and the use of differential constraints in describing and optimizing dynamic systems. For more background on how nonlinear programming solvers work, refer to the Course on Optimization and the associated online Design Optimization Textbook. A good illustrative example is the Two Bar Truss optimization or the example below.

GEKKO (Python)

GEKKO Python is designed for large-scale optimization and accesses solvers of constrained, unconstrained, continuous, and discrete problems. Problems in linear programming, quadratic programming, integer programming, nonlinear optimization, systems of dynamic nonlinear equations, and multi-objective optimization can be solved. The platform can find optimal solutions, perform tradeoff analyses, balance multiple design alternatives, and incorporate optimization methods into external modeling and analysis software. It is free for academic and commercial use under the MIT license.

Gekko Documentation

The GEKKO package is available through the package manager pip in Python.

python -m pip install gekko

View Source for 18 GEKKO Example Solutions

APMonitor (MATLAB and Python)

APMonitor is a tool for nonlinear optimization and dynamic optimization. Source files are available for Julia, Python, and MATLAB. Users can select either a public server or a local host if the APMonitor Server is installed locally. The user must also specify an application name.

 server = ''         # for local server
 server = 'https://byu.apmonitor.com' # for public server
 app = myApp                         # application name

Once the server and application name are defined, the following is a list of available commands in each package.

An example script is below. The same commands are used in Python, MATLAB, and Julia with minor modifications such as the ';' in MATLAB to suppress console output or change in the comment characters.

Model Predictive Control Example (MATLAB and Python)
# import apm.py, available from
#   https://apmonitor.com/wiki/index.php/Main/PythonApp
from apm import *
# for MATLAB use: addpath('apm')

s = 'https://byu.apmonitor.com'
a = 'myApp'

# clear prior application
apm(s,a,'clear all')

# load model and data

# specify FV, MV, SV, CV

# configuration parameters

# turn on MV as a degree of freedom
# turn on CV to add terms to objective function

# tune MV in the controller

# tune CV in the controller

# solve and retrieve results
output = apm(s,a,'solve')

# open web-viewer

# retrieve solution
z = apm_sol(s,a)
Home | Dynamic Optimization Basics