Description Your Own Alternative to Elective Tasks

If you want to replace elective tasks for some more advanced alternative please do like this:

  • Send a mail with your suggestion to the teachers in the course, describing what you want to do
    • Spend a reasonable amount of time, learning something new
  • Prepare a 5-10 minute presentation and submit it in Canvas before the deadline
  • Be ready to give a presentation at the KTH meeting in December if we ask you to

 

A possible alternative could be to do something with  https://github.com/cvxgrp/cvxpygen Links to an external site. replacing the task below

 

Additional: CVXGEN - generate efficient C-code for Quadratic Programming problems

(An alternative to CVXGEN can also be to try out  https://github.com/cvxgrp/cvxpygen Links to an external site. )

We will demonstrate  how to  generate fast C-code that solves convex QP-problems with some hundred or so optimization variables within a millisecond. We will use a web-service that transforms a CVX-like description of your optimization problem and automatically generates C-code that can be used from within matlab, or can be embedded into your realtime production code.

If you want to generate code yourself, you will need to follow the instructions at cvxgen.com Links to an external site.. Note that CVXGEN is only available for free to academic, non-commercial users with an academic email address, and you will need that to request for an academic license.

The work flow is shown in the series of cvxgen screenshots at this page. Links to an external site.

The tool can be used to generate support vector machines, solve so called Lasso problems used in statistical modeling, etc. Here we will demonstrate it by implementing a so called Model Predictive Controller (MPC).

Model predictive control is based on solving repeated optimization problems using so called receding horizon control. The MPC method is explained in this video Links to an external site.

To generate code for an MPC controller for the double integrator we took the lines of code in the file Download inputtocvxgen.m

and pasted it into the cvxgen webservice (after requesting an academic license). Following the workflow on the cvxgen home page we ended up with a number of files, including the solver codes cvxsolve (matlab-code), csolve.c (C-code) and csolve.mexmaci64 (mex-code to use the C code within matlab on a Mac computer).

The matlab solver was then bench-marked against the generated C-solver in the file Download test_cvxgen.m 

which implements a simple MPC controller for the double integrator. The running time for solving the optimization problem in matlab with cvxsolve.m was about 3 seconds per time step and using the csolve.mexmaci64 it was 50 microseconds (a speedup of about 60000 !).

If you think it might be useful to be able to generate fast embedded C-code for quadratic optimization problems you might want to redo the example presented above.