function [optiX] = mosekCVXYalmipMosek(dim,  G, exR, consVIndices, exV, k )
%function [optiX optiLambda] = mosekSDPYalmip( G, exR, consVIndices, exV, k )

%  G: dim*dim*m x dim*n 
% exR: dim*dim*m x 1
% consVIndices: t x 1, t: number of constrained vertices   !!!1-based!!!
% exV: dim*t x 1, position of constrained vertices
% k: the weight of positional constraAint when it is modeled as a soft constraint; set k=0 if the positional constraint is a hard constraint 
% optiX: dim*n x 1
% number_of_it: maximum number of iterations

bNoninversion = 1;

dim_square = dim*dim;

m = size(G,1)/dim_square;
n = size(G,2)/dim;

sizeCN = size(consVIndices,1);
indices = zeros(dim*sizeCN,1);
if (dim == 2)
    for i=1:sizeCN % could be faster
        indices(2*i-1) = 2*consVIndices(i)-1;
        indices(2*i  ) = 2*consVIndices(i);
    end
elseif (dim == 3)
    for i=1:sizeCN % could be faster
        indices(3*i-2) = 3*consVIndices(i)-2;
        indices(3*i-1) = 3*consVIndices(i)-1;
        indices(3*i  ) = 3*consVIndices(i);
    end
end
nm = size(G,1) + size(indices,1);

sdpCVXtimeMS = tic;
cvx_begin

variable v(n+1, 1);

F = G*v(1:n,1);
{[ F- exR; sqrt(k)*(v(indices) - exV(indices))], v(n+1,1)} == lorentz(nm);
if bNoninversion
    if (dim == 2)
        for i=1:m
            curR = [exR(4*i-3) exR(4*i-2);exR(4*i-1) exR(4*i)];
            curF = [F(4*i-3) F(4*i-2);F(4*i-1) F(4*i)];
            curR'*curF+curF'*curR == semidefinite(2);
        end
    elseif (dim == 3)
        for i=1:m
            curR = [exR(9*i-8) exR(9*i-7) exR(9*i-6);exR(9*i-5) exR(9*i-4) exR(9*i-3);exR(9*i-2) exR(9*i-1) exR(9*i)];
            curF = [F(9*i-8) F(9*i-7) F(9*i-6);F(9*i-5) F(9*i-4) F(9*i-3);F(9*i-2) F(9*i-1) F(9*i)];
            curR'*curF+curF'*curR == semidefinite(3);
        end
    end
end
sdpCVXtimeM  = toc(sdpCVXtimeMS);

sdpCVXtimeSS = tic;
minimize( v(n+1,1) );
cvx_end
sdpCVXtimeS  = toc(sdpCVXtimeSS);

fprintf('cvx+mosek modeling time = %f\n',sdpCVXtimeM);
fprintf('cvx+mosek solving time = %f\n',sdpCVXtimeS);

optiX = v(1:n,1);

end

