1

We are developing a website tool that, given some parameters by the user, solves the following optimal control problem online: $$\boxed{\begin{array}{cl} \displaystyle \min_{u\in\mathcal{U}} & \displaystyle L(u) := \frac{1}{T} \int_0^T v^\top x(t; x_0, \theta, u) dt \\ \text{subject to} & \left\{\begin{array}{l} \dot{x} = f_\theta (x,u), \quad x(0) = x_0 \\ w^\top x(t) \leq b \end{array}\right. \end{array}}$$ where $\theta$ is the vector of model parameters provided by the user, $w,v\in\mathbb{R}^n$ are vectors, $x(t)\in\mathbb{R}^n$ is the state, and $u(t)\in\mathbb{R}^p$ is the control function to be optimized. The dimension $n$ is on the order of $10^3$. Each time the user changes the model parameters, he/she runs the optimization and wait for the result. However, it may take too long to finish.

Question 1: Which optimization solvers are best in terms of computation time for solving this problem in real-time on the website?

Question 2: Which language (C++, Python, etc.) should be used to code the optimization?

Question 3: I have coded the algorithm in MATLAB using fmincon function. There is a MATLAB toolbox (MATLAB Coder) to convert MATLAB code to a C++ code. Do you have a recent experience (good/bad) about this?

1 Answers1

1

A bit late, but hope it still can help somebody.

For the optimization solver, it will depend on your model $f_{\theta}$. A modeling framework as cvx or yalmip can transform your problem in a more convenient one for a specific solver.

As the dimension of $n$ is on the order $10^3$, I suppose it is not recommended to code it in javascript and its flavors. I would recommend to use c/c++ in the backend or in the worst case some language that calls c/c++ code for the performance specific parts (python with cython).

There are many fast optimization solvers in github implemented in c with permissible licenses for non commercial projects (ecos, osqp, sedumi etc). They are developed by renowned people as Stephen Boyd and Alberto Bemporad (ecos, osqp). Many of them have python bindings (ecos-python, osqp-python)

Alternatively, as you proposed, you can use MATLAB Coder to convert the code to c, which needs a MATLAB Coder license. Observe that as shown in matlab documentation for fmincon, the solutions can vary due to differences in the math kernel libraries used by the pure c/c++ version and versions in MATLAB.

For the interface with the website I see two options, writing a webserver with integrated solution for the optimization, or if you have a webserver which supports cgi binaries, use cgi-bin applications.

If you go with the second option, I suggest to use POST requests with your $\theta$ parameters in a json content, since it would be more elegant than sending all the parameters in a URI with web-forms like www.myoptimizer/optimize?theta=2.... Here is an example of how to do it in python.

Accácio
  • 92
  • 5