7.2 A gallery of conic examples¶
In this chapter we demonstrate various simple examples of conic problems including various cone types (domains). We assume full familiarity with the basic tutorial of Sec. 7.1 (The conic interface tutorial).
7.2.1 Example CQO1 (quadratic cones)¶
We solve the conic quadratic problem:
The variable has length 6 and is ordered as
model = mosekmodel(...
name = "cqo1", ...
numvar = 6);
% Variable is [x, y]
model.objective("minimize", [0 0 0 1 1 1]');
% Linear constraint
model.appendcons(F = [1 1 2 0 0 0], domain = mosekdomain("eq", rhs=1.0));
% Bounds on x
model.appendcons(F = sparse([eye(3) zeros(3)]), domain = mosekdomain("rplus", dim=3));
% Quadratic cone
model.appendcons(F = sparse([1,2,3],[4,1,2],[1,1,1]), domain = mosekdomain("qcone",dim=3));
% Rotated quadratic cone
model.appendcons(F = sparse([1,2,3],[5,6,3],[1,1,1]), domain = mosekdomain("rqcone",dim=3));
model.solve();
if model.hassolution("interior")
[xx,prosta,solsta] = model.getsolution("interior","x");
fprintf("Solution x1,x2,x3: [ %s ]\n", sprintf("%.2g ", xx(1:3)));
fprintf("Solution y1,y2,y3: [ %s ]\n", sprintf("%.2g ", xx(4:6)));
end
7.2.2 Example AFFCO2 (power cones and auxiliary variables)¶
Consider the following simple optimization problem:
Adding auxiliary variables we convert this problem into an equivalent conic form:
We arrange the variables as x
followed by t
.
For the sake of demonstration:
we add constraints in three blocks: first the quadratic constraint, then both power cone constraints together, and finally the linear constraint,
we add the quadratic constraint in the constructor
mosekmodel
and the other ones later usingmosekmodel.appendcons
,
while of course any other combination is also possible.
For example, the constraint
The joint power cone constraints have the following representation:
This is altogether implemented as follows:
% Variables [x1; x2; t1; t2]
model = mosekmodel(name = "affco1", numvar = 4, ...
objsense = "maximize", objective = [0, 0, 1, 1], ...
F = sparse([zeros(1,4); speye(2) zeros(2,2)]), ... % The quadratic cone constraint
g = [1 -0.5 -0.6]', ...
domain = mosekdomain("qcone", dim = 3));
% The power cones added as one block:
model.appendcons(name="pow", ...
F = sparse([1,3,4,4,6], [1,3,1,2,4], ones(1,5)), ...
g = [0 1 0 0.1 1 0]', ...
domain = [mosekdomain("pow", dim = 3, alpha = [1 2]'), ... % Exponents [ 1/3, 2/3 ]
mosekdomain("pow", dim = 3, alpha = 0.25) ]); % Exponents [ 0.25, 0.75 ]
% Linear inequality x_1 - x_2 <= 1
model.appendcons(F = [1 -1 0 0], domain = mosekdomain("less than", rhs = 1));
7.2.3 Example AFFCO2 (many exponential cones)¶
Consider the following simple linear dynamical system. A point in
which can be cast into conic form as:
with variable vector
We assemble all conic constraints in the form
For the conic quadratic constraint the affine conic representation is
For the
where mosekmodel.appendcons
, where the argument n
denotes the number of cones.
function t = firstHittingTime(n, z, a, d)
% Variables [t, y1, ..., yn]
model = mosekmodel(...
name = "affco2", ...
numvar = n + 1, ...
objective = [1 zeros(1,n)], ...
objsense = "minimize");
model.varname([1], ["t"]);
% Quadratic cone
model.appendcons(F = diag([0; z]), ...
g = [d; zeros(n,1)], ...
domain = mosekdomain("qcone", dim = n + 1));
% All exponential cones (their number is n)
FExp = sparse([1:3:3*n 3:3:3*n], ...
[2:n+1 ones(1,n)], ...
[ones(1,n) a']);
gExp = repmat([0; 1; 0], n, 1);
model.appendcons(F = FExp, g = gExp, ...
domain = mosekdomain("exp", dim = 3, n = n));
% Solve and get solution
model.solve();
if model.hassolution("interior")
[x, prosta, solsta] = model.getsolution("interior", "x");
t = x(1);
end