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 \(x\) followed by \(y\) from (7.5). We add the constraints in the order in which they appear above.
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 \((1,x_1-0.5,x_2-0.6)\in \Q^3\) is written in matrix form as
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 \(\real^n\) moves along a trajectory given by \(z(t) = z(0)\exp(At)\), where \(z(0)\) is the starting position and \(A=\Diag(a_1,\ldots,a_n)\) is a diagonal matrix with \(a_i<0\). Find the time after which \(z(t)\) is within euclidean distance \(d\) from the origin. Denoting the coordinates of the starting point by \(z(0)=(z_1,\ldots,z_n)\) we can write this as an optimization problem in one variable \(t\):
which can be cast into conic form as:
with variable vector \(x=[t,y_1,\ldots,y_n]^T\).
We assemble all conic constraints in the form
For the conic quadratic constraint the affine conic representation is
For the \(i\)-th exponential cone we have
where \(e_i\) denotes a vector of length \(n\) with a single \(1\) in position \(i\). We assemble all those exponential cone desctiptions in one call to 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