-
Notifications
You must be signed in to change notification settings - Fork 3
Conic Optimization
To solve polynomial sum-of-squares optimization problems via semidefinite programming, CaΣoS provides both a high-level and low-level interface for convex optimization. These interfaces extend CasADi's qpsol and conic syntax. Several conic solvers are supported (but, unlike CasADi, the solvers must be installed separately and be accessible through MATLAB).
Note
SeDuMi does not support quadratic cost functions.
The high-level interface solves convex problems of the form
where
S = casos.sdpsol('S','solver',struct('x',x,'f',f,'g',g,'p',p),opts)
initializes the SDP solver named 'S' using the convex solver 'solver'. Options are provided as structure opts including optional fields opts.Kx and opts.Kc describing, respectively, the cones
sol = S('lbx',lbx,'ubx',ubx,'cbx',cbx,'lbg',lbg,'ubg',ubg,'cbg',cbg)
evaluates the SDP solver S providing (optional) arguments to describe
Note
When using casos.sdpsol with Mosek, PSD decision variables must be constrained to the PSD cone on Kx, not Kc. This is because Mosek expects variables in triangulized (lower-triangular) form, while CaΣoS internally represents them in vectorized form. Symmetry is therefore enforced on Kx rather than on Kc. For further details, see Question #126.
The low-level interface solves conic problems of the form
where
S = casos.conic('S','solver',struct('h',hs,'a',as),opts)
initializes the conic solver named 'S' using the convex solver 'solver', where hs and as are sparsity patterns for opts including optional fields opts.Kx and opts.Kc describing, respectively, the cones
sol = S('h',h,'g',g,'a',a,'lba',lba,'uba',uba,'cba',cba,'lbx',lbx,'ubx',ubx,'cbx',cbx)
evaluates the conic solver S providing (optional) arguments to describe
Consider Example 6.7.1 from the Mosek documentation.
The problem involves semidefinite and conic constraints with a linear cost function, that is:
In CaΣoS, the implementation of this problem is rather straightforward.
We start by defining the symbolic decision variables as casadi.SX objects with
x_bar = casadi.SX.sym('x_bar', 3, 3);
x = casadi.SX.sym('x', 3, 1);Note that sdp-struct with
sdp.x = [x; x_bar(:)];Note
All problem decision variables need to be defined as one vector.
With the syntax
opts.Kx = struct('lin', [3], 'psd', [3]);we define that there are linear bounds on ...'psd', 3... instead of ...'psd', 9....
Finally, we need to define the linear upper and lower bounds on
lbx = -inf(3,1); % no bound -> set to -inf
ubx = inf(3,1); % no bound -> set to infWe define the three matrices (cost function and first two constraints) with
A = [2 1 0; 1 2 1; 0 1 2];
B = eye(3);
C = ones(3, 3);which now allows us to use standard Matlab syntax to define the cost function
sdp.f = trace(A*x_bar) + x(1); % costand the three constraints with
sdp.g = [ % constraints
trace(B*x_bar) + x(1);
trace(C*x_bar) + x(2) + x(3);
[x(1); x(2); x(3)];
]where the actual dimension is size(sdp.g)= [5 1] since the Lorentz cone constraint considers three variables which we define with the K_-notation:
% cones
opts.Kc = struct('lin', [2], 'lor', [3]);Since we could potentially have several Lorentz constraints, [3] can correctly be defined as a list (best practice).
Finally, we add the upper and lower bounds for the first two linear constraints
lbg = [1; .5];
ubg = [1; .5];to force the equality constraints given in the problem.
Now we can build the solver and obtain the solution with
% Use high-level interface
S = casos.sdpsol('S','mosek',sdp,opts);
sol = S('lbx',lbx,'ubx',ubx,'lbg',lbg,'ubg',ubg);The complete code is given by:
% https://docs.mosek.com/latest/toolbox/tutorial-sdo-shared.html#example-sdo1
% Decision variables
x_bar = casadi.SX.sym('x_bar', 3, 3); % matrix
x = casadi.SX.sym('x', 3, 1); % vector
sdp.x = [x; x_bar(:)]; % List of decision variables
lbx = -inf(3,1); % lower bound
ubx = inf(3,1); % upper bound
opts.Kx = struct('lin', [3], 'psd', [3]);
% Cost and constraints
A = [2 1 0; 1 2 1; 0 1 2];
B = eye(3);
C = ones(3, 3);
sdp.f = trace(A*x_bar) + x(1); % cost
% constraints
sdp.g = [
trace(B*x_bar) + x(1);
trace(C*x_bar) + x(2) + x(3);
[x(1); x(2); x(3)];
]
% Conic constraints
opts.Kc = struct('lin', [2], 'lor', [3]);
% Linear upper and lower bound
lbg = [1; .5];
ubg = [1; .5];
% Use SDP interface
S = casos.sdpsol('S','mosek',sdp,opts);
sol = S('lbx',lbx,'ubx',ubx,'lbg',lbg,'ubg',ubg);- Getting started
- Available conic solvers
- Convex and nonconvex sum-of-squares optimization
- Supported vector, matrix, and polynomial cones
- Some practical tipps for sum-of-squares
- Transitioning from other toolboxes
- Example code snippets
If you use CaΣoS, please cite us.