In this example, we will show how to determine the best ADMM algorithm parameters using the simple MPC example. The template described in this page can be easily adapted to other problems. Our goal is to choose the values of \( \rho \) and \( \alpha \) to improve the average solution accuracy for a fixed number of iterations.

**Define Multistage Problem**

Firstly, one has to define the multistage problem. See the simple MPC example for details on how to achieve this.

**Modify Solver Options**

Then one has to modify the solver options to prepare the solver for 'tuning' mode. Choose one ADMM variant and set the number of iterations to the maximum number of iterations that you would like the solver to execute for.

codeoptions.maxit = 40;

codeoptions.ADMMvariant = 1;

Also set the accuracy requirements to a high value:

codeoptions.accuracy.dres = 1E-6;

and turn on auto tuning mode:

`
codeoptions.ADMMtune = 1;
`

**Prepare Testbench**

The algorithm parameters will be tuned for a set of problems provided by the user. It is important that this set of problems is a good representation of the problems that the solver will encounter when executing autonomously.

One way to obtain this testbench is to run a closed-loop simulation with an interior-point method and record the problems being fed into the solver in a MATLAB cell array.

Another approach, which will be used here, is to grid the parameter space. For the simple MPC example the only parameter is the current state estimate, which is 2-dimensional, hence this approach is feasible. The following code creates 1681 test problems evenly distributed over the state space.

`
i = 1;
for x1 = -4:0.2:4
for x2 = -4:0.2:4
problem{i}.minusA_times_x0 = -A*[x1;x2];
i = i+1;
end
end
`

**Search the Design Space**

The script provided at the end of page file includes an algorithm to find the combination of \( \rho \) and \( \alpha \) such that the average consensus error over all the test problems is minimized. The algorithm starts at a point in the \( ( \rho, \alpha ) \) space, evaluates the average consensus error at several points in the neighbourhood, and takes a steepest descent step while satisfying the constraints on \( \rho \) and \( \alpha \).

The following parameters can be tuned to trade-off the runtime of the tool against the accuracy of the \( \rho \) and \( \alpha \) selection.

factor = 1.1; % TUNING PARAMETER: search neighbourhood around current point

grad_stepsize = 0.5; % TUNING PARAMETER: gradient step size

% TUNING PARAMETER: starting point

rho(1) = 1;

alpha(1) = 1.5;

For the simple MPC example the algorithm follows the following search path. The best ADMM parameters for this data set are:

\[ \rho = 3.12 \\ \alpha = 1 \].