Matlab¶
Before generating code for a parametric problem, the problem should be first specified in the setup phase. See Setup for more details.
Codegen¶
The code is generated by running
m.codegen(dir_name, varargin)
The argument dir_name
is the name of a directory where the generated
code is stored.
The second argument varargin
specifies additional codegen options
shown in the following table
Option |
Description |
Allowed values |
---|---|---|
|
Build environment |
'' (default)'Makefile' 'MinGW Makefiles' 'Unix Makefiles' 'CodeBlocks' 'Xcode' |
|
Problem parameters |
'vectors' (default)'matrices' |
|
Name of the compiled mex interface |
'emosqp' (default)Nonempty string
|
|
Rewrite existing directory |
false (default)true |
|
Use |
false (default)true |
|
Use |
true (default)false |
You can pass the options as field-value pairs, e.g.,
m.codegen('code', 'parameters', 'matrices', 'mexname', 'emosqp');
If the project_type
argument is not passed or is set to ''
,
then no build files are generated.
Mex interface¶
Once the code is generated the following functions are provided through its mex interface. Each function is called as
emosqp('function_name');
where emosqp
is the name of the mex interface specified in the previous section
- emosqp('solve')
Solve the problem.
- Returns:
multiple variables [x, y, status_val, iter, run_time]
x (ndarray) - Primal solution
y (ndarray) - Dual solution
status_val (int) - Status value as in Status values and errors
iter (int) - Number of iterations
run_time (double) - Run time
- emosqp('update_lin_cost', q_new)
Update linear cost.
- Parameters:
q_new (ndarray) – New linear cost vector
- emosqp('update_lower_bound', l_new)
Update lower bound in the constraints.
- Parameters:
l_new (ndarray) – New lower bound vector
- emosqp('update_upper_bound', u_new)
Update upper bound in the constraints.
- Parameters:
u_new (ndarray) – New upper bound vector
- emosqp('update_bounds', l_new, u_new)
Update lower and upper bounds in the constraints.
- Parameters:
l_new (ndarray) – New lower bound vector
u_new (ndarray) – New upper bound vector
If the code is generated with the option parameters
set to
'matrices'
, then the following functions are also provided
- emosqp('update_P', Px, Px_idx, Px_n)¶
- :noindex:
Update nonzero entries of the quadratic cost matrix (only upper triangular) without changing sparsity structure.
- param ndarray Px:
Values of entries to be updated
- param ndarray Px_idx:
Indices of entries to be updated. Pass
[]
if all the indices are to be updated- param int Px_n:
Number of entries to be updated. Used only if Px_idx is not
[]
.
- emosqp('update_A', Ax, Ax_idx, Ax_n)
Update nonzero entries of the constraint matrix.
- Parameters:
Ax (ndarray) – Values of entries to be updated
Ax_idx (ndarray) – Indices of entries to be updated. Pass
[]
if all the indices are to be updatedAx_n (int) – Number of entries to be updated. Used only if Ax_idx is not
[]
.
- emosqp('update_P_A', Px, Px_idx, Px_n, Ax, Ax_idx, Ax_n)¶
- :noindex:
Update nonzero entries of the quadratic cost and constraint matrices. It considers only the upper-triangular part of P.
- param ndarray Px:
Values of entries to be updated
- param ndarray Px_idx:
Indices of entries to be updated. Pass
[]
if all the indices are to be updated- param int Px_n:
Number of entries to be updated. Used only if Px_idx is not
[]
.- param ndarray Ax:
Values of entries to be updated
- param ndarray Ax_idx:
Indices of entries to be updated. Pass
[]
if all the indices are to be updated- param int Ax_n:
Number of entries to be updated. Used only if Ax_idx is not
[]
.
You can update all the nonzero entries in matrix \(A\) by running
emosqp('update_A', Ax_new, [], 0);
See C Sublevel API for more details on the input arguments.