MTSOS: writing barrier functions
In order to compile MTSOS, the user must provide a function for calculating the barrier at a given a point . Although it is possible to write the barrier funciton in MATLAB, doing so will incur a significant performance penalty, so users are encouraged to write their barrier function directly in C.
A very brief introduction to barrier methods
A very brief introduction to barrier methods will be provided here and we will obscure many of the details to focus on implementation.
For more information on barrier functions for interior point methods see Convex Optimization and .
As outlined in Minimum-Time Speed Optimization Over a Fixed Path the constraints will have the form
.
For the purposes of explanation we will consider constraints of the more specific form
,
where is convex.
In a barrier method, we reformulate our constraints as a cost in the objective by adding to the objective, where
![I_(u)=bigg{begin{array}{cc}0&u leq 0 infty&u > 0end{array}](eqs/7545351322956210662-130.png)
is the indicator function.
If the constraint is satisfied, it will not contribute to the objective at all, while if it is unsatisfied, the objective will be infinite.
Therefore, to minimize the objective, the constraints must be satisfied. Unfortunately, the indictaor is not differentiable so we approximate it by
,
where is a parameter that sets the accuracy of the approximation.
As decreases, this approximation approaches the indicator function.
Although we strongly encourage the use of the log barrier function, MTSOS is written to allow the use of an alternative barrier function if desired.
If you have multiple constraints, say of them at evaluation point , then we evaluate them as
.
In the barrier function you must calculate , , and as described below.
MATLAB
If the user must write the barrier function in MATLAB, change the compiler to point to barreir_matlab.c instead of barrier_front.c.
This will cause the algorithm to look to barrier_mat.m for the dynamics. The name of this file can be changed in barrier_matlab.c.
[H G F] = barrier(S, S_prime, S_dprime, a, b, u,indicator,kappa,variables)
Inputs
Outputs
H | a length vector consisting of the Hessian of each for provided in column first order and concatenated; if any of the points lie outside the domain of for any , then H should be set to inf NOTE: variable order is ![(b,a,u)](eqs/5733974055070241524-130.png) |
G | a length vector consisting of the gradient of each for concatenated;if any of the points lie outside the domain of for any , then G should be set to inf NOTE: variable order is ![(b,a,u)](eqs/5733974055070241524-130.png) |
F | a length vector consisting of the evaluation of for ; if any of the points lie outside the domain of for any , then G should be set to inf
|
C
- int so_barrier(const double* S, const double* S_prime, const double* S_dprime,
const double* b, const double* a, const double* u,
int S_length, int U_size, int State_size,
int indicator, double kappa, const double* variables, int variables_length,
double* H_barrier, double* G_barrier, double* F_barrier)
Inputs
Note: these are all constant.
Outputs
Allocated, but unitialized, arrays are provided for the user to populate.
In particular, if an array needs to be zero, the values must be set to zero, do not assume any values in the arrays.
RETURN int | 1 : all values are within the domain, no errors 0 : points lie outside the domain of -1 : an error occurred and the algorithm will abort |
double* H_barrier | a length array consisting of the Hessian for each for provided in column first order and concatenated; if any of the points lie outside the domain of for any , then the value of H_barrier is irrelevant and the function should return 0 |
double* G_barrier | a length array consisting of the gradient of each for concatenated; if any of the points lie outside the domain of for any , then the value of G_barrier is irrelevant and the function should return 0 |
double* F_barrier | a length array consisting of the evaluation of for ; if any of the points lie outside the domain of for any , then the value of F_barrier is irrelevant and the function should return 0
|
Tips for writing barrier functions
Log barrier gradients and Hessians
Some useful quantities when using the log barrier function,
are:
![nablaphi(x) = sum_{j=1}^kfrac{-kappa}{g_j(x)}nabla g_j(x),](eqs/4365201342851773572-130.png)
![nabla^2phi(x) = sum_{j=1}^kfrac{kappa}{g_j(x)^2}nabla g_j(x) nabla g_j(x)^T + sum_{i=1}^kfrac{-kappa}{g_j(x)}nabla^2 g_j(x),](eqs/4872883568632540634-130.png)
where is .
This suggests an advantageous structuring of the code for the calculation of the gradient and Hessian of .
Example structure
![forall; i,j](eqs/5171303792065996783-130.png)
calculate ;
if ( )
if (indicator )
else
calculate , known as F
|