-
Notifications
You must be signed in to change notification settings - Fork 3
Conic Optimization
This page is under construction
#TODO
#TODO
#TODO
#TODO
#TODO
Add sdpsol definition here. Remark: example at the end
#TODO
#TODO
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 off 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.